Reputation: 3
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.
Upvotes: 0
Views: 1323
Reputation: 160261
The error message indicates what the issue is: if you're using any... any
you can't then have a not-any
matcher:
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"));
See how you're doing precisely what it says you can't do? And how it says to correct it?
Upvotes: 1