I have such method:
<T extends Entity> boolean putObject(T value);
But can`t find out how to mock it using mockito? anyObject() and any() produce error:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
1 matchers expected, 3 recorded.
Mock:
when(service.putObject(any(ProcessingTransaction.class))).thenReturn(true);
How it shold work?
Most likely, you have one or two improperly-formed calls to Mockito methods, somewhere earlier in your test (or even in a previous test). When you call a Mockito method that makes an argument matcher (like
any()), the matcher gets added to an internal data structure. It’s then removed when it’s actually used.The fact that Mockito found three argument matchers instead of just one suggests that you made some argument matchers but didn’t use them. For example, if you use
when(...)withoutthenReturn(), this can happen; but there are lots of other cases too.If you want help finding exactly what you’ve done wrong, you need to post more of your test code.