|
25 | 25 | import java.util.Map;
|
26 | 26 | import java.util.Set;
|
27 | 27 |
|
28 |
| -import static org.mockito.Matchers.any; |
29 |
| -import static org.mockito.Matchers.anyString; |
30 |
| -import static org.mockito.Matchers.eq; |
| 28 | +import static org.mockito.Matchers.*; |
31 | 29 | import static org.mockito.Mockito.*;
|
| 30 | +import static org.testng.Assert.assertEquals; |
32 | 31 | import static org.testng.Assert.assertNotNull;
|
33 | 32 |
|
34 | 33 | /**
|
@@ -61,7 +60,53 @@ public void testForkRepositoriesFound() throws Exception {
|
61 | 60 | all.loadDockerfileGithubUtil(dockerfileGitHubUtil);
|
62 | 61 | all.forkRepositoriesFound(ArrayListMultimap.create(), ArrayListMultimap.create(), contentsWithImage, "image");
|
63 | 62 |
|
64 |
| - Mockito.verify(dockerfileGitHubUtil, times(1)).closeOutdatedPullRequestAndFork(any()); |
| 63 | + Mockito.verify(dockerfileGitHubUtil, times(3)).closeOutdatedPullRequestAndFork(any()); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testForkRepositoriesFound_unableToforkRepo() throws Exception { |
| 68 | + DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); |
| 69 | + |
| 70 | + GHRepository contentRepo1 = mock(GHRepository.class); |
| 71 | + when(contentRepo1.getFullName()).thenReturn("1"); |
| 72 | + |
| 73 | + GHRepository contentRepo2 = mock(GHRepository.class); |
| 74 | + when(contentRepo2.getFullName()).thenReturn("1"); |
| 75 | + |
| 76 | + GHRepository contentRepo3 = mock(GHRepository.class); |
| 77 | + when(contentRepo3.getFullName()).thenReturn("2"); |
| 78 | + |
| 79 | + GHContent content1 = mock(GHContent.class); |
| 80 | + when(content1.getOwner()).thenReturn(contentRepo1); |
| 81 | + when(content1.getPath()).thenReturn("1"); |
| 82 | + |
| 83 | + GHContent content2 = mock(GHContent.class); |
| 84 | + when(content2.getOwner()).thenReturn(contentRepo2); |
| 85 | + when(content2.getPath()).thenReturn("2"); |
| 86 | + |
| 87 | + GHContent content3 = mock(GHContent.class); |
| 88 | + when(content3.getOwner()).thenReturn(contentRepo3); |
| 89 | + when(content3.getPath()).thenReturn("3"); |
| 90 | + |
| 91 | + PagedSearchIterable<GHContent> contentsWithImage = mock(PagedSearchIterable.class); |
| 92 | + |
| 93 | + PagedIterator<GHContent> contentsWithImageIterator = mock(PagedIterator.class); |
| 94 | + when(contentsWithImageIterator.hasNext()).thenReturn(true, true, true, false); |
| 95 | + when(contentsWithImageIterator.next()).thenReturn(content1, content2, content3, null); |
| 96 | + when(contentsWithImage.iterator()).thenReturn(contentsWithImageIterator); |
| 97 | + when(dockerfileGitHubUtil.closeOutdatedPullRequestAndFork(contentRepo1)).thenReturn(null); |
| 98 | + when(dockerfileGitHubUtil.closeOutdatedPullRequestAndFork(contentRepo2)).thenReturn(null); |
| 99 | + when(dockerfileGitHubUtil.closeOutdatedPullRequestAndFork(contentRepo3)).thenReturn(new GHRepository()); |
| 100 | + |
| 101 | + All all = new All(); |
| 102 | + all.loadDockerfileGithubUtil(dockerfileGitHubUtil); |
| 103 | + Multimap<String, String> pathToDockerfilesInParentRepo = ArrayListMultimap.create(); |
| 104 | + Multimap<String, String> imagesFoundInParentRepo = ArrayListMultimap.create(); |
| 105 | + all.forkRepositoriesFound(pathToDockerfilesInParentRepo, imagesFoundInParentRepo, contentsWithImage, "image"); |
| 106 | + |
| 107 | + assertEquals(pathToDockerfilesInParentRepo.size(), 1); |
| 108 | + assertEquals(imagesFoundInParentRepo.size(), 1); |
| 109 | + Mockito.verify(dockerfileGitHubUtil, times(3)).closeOutdatedPullRequestAndFork(any()); |
65 | 110 | }
|
66 | 111 |
|
67 | 112 | @Test
|
|
0 commit comments