@Test public void testChangeIfDockerfileBaseImageLine_modifyingStringBuilder() throws Exception { gitHubUtil = mock(GitHubUtil.class); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); StringBuilder stringBuilder = new StringBuilder(); String img = "image"; String tag = "7357"; dockerfileGitHubUtil.changeIfDockerfileBaseImageLine(img, tag, stringBuilder, "hello"); dockerfileGitHubUtil.changeIfDockerfileBaseImageLine(img, tag, stringBuilder, "FROM image:blah"); dockerfileGitHubUtil.changeIfDockerfileBaseImageLine(img, tag, stringBuilder, "world"); dockerfileGitHubUtil.changeIfDockerfileBaseImageLine(img, tag, stringBuilder, "this is a test"); assertEquals(stringBuilder.toString(), "hello\nFROM image:7357\nworld\nthis is a test\n"); }
protected boolean changeIfDockerfileBaseImageLine(String imageToFind, String tag, StringBuilder stringBuilder, String line) { boolean modified = false; String outputLine = line; if (FromInstruction.isFromInstruction(line)) { FromInstruction fromInstruction = new FromInstruction(line); if (fromInstruction.hasBaseImage(imageToFind) && fromInstruction.hasADifferentTag(tag)) { fromInstruction = fromInstruction.getFromInstructionWithNewTag(tag); modified = true; } outputLine = fromInstruction.toString(); } stringBuilder.append(outputLine).append("\n"); return modified; }
DockerfileGitHubUtil { protected boolean changeIfDockerfileBaseImageLine(String imageToFind, String tag, StringBuilder stringBuilder, String line) { boolean modified = false; String outputLine = line; if (FromInstruction.isFromInstruction(line)) { FromInstruction fromInstruction = new FromInstruction(line); if (fromInstruction.hasBaseImage(imageToFind) && fromInstruction.hasADifferentTag(tag)) { fromInstruction = fromInstruction.getFromInstructionWithNewTag(tag); modified = true; } outputLine = fromInstruction.toString(); } stringBuilder.append(outputLine).append("\n"); return modified; } }
DockerfileGitHubUtil { protected boolean changeIfDockerfileBaseImageLine(String imageToFind, String tag, StringBuilder stringBuilder, String line) { boolean modified = false; String outputLine = line; if (FromInstruction.isFromInstruction(line)) { FromInstruction fromInstruction = new FromInstruction(line); if (fromInstruction.hasBaseImage(imageToFind) && fromInstruction.hasADifferentTag(tag)) { fromInstruction = fromInstruction.getFromInstructionWithNewTag(tag); modified = true; } outputLine = fromInstruction.toString(); } stringBuilder.append(outputLine).append("\n"); return modified; } DockerfileGitHubUtil(GitHubUtil gitHubUtil); }
DockerfileGitHubUtil { protected boolean changeIfDockerfileBaseImageLine(String imageToFind, String tag, StringBuilder stringBuilder, String line) { boolean modified = false; String outputLine = line; if (FromInstruction.isFromInstruction(line)) { FromInstruction fromInstruction = new FromInstruction(line); if (fromInstruction.hasBaseImage(imageToFind) && fromInstruction.hasADifferentTag(tag)) { fromInstruction = fromInstruction.getFromInstructionWithNewTag(tag); modified = true; } outputLine = fromInstruction.toString(); } stringBuilder.append(outputLine).append("\n"); return modified; } 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); }
DockerfileGitHubUtil { protected boolean changeIfDockerfileBaseImageLine(String imageToFind, String tag, StringBuilder stringBuilder, String line) { boolean modified = false; String outputLine = line; if (FromInstruction.isFromInstruction(line)) { FromInstruction fromInstruction = new FromInstruction(line); if (fromInstruction.hasBaseImage(imageToFind) && fromInstruction.hasADifferentTag(tag)) { fromInstruction = fromInstruction.getFromInstructionWithNewTag(tag); modified = true; } outputLine = fromInstruction.toString(); } stringBuilder.append(outputLine).append("\n"); return modified; } 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);  }