ResetToCommitPresenter implements ResetToCommitView.ActionDelegate { public void showDialog() { service.log(appContext.getCurrentProject().getRootProject(), false, new AsyncRequestCallback<LogResponse>(dtoUnmarshallerFactory.newUnmarshaller(LogResponse.class)) { @Override protected void onSuccess(LogResponse result) { view.setRevisions(result.getCommits()); view.setMixMode(true); view.setEnableResetButton(selectedRevision != null); view.showDialog(); } @Override protected void onFailure(Throwable exception) { String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : constant.logFailed(); console.printError(errorMessage); Notification notification = new Notification(errorMessage, ERROR); notificationManager.showNotification(notification); } } ); } @Inject  ResetToCommitPresenter(ResetToCommitView view,
                                  GitServiceClient service,
                                  GitLocalizationConstant constant,
                                  GitOutputPartPresenter console,
                                  EditorAgent editorAgent,
                                  AppContext appContext,
                                  NotificationManager notificationManager,
                                  DtoUnmarshallerFactory dtoUnmarshallerFactory,
                                  ProjectExplorerPresenter projectExplorer,
                                  EventBus eventBus,
                                  ProjectServiceClient projectService); void showDialog(); @Override void onResetClicked(); @Override void onCancelClicked(); @Override void onRevisionSelected(@NotNull Revision revision);  }
@Test public void testShowDialogWhenLogRequestIsSuccessful() throws Exception { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<String> callback = (AsyncRequestCallback<String>)arguments[2]; GwtReflectionUtils.callOnSuccess(callback, mock(LogResponse.class)); return callback; } }).when(service).log(any(ProjectDescriptor.class), anyBoolean(), Matchers.<AsyncRequestCallback<LogResponse>>anyObject()); presenter.showDialog(); verify(appContext).getCurrentProject(); verify(service).log(eq(rootProjectDescriptor), eq(!IS_TEXT_FORMATTED), Matchers.<AsyncRequestCallback<LogResponse>>anyObject()); verify(view).setRevisions(Matchers.<ArrayList<Revision>>anyObject()); verify(view).setMixMode(eq(IS_MIXED)); verify(view).setEnableResetButton(eq(DISABLE_BUTTON)); verify(view).showDialog(); }
@Test public void testShowDialogWhenLogRequestIsFailed() throws Exception { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<String> callback = (AsyncRequestCallback<String>)arguments[2]; GwtReflectionUtils.callOnFailure(callback, mock(Throwable.class)); return callback; } }).when(service).log(any(ProjectDescriptor.class), anyBoolean(), Matchers.<AsyncRequestCallback<LogResponse>>anyObject()); presenter.showDialog(); verify(appContext).getCurrentProject(); verify(service).log(eq(rootProjectDescriptor), eq(!IS_TEXT_FORMATTED), Matchers.<AsyncRequestCallback<LogResponse>>anyObject()); verify(constant).logFailed(); verify(console).printError(anyString()); verify(notificationManager).showNotification(any(Notification.class)); }