@Test(timeOut = 1000) public void testGetGHRepositories() throws Exception { Multimap<String, String> parentToPath = HashMultimap.create(); parentToPath.put("test1", "test"); parentToPath.put("test2", "correct"); parentToPath.put("test3", "test"); parentToPath.put("test4", "test"); 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); List<GHRepository> actualList = gitHubUtil.getGHRepositories(parentToPath, currentUser); List<GHRepository> expectedList = new ArrayList<>(); expectedList.add(repo1); expectedList.add(repo2); expectedList.add(repo3); expectedList.add(repo4); assertEquals(expectedList.size(), actualList.size()); assertTrue(actualList.containsAll(expectedList)); assertTrue(expectedList.containsAll(actualList)); }
public List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo, GHMyself currentUser) throws InterruptedException { List<GHRepository> listOfRepos = new ArrayList<>(); while (true) { Map<String, GHRepository> repoByName = getReposForUserAtCurrentInstant(currentUser); boolean listOfReposHasRecentForks = true; for (String s : pathToDockerfileInParentRepo.keySet()) { String forkName = s.substring(s.lastIndexOf('/') + 1); log.info(String.format("Verifying that %s has been forked", forkName)); if (repoByName.containsKey(forkName)) { listOfRepos.add(repoByName.get(forkName)); } else { log.debug("Forking is still in progress for {}" , forkName); listOfReposHasRecentForks = false; } } if (listOfReposHasRecentForks) { break; } else { log.info("Waiting for GitHub API cache to clear..."); waitFor(TimeUnit.MINUTES.toMillis(1)); } } return listOfRepos; }
GitHubUtil { public List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo, GHMyself currentUser) throws InterruptedException { List<GHRepository> listOfRepos = new ArrayList<>(); while (true) { Map<String, GHRepository> repoByName = getReposForUserAtCurrentInstant(currentUser); boolean listOfReposHasRecentForks = true; for (String s : pathToDockerfileInParentRepo.keySet()) { String forkName = s.substring(s.lastIndexOf('/') + 1); log.info(String.format("Verifying that %s has been forked", forkName)); if (repoByName.containsKey(forkName)) { listOfRepos.add(repoByName.get(forkName)); } else { log.debug("Forking is still in progress for {}" , forkName); listOfReposHasRecentForks = false; } } if (listOfReposHasRecentForks) { break; } else { log.info("Waiting for GitHub API cache to clear..."); waitFor(TimeUnit.MINUTES.toMillis(1)); } } return listOfRepos; } }
GitHubUtil { public List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo, GHMyself currentUser) throws InterruptedException { List<GHRepository> listOfRepos = new ArrayList<>(); while (true) { Map<String, GHRepository> repoByName = getReposForUserAtCurrentInstant(currentUser); boolean listOfReposHasRecentForks = true; for (String s : pathToDockerfileInParentRepo.keySet()) { String forkName = s.substring(s.lastIndexOf('/') + 1); log.info(String.format("Verifying that %s has been forked", forkName)); if (repoByName.containsKey(forkName)) { listOfRepos.add(repoByName.get(forkName)); } else { log.debug("Forking is still in progress for {}" , forkName); listOfReposHasRecentForks = false; } } if (listOfReposHasRecentForks) { break; } else { log.info("Waiting for GitHub API cache to clear..."); waitFor(TimeUnit.MINUTES.toMillis(1)); } } return listOfRepos; } GitHubUtil(GitHub gitHub); }
GitHubUtil { public List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo, GHMyself currentUser) throws InterruptedException { List<GHRepository> listOfRepos = new ArrayList<>(); while (true) { Map<String, GHRepository> repoByName = getReposForUserAtCurrentInstant(currentUser); boolean listOfReposHasRecentForks = true; for (String s : pathToDockerfileInParentRepo.keySet()) { String forkName = s.substring(s.lastIndexOf('/') + 1); log.info(String.format("Verifying that %s has been forked", forkName)); if (repoByName.containsKey(forkName)) { listOfRepos.add(repoByName.get(forkName)); } else { log.debug("Forking is still in progress for {}" , forkName); listOfReposHasRecentForks = false; } } if (listOfReposHasRecentForks) { break; } else { log.info("Waiting for GitHub API cache to clear..."); waitFor(TimeUnit.MINUTES.toMillis(1)); } } return listOfRepos; } 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); }
GitHubUtil { public List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo, GHMyself currentUser) throws InterruptedException { List<GHRepository> listOfRepos = new ArrayList<>(); while (true) { Map<String, GHRepository> repoByName = getReposForUserAtCurrentInstant(currentUser); boolean listOfReposHasRecentForks = true; for (String s : pathToDockerfileInParentRepo.keySet()) { String forkName = s.substring(s.lastIndexOf('/') + 1); log.info(String.format("Verifying that %s has been forked", forkName)); if (repoByName.containsKey(forkName)) { listOfRepos.add(repoByName.get(forkName)); } else { log.debug("Forking is still in progress for {}" , forkName); listOfReposHasRecentForks = false; } } if (listOfReposHasRecentForks) { break; } else { log.info("Waiting for GitHub API cache to clear..."); waitFor(TimeUnit.MINUTES.toMillis(1)); } } return listOfRepos; } 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; }