BranchPresenter implements BranchView.ActionDelegate { @Override public void onRenameClicked() { if (selectedBranch.isRemote()) { dialogFactory.createConfirmDialog(constant.branchConfirmRenameTitle(), constant.branchConfirmRenameMessage(), getConfirmRenameBranchCallback(), null).show(); } else { renameBranch(); } } @Inject  BranchPresenter(BranchView view,
                           DtoFactory dtoFactory,
                           EditorAgent editorAgent,
                           GitServiceClient service,
                           GitLocalizationConstant constant,
                           GitOutputPartPresenter console,
                           AppContext appContext,
                           NotificationManager notificationManager,
                           DtoUnmarshallerFactory dtoUnmarshallerFactory,
                           GitOutputPartPresenter gitConsole,
                           WorkspaceAgent workspaceAgent,
                           DialogFactory dialogFactory,
                           ProjectExplorerPresenter projectExplorer,
                           EventBus eventBus); void showBranches(); @Override void onCloseClicked(); @Override void onRenameClicked(); @Override void onDeleteClicked(); @Override void onCheckoutClicked(); @Override void onCreateClicked(); @Override void onBranchUnselected(); @Override void onBranchSelected(@NotNull Branch branch);  }
@Test public void testOnRenameClickedWhenLocalBranchSelected() throws Exception { reset(selectedBranch); when(selectedBranch.getDisplayName()).thenReturn(BRANCH_NAME); when(selectedBranch.isRemote()).thenReturn(false); InputDialog inputDialog = mock(InputDialog.class); when(dialogFactory.createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyObject(), anyObject())) .thenReturn(inputDialog); selectBranch(); presenter.onRenameClicked(); verify(dialogFactory).createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), inputCallbackCaptor.capture(), anyObject()); InputCallback inputCallback = inputCallbackCaptor.getValue(); inputCallback.accepted(RETURNED_MESSAGE); verify(service) .branchRename(eq(rootProjectDescriptor), eq(BRANCH_NAME), eq(RETURNED_MESSAGE), asyncRequestCallbackCaptor.capture()); AsyncRequestCallback<String> renameBranchCallback = asyncRequestCallbackCaptor.getValue(); GwtReflectionUtils.callOnSuccess(renameBranchCallback, PROJECT_PATH); verify(selectedBranch, times(2)).getDisplayName(); verify(service, times(2)).branchList(eq(rootProjectDescriptor), eq(LIST_ALL), anyObject()); verify(dialogFactory, never()).createConfirmDialog(anyString(), anyString(), anyObject(), anyObject()); verify(console, never()).printError(anyString()); verify(notificationManager, never()).showError(anyString()); verify(constant, never()).branchRenameFailed(); }
@Test public void testOnRenameClickedWhenRemoteBranchSelectedAndUserConfirmRename() throws Exception { reset(selectedBranch); when(selectedBranch.getDisplayName()).thenReturn(REMOTE_BRANCH_NAME); when(selectedBranch.isRemote()).thenReturn(true); InputDialog inputDialog = mock(InputDialog.class); when(dialogFactory.createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyObject(), anyObject())) .thenReturn(inputDialog); ConfirmDialog confirmDialog = mock(ConfirmDialog.class); when(dialogFactory.createConfirmDialog(anyString(), anyString(), anyObject(), anyObject())).thenReturn(confirmDialog); selectBranch(); presenter.onRenameClicked(); verify(dialogFactory).createConfirmDialog(anyString(), anyString(), confirmCallbackCaptor.capture(), anyObject()); ConfirmCallback confirmCallback = confirmCallbackCaptor.getValue(); confirmCallback.accepted(); verify(dialogFactory).createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), inputCallbackCaptor.capture(), anyObject()); InputCallback inputCallback = inputCallbackCaptor.getValue(); inputCallback.accepted(RETURNED_MESSAGE); verify(service).branchRename(eq(rootProjectDescriptor), eq(REMOTE_BRANCH_NAME), eq(RETURNED_MESSAGE), asyncRequestCallbackCaptor.capture()); AsyncRequestCallback<String> renameBranchCallback = asyncRequestCallbackCaptor.getValue(); GwtReflectionUtils.callOnSuccess(renameBranchCallback, PROJECT_PATH); verify(selectedBranch, times(2)).getDisplayName(); verify(service, times(2)) .branchList(eq(rootProjectDescriptor), eq(LIST_ALL), anyObject()); verify(console, never()).printError(anyString()); verify(notificationManager, never()).showError(anyString()); verify(constant, never()).branchRenameFailed(); }
@Test public void testOnRenameClickedWhenBranchRenameRequestIsFailed() throws Exception { when(selectedBranch.getDisplayName()).thenReturn(BRANCH_NAME); when(selectedBranch.isRemote()).thenReturn(false); InputDialog inputDialog = mock(InputDialog.class); when(dialogFactory.createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyObject(), anyObject())) .thenReturn(inputDialog); selectBranch(); presenter.onRenameClicked(); verify(dialogFactory).createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), inputCallbackCaptor.capture(), anyObject()); InputCallback inputCallback = inputCallbackCaptor.getValue(); inputCallback.accepted(RETURNED_MESSAGE); verify(service) .branchRename(eq(rootProjectDescriptor), eq(BRANCH_NAME), eq(RETURNED_MESSAGE), asyncRequestCallbackCaptor.capture()); AsyncRequestCallback<String> renameBranchCallback = asyncRequestCallbackCaptor.getValue(); GwtReflectionUtils.callOnFailure(renameBranchCallback, mock(Throwable.class)); verify(selectedBranch, times(2)).getDisplayName(); verify(console).printError(anyString()); verify(notificationManager).showError(anyString()); verify(constant).branchRenameFailed(); }