Child implements ExecutableWithNamespace { @Override public void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil) throws IOException, InterruptedException { String branch = ns.get(Constants.GIT_BRANCH); String img = ns.get(Constants.IMG); String forceTag = ns.get(Constants.FORCE_TAG); dockerfileGitHubUtil.getGitHubJsonStore(ns.get(Constants.STORE)).updateStore(img, forceTag); log.info("Retrieving repository and creating fork..."); GHRepository repo = dockerfileGitHubUtil.getRepo(ns.get(Constants.GIT_REPO)); GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(repo); if (fork == null) { log.info("Unable to fork {}. Please make sure that the repo is forkable.", repo.getFullName()); return; } GitForkBranch gitForkBranch = new GitForkBranch(img, forceTag, branch); PullRequestInfo pullRequestInfo = new PullRequestInfo(ns.get(Constants.GIT_PR_TITLE), gitForkBranch.getImageName(), gitForkBranch.getImageTag()); dockerfileGitHubUtil.createOrUpdateForkBranchToParentDefault(repo, fork, gitForkBranch); log.info("Modifying on Github..."); dockerfileGitHubUtil.modifyAllOnGithub(fork, gitForkBranch.getBranchName(), img, forceTag); dockerfileGitHubUtil.createPullReq(repo, gitForkBranch.getBranchName(), fork, pullRequestInfo); }  @Override void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil);  }
@Test(dataProvider = "inputMap") public void checkPullRequestMade(Map<String, Object> inputMap) throws Exception { Child child = new Child(); Namespace ns = new Namespace(inputMap); DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); Mockito.when(dockerfileGitHubUtil.getRepo(Mockito.any())).thenReturn(new GHRepository()); Mockito.when(dockerfileGitHubUtil.getOrCreateFork(Mockito.any())).thenReturn(new GHRepository()); doNothing().when(dockerfileGitHubUtil).modifyAllOnGithub(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); GitHubJsonStore gitHubJsonStore = mock(GitHubJsonStore.class); when(dockerfileGitHubUtil.getGitHubJsonStore(anyString())).thenReturn(gitHubJsonStore); doNothing().when(dockerfileGitHubUtil).createPullReq(Mockito.any(), anyString(), Mockito.any(), any()); child.execute(ns, dockerfileGitHubUtil); Mockito.verify(dockerfileGitHubUtil, atLeastOnce()) .createPullReq(Mockito.any(), anyString(), Mockito.any(), any()); }
@Test public void testCreateForkFailureCase_CreatePullReqIsSkipped() throws IOException, InterruptedException { Child child = new Child(); Map<String, Object> nsMap = ImmutableMap.of( GIT_REPO, "test", IMG, "test", FORCE_TAG, "test", STORE, "test"); Namespace ns = new Namespace(nsMap); DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); GitHubJsonStore gitHubJsonStore = mock(GitHubJsonStore.class); when(dockerfileGitHubUtil.getGitHubJsonStore(anyString())).thenReturn(gitHubJsonStore); Mockito.when(dockerfileGitHubUtil.getRepo(Mockito.any())).thenReturn(new GHRepository()); Mockito.when(dockerfileGitHubUtil.getOrCreateFork(Mockito.any())).thenReturn(null); child.execute(ns, dockerfileGitHubUtil); Mockito.verify(dockerfileGitHubUtil, Mockito.never()).createPullReq(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); }