Reputation: 58774
I have a DAO method I want to verify is called inside Service
send(User user, Properties prop)
I can verify using a protected method in service, but I think it should be private
verify(dao).send(user, service.getProp())
I tried in different ways to define accepting any properties as:
verify(dao).send(user, any(Properties.class)); // or any()
verify(dao).send(user, Matchers.isA(Properties.class)));
But all failed with invalid arguments
FAILED: testService
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at com.package.TestService.testService(TestService.java:330)
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.
Upvotes: 2
Views: 2873
Reputation: 46323
As the exception details explain, you're not allowed to mix raw values (user
) with matchers (any(...)
).
Instead, use matchers for all arguments using the eq(...)
matcher:
verify(dao).send(eq(user), any());
Upvotes: 7