DockerfileGitHubUtil { public Optional<PagedSearchIterable<GHContent>> getGHContents(String org, String img) throws IOException, InterruptedException { PagedSearchIterable<GHContent> contentsWithImage = null; for (int i = 0; i < 5; i++) { contentsWithImage = findFilesWithImage(img, org); if (contentsWithImage.getTotalCount() > 0) { break; } else { getGitHubUtil().waitFor(TimeUnit.SECONDS.toMillis(1)); } } int numOfContentsFound = contentsWithImage.getTotalCount(); if (numOfContentsFound <= 0) { log.info("Could not find any repositories with given image: {}", img); return Optional.empty(); } return Optional.of(contentsWithImage); } DockerfileGitHubUtil(GitHubUtil gitHubUtil); GHRepository getOrCreateFork(GHRepository parent); GHMyself getMyself(); GHRepository getRepo(String repoName); PagedSearchIterable<GHContent> findFilesWithImage(String query, String org); List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo,
                                                            GHMyself currentUser); void modifyAllOnGithub(GHRepository repo, String branch,
                                  String img, String tag); GHContent tryRetrievingContent(GHRepository repo, String path, String branch); void modifyOnGithub(GHContent content,
                               String branch, String img, String tag, String customMessage); GitHubJsonStore getGitHubJsonStore(String store); void createPullReq(GHRepository origRepo,
                              String branch, GHRepository forkRepo,
                              PullRequestInfo pullRequestInfo); Optional<GHPullRequest> getPullRequestForImageBranch(GHRepository repository, GitForkBranch gitForkBranch); void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch); boolean thisUserIsOwner(GHRepository repo); Optional<PagedSearchIterable<GHContent>> getGHContents(String org, String img);  }
@Test public void testGetGHContents() throws Exception { DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); GHContent content1 = mock(GHContent.class); GHContent content2 = mock(GHContent.class); GHContent content3 = mock(GHContent.class); PagedSearchIterable<GHContent> contentsWithImage = mock(PagedSearchIterable.class); when(contentsWithImage.getTotalCount()).thenReturn(3); PagedIterator<GHContent> contentsWithImageIterator = mock(PagedIterator.class); when(contentsWithImageIterator.hasNext()).thenReturn(true, true, true, false); when(contentsWithImageIterator.next()).thenReturn(content1, content2, content3, null); when(contentsWithImage.iterator()).thenReturn(contentsWithImageIterator); when(dockerfileGitHubUtil.findFilesWithImage(anyString(), eq("org"))).thenReturn(contentsWithImage); when(dockerfileGitHubUtil.getGHContents("org", "image")).thenCallRealMethod(); assertEquals(dockerfileGitHubUtil.getGHContents("org", "image"), Optional.of(contentsWithImage)); }