public void addBranch(final Branch branch) { branches.put(branch.getName(), branch); } }
private Collection<String> toBranchNames(final Collection<Branch> branches) { final ArrayList<String> result = new ArrayList<>(); for (final Branch branch : branches) { result.add(branch.getName()); } return result; } }
private boolean hasBranchBeenRemoved(final Repository repository, final String branchName) { return !repository .getBranches() .stream() .anyMatch(branch -> branch.getName().equals(branchName)); }
@Override protected DefExplorerQuery createRefreshQuery() { return new DefExplorerQuery(activeOrganizationalUnit, activeRepository, activeModule, activeRepository.getDefaultBranch().get().getName()); }
@Override public void onNewRepositoryAdded(final Repository repository) { addRepositoryItem(repository, repository.getDefaultBranch().get().getName()); }
private Branch makeBranch(String branchName) { final Branch branch = mock(Branch.class); doReturn(branchName).when(branch).getName(); return branch; } }
public void onNewRepository(final @Observes NewRepositoryEvent event) { final Repository newRepository = event.getNewRepository(); if (newRepository.getDefaultBranch().isPresent()) { aliasBranch.put(newRepository.getAlias(), newRepository.getDefaultBranch().get().getName()); } for (final GuvnorStructureContextChangeHandler handler : handlers.values()) { handler.onNewRepositoryAdded(newRepository); } }
private Branch mockBranch(final String branchName) { final Branch masterBranch = mock(Branch.class); doReturn(branchName).when(masterBranch).getName(); return masterBranch; }
private Branch mockBranch(final String branchName) { final Branch masterBranch = mock(Branch.class); doReturn(branchName).when(masterBranch).getName(); return masterBranch; }
private void updateBranch(final Repository repository) { if (!repository.getDefaultBranch().isPresent()) { return; } final String branchName = aliasBranch.get(repository.getAlias()); if (branchName == null || hasBranchBeenRemoved(repository, branchName)) { aliasBranch.put(repository.getAlias(), repository.getDefaultBranch().get().getName()); } }
@PostConstruct public void setup() { view.init(AddBranchPopUpPresenter.this); project = libraryPlaces.getActiveWorkspace(); view.setBranches(project.getRepository().getBranches().stream().map(Branch::getName).sorted(SortHelper.ALPHABETICAL_ORDER_COMPARATOR).collect(Collectors.toList())); view.setBranchFrom(project.getBranch().getName()); }
private void populateBranches(final String currentBranch) { final ArrayList<Branch> branches = new ArrayList<>(repository.getBranches()); Collections.reverse(branches); view.clearBranches(); for (Branch branch : branches) { view.addBranch(branch.getName()); } view.setSelectedBranch(currentBranch); }
private void updateRepository(final Repository repository) { if (!repository.getDefaultBranch().isPresent()) { return; } if (isNewRepository(repository)) { aliasBranch.put(repository.getAlias(), repository.getDefaultBranch().get().getName()); } else { updateBranch(repository); } }
private void fireNewBranchEvent(final Path targetRoot, final org.uberfire.java.nio.file.Path nioTargetRepositoryRoot) { final Repository repository = repoService.getRepository(targetRoot); final Optional<Branch> branch = repository.getBranch(Paths.convert(nioTargetRepositoryRoot.getRoot())); if (branch.isPresent()) { newBranchEvent.fire(new NewBranchEvent(repository, branch.get().getName(), sessionInfo.getIdentity())); } else { throw new IllegalStateException("Could not find a branch that was just created. The Path used was " + nioTargetRepositoryRoot.getRoot()); } }
@Test public void testShowDeleteIfIsAbleTo() { this.presenter.show(branch); verify(this.view).show(eq(branch.getName())); }
@Test public void newBranchCreatedByOtherUserShouldNotBeOpened() { final User otherUser = mock(User.class); when(otherUser.getIdentifier()).thenReturn("otherUser"); doReturn(false).when(libraryPlaces).isThisUserAccessingThisRepository(otherUser, repository); presenter.newBranchEvent(new NewBranchEvent(repository, newBranch.getName(), otherUser)); verify(libraryPlaces, never()).goToProject(project, newBranch); }
@Before public void setUp() { when(libraryPlaces.getActiveWorkspace()).thenReturn(project); when(project.getRepository().getDefaultBranch()).thenReturn(Optional.of(branch)); when(branch.getName()).thenReturn("myBranch"); presenter = spy(new DeleteBranchPopUpScreen(view, new CallerMock<>(libraryService), libraryPlaces)); }
public boolean userCanDeleteBranch(final WorkspaceProject project) { return (userIsAtLeast(ContributorType.ADMIN, project.getRepository().getContributors()) || userIsAtLeast(ContributorType.ADMIN, project.getOrganizationalUnit().getContributors()) || userCanDeleteProject(project)) && !project.getBranch().getName().equals("master"); }
@Test public void lastBranchOpenedExists() { final WorkspaceProject project = makeProject("space", "repo", "master"); final Branch masterBranch = makeBranch("master"); libraryInternalPreferences.setLastBranchOpened(project, masterBranch); assertEquals(masterBranch.getName(), libraryInternalPreferences.getLastBranchOpened(project).get().getName()); }
@Test public void newBranchCreatedByUserShouldBeOpened() { doReturn(true).when(libraryPlaces).isThisUserAccessingThisRepository(user, repository); presenter.newBranchEvent(new NewBranchEvent(repository, newBranch.getName(), user)); verify(libraryPlaces).goToProject(project, newBranch); }