Use eq in mockito
When using mockito, we should use eq
for String
.
It seems that we should use eq
even for long
.
If we foget to use it as follows:
when(mockService.method(longValue, any(ClassA.class))).thenReturn(true);
You will get the following error.
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 2 matchers expected, 1 recorded: -> at com.example.XxxTest.test(XxxTest.java:51) 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"));