org.mockito.exceptions.misusing.InvalidUseOfMatchersException当我没有匹配器时

时间:2014-08-07 14:31:57

标签: java unit-testing testing mocking mockito

我尝试模拟一个方法:

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

但是我得到以下错误,我无法理解我的代码是如何相关的:

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.

1 个答案:

答案 0 :(得分:1)

如错误所示,您使用原始值和Matchers的组合。 userInfo是原始值