@Test public void onRequestValidationWillFireRunValidationEvent() { // given current display has one editor and current editor has target content selectedTU = currentPageRows.get(0); presenter.setStatesForTesting(selectedTU.getId(), 0, display); when(display.getId()).thenReturn(selectedTU.getId()); when(editor.getId()).thenReturn(selectedTU.getId()); when(display.getEditors()).thenReturn(Lists.newArrayList(editor)); when(sourceContentPresenter.getCurrentTransUnitIdOrNull()).thenReturn(selectedTU.getId()); when(sourceContentPresenter.getSourceContent(selectedTU.getId())) .thenReturn(Optional.of("source")); when(editor.getText()).thenReturn("target"); presenter.onRequestValidation(RequestValidationEvent.EVENT); verify(eventBus).fireEvent(eventCaptor.capture()); RunValidationEvent event = TestFixture.extractFromEvents(eventCaptor.getAllValues(), RunValidationEvent.class); MatcherAssert.assertThat(event.getTarget(), Matchers.equalTo("target")); }
@Test public void canValidate() { selectedTU = currentPageRows.get(0); presenter.setStatesForTesting(selectedTU.getId(), 0, display); when(display.getId()).thenReturn(selectedTU.getId()); when(editor.getId()).thenReturn(selectedTU.getId()); when(editor.getText()).thenReturn("target"); when(sourceContentPresenter.getSourceContent(selectedTU.getId())) .thenReturn(Optional.of("source")); presenter.validate(editor); verify(eventBus).fireEvent(eventCaptor.capture()); RunValidationEvent event = (RunValidationEvent) eventCaptor.getValue(); assertThat(event.getSourceContent(), equalTo("source")); assertThat(event.getTarget(), equalTo("target")); assertThat(event.isFireNotification(), equalTo(false)); assertThat( event.getWidgetList(), Matchers.<HasUpdateValidationWarning>containsInAnyOrder(editor, display)); }