GitHubUtil { public Map<String, GHRepository> getReposForUserAtCurrentInstant(GHMyself user) { Map<String, GHRepository> repoByName = new HashMap<>(); if (user == null) { return repoByName; } PagedIterable<GHRepository> reposIterator = user.listRepositories(100, GHMyself.RepositoryListFilter.OWNER); for (GHRepository repo: reposIterator) { repoByName.put(repo.getName(), repo); } return repoByName; } 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 testGetReposForUserAtCurrentInstant() throws Exception { GHMyself currentUser = mock(GHMyself.class); PagedIterable<GHRepository> listOfRepos = mock(PagedIterable.class); GHRepository repo1 = mock(GHRepository.class); when(repo1.getName()).thenReturn("test1"); GHRepository repo2 = mock(GHRepository.class); when(repo2.getName()).thenReturn("test2"); GHRepository repo3 = mock(GHRepository.class); when(repo3.getName()).thenReturn("test3"); GHRepository repo4 = mock(GHRepository.class); when(repo4.getName()).thenReturn("test4"); PagedIterator<GHRepository> listOfReposIterator = mock(PagedIterator.class); when(listOfReposIterator.hasNext()).thenReturn(true, true, true, true, false); when(listOfReposIterator.next()).thenReturn(repo1, repo2, repo3, repo4, null); when(listOfRepos.iterator()).thenReturn(listOfReposIterator); when(currentUser.listRepositories(100, GHMyself.RepositoryListFilter.OWNER)).thenReturn(listOfRepos); GitHub github = mock(GitHub.class); GitHubUtil gitHubUtil = new GitHubUtil(github); Map<String, GHRepository> repoByName = gitHubUtil.getReposForUserAtCurrentInstant(currentUser); assertEquals(repoByName.size(), 4); assertTrue(repoByName.containsKey("test1") && repoByName.get("test1") == repo1); assertTrue(repoByName.containsKey("test2") && repoByName.get("test2") == repo2); assertTrue(repoByName.containsKey("test3") && repoByName.get("test3") == repo3); assertTrue(repoByName.containsKey("test4") && repoByName.get("test4") == repo4); }
@Test public void testGetReposForUserAtCurrentInstantWithNullUser() throws Exception { GitHub github = mock(GitHub.class); GitHubUtil gitHubUtil = new GitHubUtil(github); Map<String, GHRepository> repoByName = gitHubUtil.getReposForUserAtCurrentInstant(null); assertEquals(repoByName.size(), 0); }