FileBasedRepositoryLoader implements RepositoryLoader { @Override public List<Repository> load(Logger logger) throws LifecycleExecutionException { Path settingsFile = getSettingsFile(); if (Files.exists(settingsFile)) { Optional<String> fileExtension = getFileNameExtension(settingsFile.getFileName().toString()); return fileExtension.flatMap(this::getFileConfigLoader) .orElse(new PropertyFileRepositoryLoader()) .load(settingsFile, logger); } return Collections.emptyList(); } FileBasedRepositoryLoader(); @Override List<Repository> load(Logger logger); static Path getSettingsFile(); static Optional<String> getFileNameExtension(String filename);  }
@Test public void shouldLoadFromPropertyFile() throws LifecycleExecutionException { System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.properties"); List<Repository> repositoryList = loader.load(logger); TestHelper.verifyRepositories(repositoryList); System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.settings.yaml"); repositoryList = loader.load(logger); TestHelper.verifyRepositories(repositoryList); System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.settings.json"); repositoryList = loader.load(logger); TestHelper.verifyRepositories(repositoryList); }
@Test public void shouldHandleNonExistingFile() throws LifecycleExecutionException { System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "doesNotExist"); List<Repository> repositoryList = loader.load(logger); Assertions.assertThat(repositoryList).isEmpty(); }