GitHubUtil { public boolean repoHasBranch(GHRepository repo, String branchName) throws IOException { try { GHBranch branch = repo.getBranch(branchName); return branch != null; } catch (GHFileNotFoundException exception) { return false; } } GitHubUtil(GitHub gitHub); GitHub getGithub(); GHRepository getRepo(String repo); GHRepository createPublicRepo(String repoName); GHMyself getMyself(); GHContentSearchBuilder startSearch(); GHRepository createFork(GHRepository repo); void safeDeleteRepo(GHRepository repo); int createPullReq(GHRepository origRepo, String branch,
                                 GHRepository forkRepo, String title, String body); GHRepository tryRetrievingRepository(String repoName); GHContent tryRetrievingContent(GHRepository repo, String path, String branch); List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo,
                                                 GHMyself currentUser); boolean repoHasBranch(GHRepository repo, String branchName); Map<String, GHRepository> getReposForUserAtCurrentInstant(GHMyself user); static final String NO_BRANCH_WARN_FORMAT; }
@Test public void testRepoHasBranchTrue() throws IOException { GitHubUtil gitHubUtil = mock(GitHubUtil.class); when(gitHubUtil.repoHasBranch(any(), any())).thenCallRealMethod(); GHRepository repo = mock(GHRepository.class); String branchName = "some-branch"; when(repo.getBranch(branchName)).thenReturn(mock(GHBranch.class)); assertTrue(gitHubUtil.repoHasBranch(repo, branchName)); }
@Test public void testRepoHasBranchFalseIfNoBranchReturned() throws IOException { GitHubUtil gitHubUtil = mock(GitHubUtil.class); when(gitHubUtil.repoHasBranch(any(), any())).thenCallRealMethod(); GHRepository repo = mock(GHRepository.class); String branchName = "some-branch"; when(repo.getBranch(branchName)).thenReturn(null); assertFalse(gitHubUtil.repoHasBranch(repo, branchName)); }
@Test public void testRepoHasBranchFalseForGHFileNotFoundException() throws IOException { GitHubUtil gitHubUtil = mock(GitHubUtil.class); when(gitHubUtil.repoHasBranch(any(), any())).thenCallRealMethod(); GHRepository repo = mock(GHRepository.class); String branchName = "some-branch"; when(repo.getBranch(branchName)).thenThrow(new GHFileNotFoundException()); assertFalse(gitHubUtil.repoHasBranch(repo, branchName)); }