@Test public void createOnlyTwoRepositories() throws Exception { verify(repositoryService, times(2)).createRepository(any(OrganizationalUnit.class), eq(GitRepository.SCHEME.toString()), anyString(), configsCaptor.capture()); final List<RepositoryEnvironmentConfigurations> allValues = configsCaptor.getAllValues(); final Set<String> observedSubdirectories = new HashSet<>(); allValues.forEach(configs -> { assertEquals(NIOGIT_PATH, assertInstanceOf(configs.getOrigin(), String.class)); assertFalse(assertInstanceOf(configs.getInit(), Boolean.class)); assertFalse(assertInstanceOf(configs.getMirror(), Boolean.class)); final String subdirectory = assertInstanceOf(configs.getSubdirectory(), String.class); observedSubdirectories.add(subdirectory); @SuppressWarnings("unchecked") final List<String> branches = assertInstanceOf(configs.getBranches(), List.class); final List<String> expectedBranches; if (subdirectory.equals("legacyProject1")) { expectedBranches = Arrays.asList("legacyMasterBranch", "legacyDevBranch"); } else if (subdirectory.equals("legacyProject2")) { expectedBranches = Arrays.asList("legacyDevBranch"); } else { throw new AssertionError("Unrecognized subdirectory: " + subdirectory); } verify(service,times(2)).cleanupOrigin(any()); assertEquals("Unexpected branches for subdirectory " + subdirectory, new HashSet<>(expectedBranches), new HashSet<>(branches)); }); assertEquals(new HashSet<>(Arrays.asList("legacyProject1", "legacyProject2")), observedSubdirectories); }
@Test public void createOnlyTwoRepositories() throws Exception { verify(repositoryService, times(2)).createRepository(any(OrganizationalUnit.class), eq(GitRepository.SCHEME.toString()), anyString(), configsCaptor.capture()); final List<RepositoryEnvironmentConfigurations> allValues = configsCaptor.getAllValues(); final Set<String> observedSubdirectories = new HashSet<>(); allValues.forEach(configs -> { assertEquals(NIOGIT_PATH, assertInstanceOf(configs.getOrigin(), String.class)); assertFalse(assertInstanceOf(configs.getInit(), Boolean.class)); assertFalse(assertInstanceOf(configs.getMirror(), Boolean.class)); final String subdirectory = assertInstanceOf(configs.getSubdirectory(), String.class); observedSubdirectories.add(subdirectory); @SuppressWarnings("unchecked") final List<String> branches = assertInstanceOf(configs.getBranches(), List.class); final List<String> expectedBranches; if (subdirectory.equals("legacyProject1")) { expectedBranches = Arrays.asList("legacyMasterBranch", "legacyDevBranch"); } else if (subdirectory.equals("legacyProject2")) { expectedBranches = Arrays.asList("legacyDevBranch"); } else { throw new AssertionError("Unrecognized subdirectory: " + subdirectory); } verify(service,times(2)).cleanupOrigin(any()); assertEquals("Unexpected branches for subdirectory " + subdirectory, new HashSet<>(expectedBranches), new HashSet<>(branches)); }); assertEquals(new HashSet<>(Arrays.asList("legacyProject1", "legacyProject2")), observedSubdirectories); }