0
public interface EventBus{
public void fireEvent(GwtEvent<?> event);
}
和测试代码(TestNG的方法)的接口看起来是这样的:
@Test
public void testFireEvent(){
EventBus mock=mock(EventBus.class);
//when both Event1 and Event2 are subclasses of GwtEvent<?>
mock.fireEvent(new Event1());
mock.fireEvent(new Event2());
//then
verify(mock).fireEvent(argThat(new Event2Matcher()));
}
Event2Matcher看起来是这样的:
private class Event2Matcher extends ArgumentMatcher<Event2>
{
@Override
public boolean matches(Object arg)
{
return ((Event2) arg).getSth==sth;
}
}
,但得到指示错误即:
Event1 can't be cast to Event2
而且很明显,匹配匹配的第一个调用
mock.fireEvent(new Event1());
所以,以下语句匹配内
return ((Event2) arg).getSth==sth;
会抛出这个exception.So的问题是如何让
verify(mock).fireEvent(argThat(new Event2Matcher()));
匹配第二次调用?