RemotePresenter implements RemoteView.ActionDelegate { public void showDialog() { project = appContext.getCurrentProject().getRootProject(); getRemotes(); } @Inject  RemotePresenter(RemoteView view,
                           GitServiceClient service,
                           AppContext appContext,
                           GitLocalizationConstant constant,
                           AddRemoteRepositoryPresenter addRemoteRepositoryPresenter,
                           NotificationManager notificationManager,
                           DtoUnmarshallerFactory dtoUnmarshallerFactory,
                           GitOutputPartPresenter console); void showDialog(); @Override void onCloseClicked(); @Override void onAddClicked(); @Override void onDeleteClicked(); @Override void onRemoteSelected(Remote remote);  }
@Test public void testShowDialogWhenRemoteListRequestIsSuccessful() throws Exception { final List<Remote> remotes = new ArrayList<>(); remotes.add(selectedRemote); when(view.isShown()).thenReturn(!IS_SHOWN); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<List<Remote>> callback = (AsyncRequestCallback<List<Remote>>)arguments[3]; Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, remotes); return callback; } }).when(service).remoteList((ProjectDescriptor)anyObject(), anyString(), anyBoolean(), (AsyncRequestCallback<List<Remote>>)anyObject()); presenter.showDialog(); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(SHOW_ALL_INFORMATION), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(view).setEnableDeleteButton(eq(DISABLE_BUTTON)); verify(view).setRemotes((List<Remote>)anyObject()); verify(view).showDialog(); }
@Test public void testShowDialogWhenRemoteListRequestIsFailed() throws Exception { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<List<Remote>> callback = (AsyncRequestCallback<List<Remote>>)arguments[3]; Method onFailure = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onFailure.invoke(callback, mock(Throwable.class)); return callback; } }).when(service).remoteList((ProjectDescriptor)anyObject(), anyString(), anyBoolean(), (AsyncRequestCallback<List<Remote>>)anyObject()); presenter.showDialog(); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(SHOW_ALL_INFORMATION), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(constant).remoteListFailed(); }