StatusCommandPresenter { public void showStatus() { CurrentProject project = appContext.getCurrentProject(); if (project == null) { return; } service.statusText(project.getRootProject(), LONG, new AsyncRequestCallback<String>(new StringUnmarshaller()) { @Override protected void onSuccess(String result) { printGitStatus(result); } @Override protected void onFailure(Throwable exception) { String errorMessage = exception.getMessage() != null ? exception.getMessage() : constant.statusFailed(); Notification notification = new Notification(errorMessage, ERROR); notificationManager.showNotification(notification); } }); } @Inject  StatusCommandPresenter(GitServiceClient service,
                                  AppContext appContext,
                                  GitOutputPartPresenter console,
                                  GitLocalizationConstant constant,
                                  NotificationManager notificationManager); void showStatus();  }
@Test public void testShowStatusWhenStatusTextRequestIsSuccessful() throws Exception { doAnswer(new Answer<AsyncRequestCallback<String>>() { @Override public AsyncRequestCallback<String> answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<String> callback = (AsyncRequestCallback<String>)arguments[2]; Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, EMPTY_TEXT); return callback; } }).when(service).statusText(Matchers.<ProjectDescriptor>anyObject(), Matchers.<StatusFormat>anyObject(), Matchers.<AsyncRequestCallback<String>>anyObject()); presenter.showStatus(); verify(appContext).getCurrentProject(); verify(service).statusText(eq(rootProjectDescriptor), eq(IS_NOT_FORMATTED), Matchers.<AsyncRequestCallback<String>>anyObject()); }
@Test public void testShowStatusWhenStatusTextRequestIsFailed() throws Exception { doAnswer(new Answer<AsyncRequestCallback<String>>() { @Override public AsyncRequestCallback<String> answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<String> callback = (AsyncRequestCallback<String>)arguments[2]; Method onFailure = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onFailure.invoke(callback, mock(Throwable.class)); return callback; } }).when(service).statusText(Matchers.<ProjectDescriptor> anyObject(), Matchers.<StatusFormat> anyObject(), Matchers.<AsyncRequestCallback<String>> anyObject()); presenter.showStatus(); verify(appContext).getCurrentProject(); verify(service).statusText(eq(rootProjectDescriptor), eq(IS_NOT_FORMATTED), Matchers.<AsyncRequestCallback<String>> anyObject()); verify(notificationManager).showNotification((Notification)anyObject()); verify(constant).statusFailed(); }