Mockito official doc says:
Warning:
If you are using argument matchers, all arguments have to be provided by matchers.
E.g: (example shows verification but the same applies to stubbing):
verify(mock).someMethod(anyInt(), anyString(), eq("third argument")); //above is correct - eq() is also an argument matcher verify(mock).someMethod(anyInt(), anyString(), "third argument"); //above is incorrect - exception will be thrown because third argument is given without argument matcher.
Matcher methods like
anyObject()
,eq()
do not return matchers. Internally, they record a matcher on a stack and return a dummy value (usually null).
I am curious why it is impossible to use Mathers
alongside values even though any()
-like methods return null
.