ShowProjectGitReadOnlyUrlPresenter implements ShowProjectGitReadOnlyUrlView.ActionDelegate { public void showDialog() { final CurrentProject project = appContext.getCurrentProject(); view.showDialog(); service.remoteList(project.getRootProject(), null, true, new AsyncRequestCallback<List<Remote>>(dtoUnmarshallerFactory.newListUnmarshaller(Remote.class)) { @Override protected void onSuccess(List<Remote> result) { view.setRemotes(result); } @Override protected void onFailure(Throwable exception) { view.setRemotes(null); String errorMessage = exception.getMessage() != null ? exception.getMessage() : constant.remoteListFailed(); console.printError(errorMessage); Notification notification = new Notification(errorMessage, ERROR); notificationManager.showNotification(notification); } } ); service.getGitReadOnlyUrl(project.getRootProject(), new AsyncRequestCallback<String>(new StringUnmarshaller()) { @Override protected void onSuccess(String result) { view.setLocaleUrl(result); } @Override protected void onFailure(Throwable exception) { String errorMessage = exception.getMessage() != null && !exception.getMessage().isEmpty() ? exception.getMessage() : constant.initFailed(); console.printError(errorMessage); Notification notification = new Notification(errorMessage, ERROR); notificationManager.showNotification(notification); } }); } @Inject  ShowProjectGitReadOnlyUrlPresenter(ShowProjectGitReadOnlyUrlView view,
                                              GitServiceClient service,
                                              AppContext appContext,
                                              GitLocalizationConstant constant,
                                              GitOutputPartPresenter console,
                                              NotificationManager notificationManager,
                                              DtoUnmarshallerFactory dtoUnmarshallerFactory); void showDialog(); @Override void onCloseClicked();  }
@Test public void getGitReadOnlyUrlAsyncCallbackIsSuccess() throws Exception { presenter.showDialog(); verify(service).getGitReadOnlyUrl((ProjectDescriptor)anyObject(), asyncRequestCallbackGitReadOnlyUrlCaptor.capture()); AsyncRequestCallback<String> callback = asyncRequestCallbackGitReadOnlyUrlCaptor.getValue(); Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, LOCALE_URI); verify(appContext).getCurrentProject(); verify(service).getGitReadOnlyUrl(eq(rootProjectDescriptor), (AsyncRequestCallback<String>)anyObject()); verify(view).setLocaleUrl(eq(LOCALE_URI)); }
@Test public void getGitReadOnlyUrlAsyncCallbackIsFailed() throws Exception { presenter.showDialog(); verify(service).getGitReadOnlyUrl((ProjectDescriptor)anyObject(), asyncRequestCallbackGitReadOnlyUrlCaptor.capture()); AsyncRequestCallback<String> callback = asyncRequestCallbackGitReadOnlyUrlCaptor.getValue(); Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onSuccess.invoke(callback, mock(Throwable.class)); verify(appContext).getCurrentProject(); verify(service).getGitReadOnlyUrl(eq(rootProjectDescriptor), (AsyncRequestCallback<String>)anyObject()); verify(notificationManager).showNotification((Notification)anyObject()); verify(console).printError(anyString()); verify(constant).initFailed(); }
@Test public void getGitRemoteListAsyncCallbackIsSuccess() throws Exception { final List<Remote> remotes = new ArrayList<>(); remotes.add(mock(Remote.class)); presenter.showDialog(); verify(service) .remoteList((ProjectDescriptor)anyObject(), anyString(), anyBoolean(), asyncRequestCallbackRemoteListCaptor.capture()); AsyncRequestCallback<List<Remote>> callback = asyncRequestCallbackRemoteListCaptor.getValue(); Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, remotes); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(true), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(view).setRemotes((List<Remote>)anyObject()); }
@Test public void getGitRemoteListAsyncCallbackIsFailed() throws Exception { final List<Remote> remotes = new ArrayList<>(); remotes.add(mock(Remote.class)); presenter.showDialog(); verify(service) .remoteList((ProjectDescriptor)anyObject(), anyString(), anyBoolean(), asyncRequestCallbackRemoteListCaptor.capture()); AsyncRequestCallback<List<Remote>> callback = asyncRequestCallbackRemoteListCaptor.getValue(); Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onSuccess.invoke(callback, mock(Throwable.class)); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(true), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(view).setRemotes(null); verify(console).printError(anyString()); verify(notificationManager).showNotification((Notification)anyObject()); }