DockerfileGitHubUtil { protected void findImagesAndFix(GHContent content, String branch, String img, String tag, String customMessage, BufferedReader reader) throws IOException { StringBuilder strB = new StringBuilder(); boolean modified = rewriteDockerfile(img, tag, reader, strB); if (modified) { content.update(strB.toString(), "Fix Dockerfile base image in /" + content.getPath() + "\n\n" + customMessage, branch); } } 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(dataProvider = "inputBranchesImagesAndTags") public void testFindImagesAndFix(String branch, String currentImage, String searchImage, String currentTag, String newTag, int modified) throws Exception { gitHubUtil = mock(GitHubUtil.class); BufferedReader reader = mock(BufferedReader.class); GHContent content = mock(GHContent.class); when(content.getPath()).thenReturn("path"); when(content.update(anyString(), anyString(), eq(branch))).thenReturn(null); when(reader.readLine()).thenReturn("FROM " + currentImage + ":" + currentTag, "", null); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); dockerfileGitHubUtil.findImagesAndFix(content, branch, searchImage, newTag, "", reader); verify(content, times(modified)).update(anyString(), anyString(), eq(branch)); }
@Test(dataProvider = "inputBranchesImagesAndTags") public void testFindImagesAndFix_KeepLinesIntact(String branch, String currentImage, String searchImage, String currentTag, String newTag, int modified) throws Exception { gitHubUtil = mock(GitHubUtil.class); BufferedReader reader = mock(BufferedReader.class); GHContent content = mock(GHContent.class); when(content.getPath()).thenReturn("path"); when(content.update(anyString(), anyString(), eq(branch))).thenReturn(null); when(reader.readLine()).thenReturn("blahblahblah", "FROM " + currentImage + ":" + currentTag, "blahblahblah", null); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); dockerfileGitHubUtil.findImagesAndFix(content, branch, searchImage, newTag, "", reader); verify(content, times(modified)).update(anyString(), anyString(), eq(branch)); }