FetchPresenter implements FetchView.ActionDelegate { public void showDialog() { project = appContext.getCurrentProject(); view.setRemoveDeleteRefs(false); view.setFetchAllBranches(true); updateRemotes(); } @Inject  FetchPresenter(DtoFactory dtoFactory,
                          FetchView view,
                          GitOutputPartPresenter console,
                          GitServiceClient service,
                          AppContext appContext,
                          GitLocalizationConstant constant,
                          NotificationManager notificationManager,
                          DtoUnmarshallerFactory dtoUnmarshallerFactory,
                          BranchSearcher branchSearcher); void showDialog(); @Override void onFetchClicked(); @Override void onCancelClicked(); @Override void onValueChanged(); @Override void onRemoteBranchChanged(); @Override void onRemoteRepositoryChanged();  }
@Test public void testShowDialogWhenBranchListRequestIsSuccessful() throws Exception { final List<Remote> remotes = new ArrayList<>(); remotes.add(mock(Remote.class)); final List<Branch> branches = new ArrayList<>(); branches.add(branch); 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()); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<List<Branch>> callback = (AsyncRequestCallback<List<Branch>>)arguments[2]; Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, branches); return callback; } }).doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<List<Branch>> callback = (AsyncRequestCallback<List<Branch>>)arguments[2]; Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, branches); return callback; } }).when(service).branchList((ProjectDescriptor)anyObject(), anyString(), (AsyncRequestCallback<List<Branch>>)anyObject()); presenter.showDialog(); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(SHOW_ALL_INFORMATION), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(view).setEnableFetchButton(eq(ENABLE_BUTTON)); verify(view).setRepositories((List<Remote>)anyObject()); verify(view).setRemoveDeleteRefs(eq(NO_REMOVE_DELETE_REFS)); verify(view).setFetchAllBranches(eq(FETCH_ALL_BRANCHES)); verify(view).showDialog(); verify(view).setRemoteBranches((List<String>)anyObject()); verify(view).setLocalBranches((List<String>)anyObject()); }
@Test public void testShowDialogWhenBranchListRequestIsFailed() throws Exception { final List<Remote> remotes = new ArrayList<>(); remotes.add(mock(Remote.class)); 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()); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<List<Branch>> callback = (AsyncRequestCallback<List<Branch>>)arguments[2]; Method onFailure = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onFailure.invoke(callback, mock(Throwable.class)); return callback; } }).doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<List<Branch>> callback = (AsyncRequestCallback<List<Branch>>)arguments[2]; Method onFailure = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onFailure.invoke(callback, mock(Throwable.class)); return callback; } }).when(service).branchList((ProjectDescriptor)anyObject(), anyString(), (AsyncRequestCallback<List<Branch>>)anyObject()); presenter.showDialog(); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(SHOW_ALL_INFORMATION), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(constant).branchesListFailed(); verify(console).printError(anyString()); verify(notificationManager).showError(anyString()); verify(view).setEnableFetchButton(eq(DISABLE_BUTTON)); }
@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(); verify(view).setEnableFetchButton(eq(DISABLE_BUTTON)); }