MultiRepositoryManager { void initializeRepositoryListForMultiRepositoryAndReconfigureFactory(List<RepositoryProperties> repositoryList) { ObjectMapper objectMapper = new ObjectMapper(); File repositoryConfiguration = new File(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), Filename.FILENAME_JSON_REPOSITORIES); if (!repositoryConfiguration.exists()) { try { Files.createFile(repositoryConfiguration.toPath()); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.writeValue(repositoryConfiguration, repositoryList); } catch (IOException exception) { exception.printStackTrace(); } createMultiRepositoryFileStructure(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot()), Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), Constants.DEFAULT_LOCAL_REPO_NAME)); } try { RepositoryFactory.reconfigure(); } catch (Exception e) { LOGGER.debug("Error reconfiguring the RepositoryFactory.", e); } }  List<RepositoryProperties> getRepositoriesAsList(); void addRepositoryToFile(List<RepositoryProperties> repositories);  }
@Test public void testInitializeRepositoryList() throws IOException { ArrayList<RepositoryProperties> repositoryList = new ArrayList<>(); repositoryList.add(new RepositoryProperties("mainTestRepository", "https: MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager(); multiRepositoryManager.initializeRepositoryListForMultiRepositoryAndReconfigureFactory(repositoryList); assertTrue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), Filename.FILENAME_JSON_REPOSITORIES).toFile().exists()); ObjectMapper objectMapper = new ObjectMapper(); ObjectReader reader = objectMapper.readerFor(new TypeReference<List<RepositoryProperties>>() { }); repositoryList = reader.readValue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), Filename.FILENAME_JSON_REPOSITORIES).toFile()); assertEquals(1, repositoryList.size()); assertEquals("https: assertEquals("master", repositoryList.get(0).getBranch()); assertEquals("mainTestRepository", repositoryList.get(0).getName()); }
@Test public void testMultiRepositoryCreation() { ArrayList<RepositoryProperties> repositoryList = new ArrayList<>(); repositoryList.add(new RepositoryProperties("mainTestRepository", "https: MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager(); multiRepositoryManager.initializeRepositoryListForMultiRepositoryAndReconfigureFactory(repositoryList); assertTrue(RepositoryFactory.getRepository() instanceof MultiRepository); }