我不明白我的课堂上发生了什么。我有一个采用 List 和字符串的方法。我正在尝试使用 mockito 模拟它,以便它返回 null。这是我拥有的代码:
when(myClass.myMethod(anyList(), anyString())).thenReturn(null);
我得到一个标准InvalidUseOfMatchersException
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
1 matchers expected, 2 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.
...
但我真的不明白。我正确使用了匹配器 - 不是anyList()和anyString()两个匹配器吗?