DockerfileGitHubUtil { public Optional<GHPullRequest> getPullRequestForImageBranch(GHRepository repository, GitForkBranch gitForkBranch) { PagedIterable<GHPullRequest> pullRequests = repository.queryPullRequests().state(GHIssueState.OPEN).head(gitForkBranch.getBranchName()).list(); for (GHPullRequest pullRequest : pullRequests) { return Optional.of(pullRequest); } return Optional.empty(); } 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 testReturnPullRequestForBranch() { String imageName = "someimage"; GHPullRequest ghPullRequest = mock(GHPullRequest.class); GHPullRequestQueryBuilder queryBuilder = getGHPullRequestQueryBuilder(imageName, Optional.of(ghPullRequest)); GHRepository parent = mock(GHRepository.class); when(parent.queryPullRequests()).thenReturn(queryBuilder); GitForkBranch gitForkBranch = new GitForkBranch(imageName, "", null); gitHubUtil = mock(GitHubUtil.class); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); assertEquals(dockerfileGitHubUtil.getPullRequestForImageBranch(parent, gitForkBranch), Optional.of(ghPullRequest)); }
@Test public void testNoPullRequestForBranch() { String imageName = "someimage"; GHPullRequest ghPullRequest = mock(GHPullRequest.class); GHPullRequestQueryBuilder queryBuilder = getGHPullRequestQueryBuilder(imageName, Optional.empty()); GHRepository parent = mock(GHRepository.class); when(parent.queryPullRequests()).thenReturn(queryBuilder); GitForkBranch gitForkBranch = new GitForkBranch(imageName, "", null); gitHubUtil = mock(GitHubUtil.class); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); assertEquals(dockerfileGitHubUtil.getPullRequestForImageBranch(parent, gitForkBranch), Optional.empty()); }