Elad Benda2
Elad Benda2

Reputation: 15482

org.mockito.exceptions.misusing.InvalidUseOfMatchersException when i have no matcher

I try to mock a method:

    PermissionsChecker checker = mock(PermissionsChecker.class);
    mockDoesUSerHasPermissions(checker, trustedUser, true);
    mockDoesUSerHasPermissions(checker, nonTrustedUser, false);



private void mockDoesUSerHasPermissions(PermissionsChecker checker, UserInfo userInfo, boolean doesHasPermissions) {
        when(checker.doesUserHavePermissions(Mockito.any(Venue3.class), Mockito.any(Venue3.class), userInfo, Mockito.any(ActionType.class))).thenReturn(doesHasPermissions);
    }

but i get the following error that i cannot understand how is related to my code:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
4 matchers expected, 3 recorded:

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"));

For more info see javadoc for Matchers class.

Upvotes: 1

Views: 229

Answers (1)

jny
jny

Reputation: 8057

As the error says, you use combination of raw values and Matchers. userInfo is raw value

Upvotes: 1

Related Questions