I cant find an answer already on stackoverlow for this. This is the simplest example I can boil it down to.
I have a class which I want to mock and it places calls to this class
public class GetCustomerForUser extends PropertyAction<Customer>
....
PropertyAction:
public abstract class PropertyAction<R> extends AbstractProcessAction<R> implements
ValuedAction<R, R> {
The real calling code looks like this
Customer self = dispatcher.invokeTransactionless(actor, new GetCustomerForUser());
dispatcher is of type ActionDispatcher
In the calling mock
protected void applyWhenClauses(ActionDispatcher dispatcher, Actor actor) throws ProcessException {
when(dispatcher.invokeTransactionless(actor, (ProcessAction<Customer>) anyObject())).thenReturn(null);
....
dispatcher is of type ActionDispatcherMock
When I run the test I get
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded.
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
For more info see javadoc for Matchers class.
at com.prolog.test.mock.ActionDispatcherMock2.applyWhenClauses
(ActionDispatcherMock2.java:18)
at com.prolog.test.mock.ActionDispatcherMock.createMockInstance
(ActionDispatcherMock.java:84)
at com.prolog.test.mock.ActionDispatcherMock.createMockInstance
(ActionDispatcherMock.java:1)
at com.prolog.test.mockFactory.AbstractPrologInstanceMock.createInstanceMock
(AbstractPrologInstanceMock.java:11)
I intend to have a when for each class that the dispatcher could invoke.
Does anyone have any words of wisdom about what I’m doing wrong here?
thanks for your time.
The error message indicates what the issue is: if you’re using any…
anyyou can’t then have a not-anymatcher:See how you’re doing precisely what it says you can’t do? And how it says to correct it?