@Test public void testIsDirty() { tested.init(); tested.open(diagram); assertFalse(tested.isDirty(tested.getCurrentDiagramHash())); tested.setOriginalHash(~~(tested.getCurrentDiagramHash() + 1)); assertTrue(tested.isDirty(tested.getCurrentDiagramHash())); }
@Test public void testHasChanges() { tested.init(); tested.open(diagram); assertFalse(tested.hasUnsavedChanges()); tested.setOriginalHash(~~(tested.getCurrentDiagramHash() + 1)); assertTrue(tested.hasUnsavedChanges()); tested.setOriginalHash(~~(tested.getCurrentDiagramHash())); assertFalse(tested.hasUnsavedChanges()); }
@SuppressWarnings("unchecked") public void testLoadContent() { tested.loadContent(); verify(projectDiagramServices, times(1)).getByPath(eq(path), any(ServiceCallback.class)); }
@Test @SuppressWarnings("unchecked") public void testOnSaveWithChanges() { tested.open(diagram); tested.setOriginalHash(diagram.hashCode() + 1); doAnswer(i -> { ((ClientSessionCommand.Callback) i.getArguments()[0]).onSuccess(); return null; }).when(sessionValidateCommand).execute(any(ClientSessionCommand.Callback.class)); tested.onSave(); assertOnSaveSavedDiagram(); }
@Test @SuppressWarnings("unchecked") public void testOnSaveRestore() { tested.open(diagram); doAnswer(i -> { ((ClientSessionCommand.Callback) i.getArguments()[0]).onSuccess(); return null; }).when(sessionValidateCommand).execute(any(ClientSessionCommand.Callback.class)); tested.onSave(); assertOnSaveSavedDiagram(); }
tested.init(); tested.setEditorSessionPresenter(sessionEditorPresenter);
@SuppressWarnings("unchecked") public void testValidateBeforeSave() { tested.save(); verify(sessionValidateCommand, times(1)).execute(any(ClientSessionCommand.Callback.class)); }
@Test public void testNotValidOnPlaceHiddenEvent() { PlaceRequest anotherRequest = mock(PlaceRequest.class); when(anotherRequest.getIdentifier()).thenReturn(""); PlaceHiddenEvent event = new PlaceHiddenEvent(anotherRequest); tested.hideDiagramEditorDocks(event); verify(onDiagramLostFocusEven, never()).fire(any(OnDiagramLoseFocusEvent.class)); }
@Test public void testHideLoadingViews() { tested.hideLoadingViews(); verify(view).hideBusyIndicator(); } }
public void testSaveWithCommitMessageOnSuccess() { tested.save(SAVE_MESSAGE); verify(view).showSaving(); verify(projectDiagramServices).saveOrUpdate(eq(path), any(ProjectDiagram.class), any(Metadata.class), eq(SAVE_MESSAGE), serviceCallbackCaptor.capture()); final ServiceCallback<ProjectDiagram> serviceCallback = serviceCallbackCaptor.getValue(); final ProjectDiagram diagram = mock(ProjectDiagram.class); serviceCallback.onSuccess(diagram); verify(view).hideBusyIndicator(); verify(versionRecordManager).reloadVersions(eq(path)); verify(presenterView).showMessage(StunnerProjectClientConstants.DIAGRAM_SAVE_SUCCESSFUL); }
@Test public void testOnPlaceHiddenEvent() { PlaceHiddenEvent event = new PlaceHiddenEvent(placeRequest); tested.hideDiagramEditorDocks(event); verify(onDiagramLostFocusEven).fire(any(OnDiagramLoseFocusEvent.class)); }
public void testSaveWithCommitMessageOnError() { tested.save(SAVE_MESSAGE); verify(view).showSaving(); verify(projectDiagramServices).saveOrUpdate(eq(path), any(ProjectDiagram.class), any(Metadata.class), eq(SAVE_MESSAGE), serviceCallbackCaptor.capture()); final ServiceCallback<ProjectDiagram> serviceCallback = serviceCallbackCaptor.getValue(); final ClientRuntimeError error = mock(ClientRuntimeError.class); serviceCallback.onError(error); verify(diagramClientErrorHandler).handleError(eq(error), consumerCaptor.capture()); final Consumer<String> consumer = consumerCaptor.getValue(); consumer.accept(ERROR_MESSAGE); verify(errorPopupPresenter).showMessage(ERROR_MESSAGE); }
@Test @SuppressWarnings("unchecked") public void testLoadContentError() { ArgumentCaptor<ServiceCallback> callbackArgumentCaptor = forClass(ServiceCallback.class); tested.loadContent(); verify(projectDiagramServices, times(1)).getByPath(eq(path), callbackArgumentCaptor.capture()); callbackArgumentCaptor.getValue().onError(new ClientRuntimeError(new DefinitionNotFoundException())); verify(placeManager, times(1)).forceClosePlace(any(PathPlaceRequest.class)); ArgumentCaptor<Consumer> consumerArgumentCaptor = forClass(Consumer.class); verify(diagramClientErrorHandler, times(1)).handleError(any(ClientRuntimeError.class), consumerArgumentCaptor.capture()); consumerArgumentCaptor.getValue().accept("error message"); verify(errorPopupPresenter, times(1)).showMessage("error message"); }