### Question:
AddBranchPopUpPresenter { public void add() { final String name = view.getName(); final String branchFrom = view.getBranchFrom(); beginBranchCreation(); validateFields(name, () -> libraryService.call(v -> { endBranchCreation(); notifySuccess(); view.hide(); }, getErrorCallback()).addBranch(name, branchFrom, project)); } @Inject  AddBranchPopUpPresenter(final Caller<LibraryService> libraryService,
                                   final BusyIndicatorView busyIndicatorView,
                                   final Event<NotificationEvent> notificationEvent,
                                   final LibraryPlaces libraryPlaces,
                                   final View view,
                                   final Caller<ValidationService> validationService); @PostConstruct void setup(); void show(); void add(); void cancel();  }### Answer:
@Test public void newBranchIsCreated() throws Exception { doReturn("new-branch").when(view).getName(); doReturn("master").when(view).getBranchFrom(); presenter.add(); final ArgumentCaptor<POM> pomArgumentCaptor = ArgumentCaptor.forClass(POM.class); verify(view).setAddButtonEnabled(false); verify(view).showBusyIndicator(anyString()); verify(libraryService).addBranch("new-branch", "master", project); verify(view).setAddButtonEnabled(true); verify(view).hideBusyIndicator(); }
@Test public void createProjectWithDuplicatedNameTest() { doReturn("new-branch").when(view).getName(); doReturn("master").when(view).getBranchFrom(); doThrow(new FileAlreadyExistsException()).when(libraryService).addBranch(any(), any(), any()); presenter.add(); verify(view).setAddButtonEnabled(false); verify(view).showBusyIndicator(anyString()); verify(view).hideBusyIndicator(); verify(view, never()).hide(); verify(view).showError(anyString()); verify(view).setAddButtonEnabled(true); }
@Test public void createProjectWithEmptyNameFailedTest() { doReturn("").when(view).getName(); doReturn("master").when(view).getBranchFrom(); presenter.add(); verify(view).setAddButtonEnabled(false); verify(view).showBusyIndicator(anyString()); verify(view).hideBusyIndicator(); verify(view, never()).hide(); verify(view).showError(anyString()); verify(view).setAddButtonEnabled(true); }
@Test public void createProjectWithInvalidNameFailedTest() { doReturn("name").when(view).getName(); doReturn(false).when(validationService).isBranchNameValid(any()); presenter.add(); verify(view).setAddButtonEnabled(false); verify(view).showBusyIndicator(anyString()); verify(view).hideBusyIndicator(); verify(view, never()).hide(); verify(view).showError(anyString()); verify(view).setAddButtonEnabled(true); }