More code needed
We will need more code for a definitive answer so until that happens this is my best guess.
Create a mock of your class
You have class A
mocked somewhere in your test using PowerMock or EasyMock, something like:
A mockedA = EasyMock.createMock(A.class);
Expect behaviour on mocked class
So all behaviour upon mocked class A
that happens during your specific test (again missing code here) should be expected with:
final String someValue = "someValue";
EasyMock.expect(mockedA.logon(EasyMock.isA(String.class))).andReturn(someValue)
I'm totally guessing here on the signature of that logon
method since I don't know your A
class implementation. In my guess the logon
method expects a String
argument (can by any class or primitive really) and returns another String
value.
Matching
If you're matching for another argument, like argument of class B
for example you need to update the above code to:
EasyMock.expect(mockedA.logon(EasyMock.isA(B.class))).andReturn(someValue)
Same can be said for the type of the return argument, if that is of type C
just instance a C
class object for someValue
last param instead.
Unclear errors
You have a valid point that the errors are very unclear in some cases. You are matching for something that accepted an argument object that was null
in your test.
Now null
can be matched in several ways, like just with fixed null
value or with EasyMock.isA(class)
. And that is likely where it went wrong in your test some experiment with the following:
EasyMock.expect(mockedA.logon(null)).andReturn(someValue)
EasyMock.expect(mockedA.logon(EasyMock.isA(SomeClass.class)).andReturn(someValue)
EasyMock.expect(mockedA.logon(EasyMock.isNull(SomeClass.class)).andReturn(someValue)
EasyMock.expect(mockedA.logon(aVariableHoldingNull)).andReturn(someValue)
EasyMock.expect(mockedA.logon(EasyMock.eq(aVariableHoldingNull)).andReturn(someValue)
EasyMock.expect(mockedA.logon(EasyMock.anyObject(SomeClass.class)).andReturn(someValue)
EasyMock.expect(mockedA.logon(EasyMock.isNull()).andReturn(someValue)
And this list is far from complete. Also make sure to get back to us with your solution so the community can learn from this.