BranchPresenter implements BranchView.ActionDelegate { @Override public void onCheckoutClicked() { String name = selectedBranch.getDisplayName(); if (name == null) { return; } final CheckoutRequest checkoutRequest = dtoFactory.createDto(CheckoutRequest.class); if (selectedBranch.isRemote()) { checkoutRequest.setTrackBranch(selectedBranch.getDisplayName()); } else { checkoutRequest.setName(selectedBranch.getDisplayName()); } service.checkout(project.getRootProject(), checkoutRequest, new AsyncRequestCallback<String>() { @Override protected void onSuccess(String result) { getBranches(); projectExplorer.reloadChildren(); updateOpenedFiles(); } @Override protected void onFailure(Throwable exception) { printGitMessage(exception.getMessage()); } }); } @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 testOnCheckoutClickedWhenSelectedNotRemoteBranch() throws Exception { when(selectedBranch.isRemote()).thenReturn(false); when(dtoFactory.createDto(CheckoutRequest.class)).thenReturn(checkoutRequest); selectBranch(); presenter.onCheckoutClicked(); verify(checkoutRequest).setName(eq(BRANCH_NAME)); verifyNoMoreInteractions(checkoutRequest); verify(service).checkout(eq(rootProjectDescriptor), eq(checkoutRequest), asyncRequestCallbackCaptor.capture()); }
@Test public void testOnCheckoutClickedWhenSelectedRemoteBranch() throws Exception { when(dtoFactory.createDto(CheckoutRequest.class)).thenReturn(checkoutRequest); selectBranch(); presenter.onCheckoutClicked(); verify(checkoutRequest).setTrackBranch(eq(BRANCH_NAME)); verifyNoMoreInteractions(checkoutRequest); verify(service).checkout(eq(rootProjectDescriptor), eq(checkoutRequest), asyncRequestCallbackCaptor.capture()); }
@Test public void testOnCheckoutClickedWhenCheckoutRequestAndRefreshProjectIsSuccessful() throws Exception { when(dtoFactory.createDto(CheckoutRequest.class)).thenReturn(checkoutRequest); VirtualFile virtualFile = mock(VirtualFile.class); when(editorInput.getFile()).thenReturn(virtualFile); when(virtualFile.getPath()).thenReturn("/foo"); selectBranch(); presenter.onCheckoutClicked(); verify(checkoutRequest).setTrackBranch(eq(BRANCH_NAME)); verifyNoMoreInteractions(checkoutRequest); verify(service).checkout(eq(rootProjectDescriptor), eq(checkoutRequest), asyncRequestCallbackCaptor.capture()); AsyncRequestCallback<String> checkoutBranchCallback = asyncRequestCallbackCaptor.getValue(); GwtReflectionUtils.callOnSuccess(checkoutBranchCallback, PROJECT_PATH); verify(editorAgent).getOpenedEditors(); verify(selectedBranch, times(2)).getDisplayName(); verify(selectedBranch).isRemote(); verify(service).checkout(eq(rootProjectDescriptor), eq(checkoutRequest), anyObject()); verify(service, times(2)).branchList(eq(rootProjectDescriptor), eq(LIST_ALL), anyObject()); verify(appContext).getCurrentProject(); verify(console, never()).printError(anyString()); verify(notificationManager, never()).showError(anyString()); verify(eventBus).fireEvent(Matchers.<FileContentUpdateEvent>anyObject()); verify(constant, never()).branchCheckoutFailed(); }
@Test public void testOnCheckoutClickedWhenCheckoutRequestAndRefreshProjectIsSuccessfulButOpenFileIsNotExistInBranch() throws Exception { when(dtoFactory.createDto(CheckoutRequest.class)).thenReturn(checkoutRequest); VirtualFile virtualFile = mock(VirtualFile.class); when(editorInput.getFile()).thenReturn(virtualFile); when(virtualFile.getPath()).thenReturn("/foo"); selectBranch(); presenter.onCheckoutClicked(); verify(checkoutRequest).setTrackBranch(eq(BRANCH_NAME)); verifyNoMoreInteractions(checkoutRequest); verify(service).checkout(eq(rootProjectDescriptor), eq(checkoutRequest), asyncRequestCallbackCaptor.capture()); AsyncRequestCallback<String> checkoutBranchCallback = asyncRequestCallbackCaptor.getValue(); GwtReflectionUtils.callOnSuccess(checkoutBranchCallback, PROJECT_PATH); verify(editorAgent).getOpenedEditors(); verify(selectedBranch, times(2)).getDisplayName(); verify(selectedBranch).isRemote(); verify(service, times(2)).branchList(eq(rootProjectDescriptor), eq(LIST_ALL), anyObject()); verify(eventBus).fireEvent(Matchers.<FileContentUpdateEvent>anyObject()); verify(appContext).getCurrentProject(); }
@Test public void testOnCheckoutClickedWhenCheckoutRequestIsFailed() throws Exception { when(dtoFactory.createDto(CheckoutRequest.class)).thenReturn(checkoutRequest); selectBranch(); presenter.onCheckoutClicked(); verify(checkoutRequest).setTrackBranch(eq(BRANCH_NAME)); verifyNoMoreInteractions(checkoutRequest); verify(service).checkout(eq(rootProjectDescriptor), eq(checkoutRequest), asyncRequestCallbackCaptor.capture()); AsyncRequestCallback<String> checkoutBranchCallback = asyncRequestCallbackCaptor.getValue(); GwtReflectionUtils.callOnFailure(checkoutBranchCallback, mock(Throwable.class)); verify(selectedBranch, times(2)).getDisplayName(); verify(selectedBranch).isRemote(); }