DockerfileGitHubUtil { protected void modifyOnGithubRecursive(GHRepository repo, GHContent content, String branch, String img, String tag) throws IOException { if (content.isFile() && content.getDownloadUrl() != null) { modifyOnGithub(content, branch, img, tag, ""); } else if(content.isDirectory()) { for (GHContent newContent : repo.getDirectoryContent(content.getPath(), branch)) { modifyOnGithubRecursive(repo, newContent, branch, img, tag); } } else { log.info("Skipping submodule {}", content.getName()); } } 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(dependsOnMethods = "testFindImagesAndFix") public void testModifyOnGithubRecursive() throws Exception { gitHubUtil = mock(GitHubUtil.class); GHRepository repo = mock(GHRepository.class); List<GHContent> tree = mock(List.class); Iterator<GHContent> treeIterator = mock(Iterator.class); GHContent content = mock(GHContent.class); when(content.isFile()).thenReturn(false, true); when(content.getDownloadUrl()).thenReturn(null, " "); when(content.isDirectory()).thenReturn(true, false); when(content.getPath()).thenReturn("path"); when(content.read()).thenReturn(new InputStream() { @Override public int read() throws IOException { return -1; } }); when(treeIterator.hasNext()).thenReturn(true, true, true, true, true, false); when(treeIterator.next()).thenReturn(content); when(tree.iterator()).thenReturn(treeIterator); String branch = "branch"; String img = "img"; String tag = "tag"; when(repo.getDirectoryContent("path", branch)).thenReturn(tree); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); dockerfileGitHubUtil.modifyOnGithubRecursive(repo, content, branch, img, tag); verify(content, times(6)).isFile(); verify(content, times(2)).isDirectory(); verify(content, times(5)).getDownloadUrl(); }