0

我不明白我的课堂上发生了什么。我有一个采用 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()两个匹配器吗?

4

1 回答 1

0

我想到了。事实证明,我试图在一个真正的方法上做一个 when ,而不是一个模拟的方法。错误消息并没有真正帮助我弄清楚...

于 2021-03-23T19:18:44.620 回答