GWT 测试部分描述了如何验证Presenter
inDisplay
对象的输出,但没有解释如何反其道而行之。换句话说,我想检查当用户点击按钮时是否Presenter
会发出正确的请求。RPC Service
Display
如何模拟按钮点击Display
?触发 GWT 事件并不简单,因为它们具有受保护的构造函数。有没有办法简单地做到这一点,没有子ClickEvent
类?
@Before
protected void setUp() {
mockRpcService = mock(NegotiationServiceAsync.class);
eventBus = new HandlerManager(null);
mockDisplay = mock(NegotiationPresenter.Display.class);
negotiationPresenter = new NegotiationPresenter(mockRpcService,
eventBus, mockDisplay);
}
@Test
private void testSth() {
when(mockDisplay.getSuppliersEmails()).thenReturn("address@domain.com");
when(mockDisplay.getTaskDescription()).thenReturn("This is the task to do");
// This does not work
mockDisplay.getSubmitButton().fireEvent(new ClickEvent());
verify(mockRpcService).startTask(any(NegotiationRequest.class), any(AsyncCallback.class));
}