【发布时间】:2013-08-14 07:57:23
【问题描述】:
我有这个代码:
import static org.mockito.Mockito.*;
final Combobox combobox = mock(Combobox.class);
//.... some business logic which calls method 'appendChild' on 'combobox'
verify(combobox, times(3)).appendChild((Component) anyObject()); // <<== exception here
它一直这样写:
Invalid use of argument matchers!
2 matchers expected, 1 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.
appendChild 方法如下所示:
public final boolean appendChild(Component child)
{
return insertBfr(null, child);
}
【问题讨论】:
-
哪一行抛出异常?请在此处发布您的 SSCCE (sscce.org)。
-
方法
appendChild是否有不同的版本(具有不同数量的参数)?你能告诉我们这个方法的代码吗? -
你为什么使用
anyObject?在泛型中使用any和您的类。看看会发生什么。