我有这个代码:
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);
}