PushToRemotePresenter implements PushToRemoteView.ActionDelegate { public void showDialog() { project = appContext.getCurrentProject(); updateRemotes(); } @Inject  PushToRemotePresenter(DtoFactory dtoFactory,
                                 PushToRemoteView view,
                                 GitServiceClient service,
                                 GitOutputPartPresenter console,
                                 AppContext appContext,
                                 GitLocalizationConstant constant,
                                 NotificationManager notificationManager,
                                 DtoUnmarshallerFactory dtoUnmarshallerFactory,
                                 BranchSearcher branchSearcher); void showDialog(); @Override void onPushClicked(); @Override void onCancelClicked(); @Override void onLocalBranchChanged(); @Override void onRepositoryChanged();  }
@Test public void testShowDialogWhenLocalBranchListRequestIsFailed() throws Exception { final List<Remote> remotes = new ArrayList<>(); remotes.add(mock(Remote.class)); presenter.showDialog(); verify(service).remoteList((ProjectDescriptor)anyObject(), anyString(), anyBoolean(), asyncRequestCallbackArrayRemoteCaptor.capture()); AsyncRequestCallback<List<Remote>> remoteCallback = asyncRequestCallbackArrayRemoteCaptor.getValue(); Method onSuccessRemotes = GwtReflectionUtils.getMethod(remoteCallback.getClass(), "OnSuccess"); onSuccessRemotes.invoke(remoteCallback, remotes); verify(service).branchList((ProjectDescriptor)anyObject(), anyString(), asyncRequestCallbackArrayBranchCaptor.capture()); AsyncRequestCallback<List<Branch>> branchesCallback = asyncRequestCallbackArrayBranchCaptor.getValue(); Method onFailureBranches = GwtReflectionUtils.getMethod(branchesCallback.getClass(), "onFailure"); onFailureBranches.invoke(branchesCallback, mock(Throwable.class)); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(SHOW_ALL_INFORMATION), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(constant, times(2)).localBranchesListFailed(); verify(console).printError(anyString()); verify(notificationManager).showError(anyString()); verify(view).setEnablePushButton(eq(DISABLE_BUTTON)); }
@Test public void testShowDialogWhenRemoteListRequestIsFailed() throws Exception { presenter.showDialog(); verify(service).remoteList((ProjectDescriptor)anyObject(), anyString(), anyBoolean(), asyncRequestCallbackArrayRemoteCaptor.capture()); AsyncRequestCallback<List<Remote>> branchesCallback = asyncRequestCallbackArrayRemoteCaptor.getValue(); Method onFailureBranches = GwtReflectionUtils.getMethod(branchesCallback.getClass(), "onFailure"); onFailureBranches.invoke(branchesCallback, mock(Throwable.class)); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(SHOW_ALL_INFORMATION), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(constant, times(2)).remoteListFailed(); verify(console).printError(anyString()); verify(notificationManager).showError(anyString()); verify(view).setEnablePushButton(eq(DISABLE_BUTTON)); }
@Test public void testShowDialogWhenAllRequestsAreSuccessful() throws Exception { final List<Remote> remotes = new ArrayList<>(); remotes.add(mock(Remote.class)); final List<Branch> branches = new ArrayList<>(); branches.add(localBranch); final List<String> names_branches = new ArrayList<>(); names_branches.add(LOCAL_BRANCH); when(branchSearcher.getLocalBranchesToDisplay((List<Branch>)anyObject())).thenReturn(names_branches); List<String> list = new ArrayList<>(); list.add(remoteBranch.getDisplayName()); when(branchSearcher.getRemoteBranchesToDisplay((BranchFilterByRemote)anyObject(), (List<Branch>)anyObject())).thenReturn(list); presenter.showDialog(); verify(service).remoteList((ProjectDescriptor)anyObject(), anyString(), anyBoolean(), asyncRequestCallbackArrayRemoteCaptor.capture()); AsyncRequestCallback<List<Remote>> remotesCallback = asyncRequestCallbackArrayRemoteCaptor.getValue(); Method onSuccessRemotes = GwtReflectionUtils.getMethod(remotesCallback.getClass(), "onSuccess"); onSuccessRemotes.invoke(remotesCallback, remotes); verify(service).branchList((ProjectDescriptor)anyObject(), anyString(), asyncRequestCallbackArrayBranchCaptor.capture()); AsyncRequestCallback<List<Branch>> branchesCallback = asyncRequestCallbackArrayBranchCaptor.getValue(); Method onSuccessBranches = GwtReflectionUtils.getMethod(branchesCallback.getClass(), "onSuccess"); onSuccessBranches.invoke(branchesCallback, branches); verify(service, times(2)).branchList((ProjectDescriptor)anyObject(), anyString(), asyncRequestCallbackArrayBranchCaptor.capture()); branchesCallback = asyncRequestCallbackArrayBranchCaptor.getValue(); onSuccessBranches = GwtReflectionUtils.getMethod(branchesCallback.getClass(), "onSuccess"); onSuccessBranches.invoke(branchesCallback, branches); verify(service).config((ProjectDescriptor)anyObject(), anyListOf(String.class), asyncRequestCallbackMapCaptor.capture()); AsyncRequestCallback<Map<String, String>> value = asyncRequestCallbackMapCaptor.getValue(); Method config = GwtReflectionUtils.getMethod(value.getClass(), "onSuccess"); config.invoke(value, new HashMap<String, String>()); verify(appContext).getCurrentProject(); verify(service).remoteList(eq(rootProjectDescriptor), anyString(), eq(SHOW_ALL_INFORMATION), (AsyncRequestCallback<List<Remote>>)anyObject()); verify(view).setEnablePushButton(eq(ENABLE_BUTTON)); verify(view).setRepositories((List<Remote>)anyObject()); verify(view).showDialog(); verify(view).setRemoteBranches((List<String>)anyObject()); verify(view).setLocalBranches((List<String>)anyObject()); }