Mockito - invalid use of argument arguments / 1 suitable answer, 3 recorded

I have a problem with mockito. I get a bizarre error that I cannot solve.

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 that is next to this test method calls:

[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 (indicating 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"));
}

Method of marking up the method:

    when(service.method(anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), anyString())).thenReturn(new ArrayList<String>());

doesn't matter, and I still get the same exception from mockito.

I do not know what happened. Import looks great, options are also used, so when did I make a mistake? Is anyone

UPDATE / DECISION

Ok, I found the reason for this error. After changing the default access modification method to protect the entire test, it works fine. Now the method in the class looks like this:

protected List<String> method(final Map<String, String> numbersMap, final Map<String, String> invalidNumbersMap, final String filename) {
    //do something
}

Mockito . .

+4

All Articles