I have a problem with mockito. I'm getting a freaky error, which I'm not able to resolve.
Error:
[error] Invalid use of argument matchers!
[error] 1 matchers expected, 3 recorded:
[error] -> at service.ServiceTest.test(ServiceTest.java:149)
[error] -> at service.ServiceTest.test(ServiceTest.java:149)
[error] -> at service.ServiceTest.test(ServiceTest.java:149)
and the test method which is next to this test method throws:
[error] Unfinished stubbing detected here:
[error] -> at service.ServiceTest.test(ServiceTest.java:149)
Method code:
List<String> method(final Map<String, String> numbersMap, final Map<String, String> invalidNumbersMap, final String filename) {
//do something
}
protected List<User> run(Map<String, String> numbersMap, final String filename, final Map<String, String> invalidNumbersMap) {
//do something
List<String> processedUsedNumbers = method(numbersMap, invalidNumbersMap, filename);
//do something
return new ArrayList<>();
}
Test code (which pointing this exception)
@Test
public void test() {
doReturn(new ArrayList<String>()).when(service).method(anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), anyString()); //line 149
// rest of mocks
Map<String, String> inputMap = getExampleMap(3); //generate test data
List<User> result = service.run(inputMap, "file.csv", new HashMap<>());
// other checks
verify(service, times(1)).method(eq(inputMap), anyMapOf(String.class, String.class), eq("file.csv"));
}
Mocking method 'method' in that way:
when(service.method(anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), anyString())).thenReturn(new ArrayList<String>());
make not difference and i'm still getting the same exception from mockito.
I have no idea what is wrong. Imports looks fine, used params also, so where I did a mistake? Anyone?
UPDATE / SOLUTION
Ok, I found the reason of this error. After change method access modifier from default to protected the whole test working fine. Now, the method in class looks like this one:
protected List<String> method(final Map<String, String> numbersMap, final Map<String, String> invalidNumbersMap, final String filename) {
//do something
}
But why Mockito throws this kind of exception. This thing is completely irrelevant to exception message output.