@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 testOnTransMemoryCopy() { when(tableEditorMessages.notifyCopied()).thenReturn("copied"); selectedTU = currentPageRows.get(0); when(display.getId()).thenReturn(selectedTU.getId()); when(display.getEditors()).thenReturn(Lists.newArrayList(editor)); presenter.setStatesForTesting(selectedTU.getId(), 0, display); presenter.onDataCopy(new CopyDataToEditorEvent(Arrays.asList("target"))); verify(editor).setTextAndValidate("target"); verify(eventBus, atLeastOnce()).fireEvent(eventCaptor.capture()); NotificationEvent notificationEvent = TestFixture.extractFromEvents(eventCaptor.getAllValues(), NotificationEvent.class); MatcherAssert.assertThat(notificationEvent.getMessage(), Matchers.equalTo("copied")); }