AddToIndexPresenter implements AddToIndexView.ActionDelegate { public void showDialog() { project = appContext.getCurrentProject(); if (project == null) { return; } final Unmarshallable<Status> unmarshall = this.dtoUnmarshallerFactory.newUnmarshaller(Status.class); service.status(project.getRootProject(), new AsyncRequestCallback<Status>(unmarshall) { @Override protected void onSuccess(final Status result) { if (!result.isClean()) { addSelection(); } else { console.printInfo(constant.nothingAddToIndex()); notificationManager.showInfo(constant.nothingAddToIndex()); } } @Override protected void onFailure(Throwable exception) { String errorMessage = exception.getMessage() != null ? exception.getMessage() : constant.statusFailed(); console.printError(errorMessage); notificationManager.showError(errorMessage); } }); } @Inject  AddToIndexPresenter(AddToIndexView view,
                               AppContext appContext,
                               DtoUnmarshallerFactory dtoUnmarshallerFactory,
                               GitLocalizationConstant constant,
                               GitOutputPartPresenter console,
                               GitServiceClient service,
                               NotificationManager notificationManager,
                               ProjectExplorerPresenter projectExplorer); void showDialog(); @Override void onAddClicked(); @Override void onCancelClicked();  }
@Test public void testDialogWillNotBeShownWhenStatusRequestIsFailed() throws Exception { presenter.showDialog(); verify(service).status(eq(rootProjectDescriptor), asyncRequestCallbackStatusCaptor.capture()); AsyncRequestCallback<Status> callback = asyncRequestCallbackStatusCaptor.getValue(); Method onFailure = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onFailure.invoke(callback, mock(Throwable.class)); verify(console).printError(anyString()); verify(notificationManager).showError(anyString()); verify(view, never()).showDialog(); verify(constant).statusFailed(); }
@Test public void testDialogWillNotBeShownWhenNothingAddToIndex() throws Exception { when(this.statusResponse.isClean()).thenReturn(true); presenter.showDialog(); verify(service).status(eq(rootProjectDescriptor), asyncRequestCallbackStatusCaptor.capture()); AsyncRequestCallback<Status> callback = asyncRequestCallbackStatusCaptor.getValue(); Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, this.statusResponse); verify(console).printInfo(anyString()); verify(notificationManager).showInfo(anyString()); verify(view, never()).showDialog(); verify(constant,times(2)).nothingAddToIndex(); }
@Test public void testShowDialogWhenRootFolderIsSelected() throws Exception { Selection selection = mock(Selection.class); ProjectDescriptorNode project = mock(ProjectDescriptorNode.class); when(project.getStorablePath()).thenReturn(PROJECT_PATH); when(selection.getHeadElement()).thenReturn(project); when(selection.isEmpty()).thenReturn(false); when(selection.isSingleSelection()).thenReturn(true); when(projectExplorer.getSelection()).thenReturn(selection); when(constant.addToIndexAllChanges()).thenReturn(MESSAGE); when(this.statusResponse.isClean()).thenReturn(false); presenter.showDialog(); verify(service).status(eq(rootProjectDescriptor), asyncRequestCallbackStatusCaptor.capture()); AsyncRequestCallback<Status> callback = asyncRequestCallbackStatusCaptor.getValue(); Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, this.statusResponse); verify(appContext).getCurrentProject(); verify(constant).addToIndexAllChanges(); verify(view).setMessage(eq(MESSAGE), Matchers.<List<String>>eq(null)); verify(view).setUpdated(anyBoolean()); verify(view).showDialog(); }