@Test public void testOnInsertString() { // Given: selectedTU = currentPageRows.get(0); when(editor.getId()).thenReturn(selectedTU.getId()); when(display.getId()).thenReturn(selectedTU.getId()); when(display.getEditors()).thenReturn(Lists.newArrayList(editor)); when(tableEditorMessages.notifyCopied()).thenReturn("copied"); when(sourceContentPresenter.getSourceContent(selectedTU.getId())) .thenReturn(Optional.of("source content")); presenter.setStatesForTesting(selectedTU.getId(), 0, display); // When: presenter.onInsertString(new InsertStringInEditorEvent("", "suggestion")); // Then: verify(editor).insertTextInCursorPosition("suggestion"); verify(eventBus, atLeastOnce()).fireEvent(eventCaptor.capture()); NotificationEvent notificationEvent = TestFixture.extractFromEvents(eventCaptor.getAllValues(), NotificationEvent.class); MatcherAssert.assertThat(notificationEvent.getMessage(), Matchers.equalTo("copied")); RunValidationEvent runValidationEvent = TestFixture.extractFromEvents(eventCaptor.getAllValues(), RunValidationEvent.class); assertThat(runValidationEvent.getSourceContent(), equalTo("source content")); }
@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)); }