BranchFilterByRemote { public String getBranchNameWithoutRefs(Branch branch) { return branch.getName().replaceFirst(refsForRemoteRepository, "") .replaceFirst("refs/heads/", ""); } BranchFilterByRemote(String remoteName); boolean isLinkedTo(Branch branch); String getBranchNameWithoutRefs(Branch branch);  }
@Test public void shouldDetermineSimpleBranchNameWhenBranchNameContainsRefs() throws Exception { String branchName = "master"; when(branch.getName()).thenReturn("refs/remotes/" + REMOTE_NAME + "/" + branchName); assertEquals(branchFilterByRemote.getBranchNameWithoutRefs(branch), branchName); }
@Test public void shouldJustReturnBranchNameWhenBranchNameContainsRefsToAnotherRemote() throws Exception { String branchName = "master"; when(branch.getName()).thenReturn("refs/remotes/" + ANOTHER_REMOTE_NAME + "/" + branchName); assertNotEquals(branchFilterByRemote.getBranchNameWithoutRefs(branch), branchName); }
@Test public void shouldDetermineSimpleBranchNameWhenBranchNameIsSimpleName() throws Exception { String branchName = "master"; when(branch.getName()).thenReturn(branchName); assertEquals(branchFilterByRemote.getBranchNameWithoutRefs(branch), branchName); }