@@ -47,71 +47,73 @@ public void testPullRequestsPrepareToCreateSuccessful() throws Exception {
4747 eq (rateLimiter ));
4848 }
4949
50- // @Test(expectedExceptions = IOException.class)
51- // public void testPullRequestsPrepareThrowsException() throws Exception {
52- // Map<String, Object> nsMap = ImmutableMap.of(Constants.IMG,
53- // "image", Constants.TAG,
54- // "tag", Constants.STORE,
55- // "store", Constants.SKIP_PR_CREATION,
56- // false, Constants.CHECK_FOR_RENOVATE, false);
57- // Namespace ns = new Namespace(nsMap);
58- // PullRequests pullRequests = new PullRequests();
59- // GitHubPullRequestSender pullRequestSender = mock(GitHubPullRequestSender.class);
60- // PagedSearchIterable<GHContent> contentsFoundWithImage = mock(PagedSearchIterable.class);
61- // GitForkBranch gitForkBranch = mock(GitForkBranch.class);
62- // RateLimiter rateLimiter = Mockito.spy(new RateLimiter());
63- // DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class);
64- // Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = ArrayListMultimap.create();
65- // GitHubContentToProcess gitHubContentToProcess = mock(GitHubContentToProcess.class);
66- // pathToDockerfilesInParentRepo.put("repo1", gitHubContentToProcess);
67- // GHRepository ghRepository = mock(GHRepository.class);
68- //
69- // when(pullRequestSender.forkRepositoriesFoundAndGetPathToDockerfiles(contentsFoundWithImage, gitForkBranch)).thenReturn(pathToDockerfilesInParentRepo);
70- // ArgumentCaptor<String> valueCapture = ArgumentCaptor.forClass(String.class);
71- // when(gitHubContentToProcess.getParent()).thenReturn(ghRepository);
72- // when(ghRepository.getFullName()).thenReturn("repo");
73- // doThrow(new IOException("Exception")).when(dockerfileGitHubUtil).changeDockerfiles(
74- // eq(ns),
75- // eq(pathToDockerfilesInParentRepo),
76- // eq(gitHubContentToProcess),
77- // anyList(),
78- // eq(gitForkBranch),
79- // eq(rateLimiter));
80- //
81- // pullRequests.prepareToCreate(ns, pullRequestSender, contentsFoundWithImage,
82- // gitForkBranch, dockerfileGitHubUtil, rateLimiter);
83- //
84- // assertThrows(IOException.class, () -> pullRequests.prepareToCreate(ns, pullRequestSender, contentsFoundWithImage,
85- // gitForkBranch, dockerfileGitHubUtil, rateLimiter));
86- // }
50+ @ Test (expectedExceptions = IOException .class )
51+ public void testPullRequestsPrepareThrowsException () throws Exception {
52+ Map <String , Object > nsMap = ImmutableMap .of (Constants .IMG ,
53+ "image" , Constants .TAG ,
54+ "tag" , Constants .STORE ,
55+ "store" , Constants .SKIP_PR_CREATION ,
56+ false , Constants .CHECK_FOR_RENOVATE , false );
57+ Namespace ns = new Namespace (nsMap );
58+ PullRequests pullRequests = new PullRequests ();
59+ GitHubPullRequestSender pullRequestSender = mock (GitHubPullRequestSender .class );
60+ PagedSearchIterable <GHContent > contentsFoundWithImage = mock (PagedSearchIterable .class );
61+ GitForkBranch gitForkBranch = mock (GitForkBranch .class );
62+ RateLimiter rateLimiter = Mockito .spy (new RateLimiter ());
63+ DockerfileGitHubUtil dockerfileGitHubUtil = mock (DockerfileGitHubUtil .class );
64+ GithubAppCheck githubAppCheck = mock (GithubAppCheck .class );
65+ Multimap <String , GitHubContentToProcess > pathToDockerfilesInParentRepo = ArrayListMultimap .create ();
66+ GitHubContentToProcess gitHubContentToProcess = mock (GitHubContentToProcess .class );
67+ pathToDockerfilesInParentRepo .put ("repo1" , gitHubContentToProcess );
68+ GHRepository ghRepository = mock (GHRepository .class );
8769
88- // @Test
89- // public void testPullRequestsPrepareToCreateWhenNoDockerfileFound() throws Exception {
90- // Map<String, Object> nsMap = ImmutableMap.of(Constants.IMG,
91- // "image", Constants.TAG,
92- // "tag", Constants.STORE,
93- // "store", Constants.SKIP_PR_CREATION,
94- // false, Constants.CHECK_FOR_RENOVATE, false);
95- // Namespace ns = new Namespace(nsMap);
96- // PullRequests pullRequests = new PullRequests();
97- // GitHubPullRequestSender pullRequestSender = mock(GitHubPullRequestSender.class);
98- // PagedSearchIterable<GHContent> contentsFoundWithImage = mock(PagedSearchIterable.class);
99- // GitForkBranch gitForkBranch = mock(GitForkBranch.class);
100- // RateLimiter rateLimiter = Mockito.spy(new RateLimiter());
101- // DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class);
102- // Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = mock(Multimap.class);
103- // GitHubContentToProcess gitHubContentToProcess = mock(GitHubContentToProcess.class);
104- // when(pullRequestSender.forkRepositoriesFoundAndGetPathToDockerfiles(contentsFoundWithImage, gitForkBranch)).thenReturn(pathToDockerfilesInParentRepo);
105- // Set<String> currUsers = new HashSet<>();
106- // currUsers.add("repo1");
107- // when(pathToDockerfilesInParentRepo.keySet()).thenReturn(currUsers);
108- // pullRequests.prepareToCreate(ns, pullRequestSender, contentsFoundWithImage,
109- // gitForkBranch, dockerfileGitHubUtil, rateLimiter);
110- //
111- // verify(dockerfileGitHubUtil, times(0)).changeDockerfiles(eq(ns),
112- // eq(pathToDockerfilesInParentRepo),
113- // eq(gitHubContentToProcess), anyList(), eq(gitForkBranch),eq(rateLimiter));
114- // }
70+ when (pullRequestSender .forkRepositoriesFoundAndGetPathToDockerfiles (contentsFoundWithImage , gitForkBranch )).thenReturn (pathToDockerfilesInParentRepo );
71+ ArgumentCaptor <String > valueCapture = ArgumentCaptor .forClass (String .class );
72+ when (gitHubContentToProcess .getParent ()).thenReturn (ghRepository );
73+ when (ghRepository .getFullName ()).thenReturn ("repo" );
74+ doThrow (new IOException ("Exception" )).when (dockerfileGitHubUtil ).changeDockerfiles (
75+ eq (ns ),
76+ eq (pathToDockerfilesInParentRepo ),
77+ eq (gitHubContentToProcess ),
78+ anyList (),
79+ eq (gitForkBranch ),
80+ eq (rateLimiter ));
81+
82+ pullRequests .prepareToCreate (ns , pullRequestSender , contentsFoundWithImage ,
83+ gitForkBranch , dockerfileGitHubUtil , rateLimiter );
84+
85+ assertThrows (IOException .class , () -> pullRequests .prepareToCreate (ns , pullRequestSender , contentsFoundWithImage ,
86+ gitForkBranch , dockerfileGitHubUtil , rateLimiter ));
87+ }
88+
89+ @ Test
90+ public void testPullRequestsPrepareToCreateWhenNoDockerfileFound () throws Exception {
91+ Map <String , Object > nsMap = ImmutableMap .of (Constants .IMG ,
92+ "image" , Constants .TAG ,
93+ "tag" , Constants .STORE ,
94+ "store" , Constants .SKIP_PR_CREATION ,
95+ false , Constants .CHECK_FOR_RENOVATE , false );
96+ Namespace ns = new Namespace (nsMap );
97+ PullRequests pullRequests = new PullRequests ();
98+ GitHubPullRequestSender pullRequestSender = mock (GitHubPullRequestSender .class );
99+ PagedSearchIterable <GHContent > contentsFoundWithImage = mock (PagedSearchIterable .class );
100+ GitForkBranch gitForkBranch = mock (GitForkBranch .class );
101+ GithubAppCheck githubAppCheck = mock (GithubAppCheck .class );
102+ RateLimiter rateLimiter = Mockito .spy (new RateLimiter ());
103+ DockerfileGitHubUtil dockerfileGitHubUtil = mock (DockerfileGitHubUtil .class );
104+ Multimap <String , GitHubContentToProcess > pathToDockerfilesInParentRepo = mock (Multimap .class );
105+ GitHubContentToProcess gitHubContentToProcess = mock (GitHubContentToProcess .class );
106+ when (pullRequestSender .forkRepositoriesFoundAndGetPathToDockerfiles (contentsFoundWithImage , gitForkBranch )).thenReturn (pathToDockerfilesInParentRepo );
107+ Set <String > currUsers = new HashSet <>();
108+ currUsers .add ("repo1" );
109+ when (pathToDockerfilesInParentRepo .keySet ()).thenReturn (currUsers );
110+ pullRequests .prepareToCreate (ns , pullRequestSender , contentsFoundWithImage ,
111+ gitForkBranch , dockerfileGitHubUtil , rateLimiter );
112+
113+ verify (dockerfileGitHubUtil , times (0 )).changeDockerfiles (eq (ns ),
114+ eq (pathToDockerfilesInParentRepo ),
115+ eq (gitHubContentToProcess ), anyList (), eq (gitForkBranch ),eq (rateLimiter ));
116+ }
115117
116118// @Test
117119// public void testPullRequestsPrepareSkipsSendingPRIfRepoOnboardedToRenovate() throws Exception {
0 commit comments