FileBasedDependencyLoader implements DependencyLoader { @Override public List<Dependency> load(Properties properties, 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 PropertyFileDependencyLoader()) .load(settingsFile, properties, logger); } return Collections.emptyList(); } FileBasedDependencyLoader(); @Override List<Dependency> load(Properties properties, 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<Dependency> dependencyList = loader.load(properties, logger); TestHelper.verifyDependencies(dependencyList); System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.settings.yaml"); dependencyList = loader.load(properties, logger); TestHelper.verifyDependencies(dependencyList); System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "classpath:yaks.settings.json"); dependencyList = loader.load(properties, logger); TestHelper.verifyDependencies(dependencyList); }
@Test public void shouldHandleNonExistingFile() throws LifecycleExecutionException { System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "doesNotExist"); List<Dependency> dependencyList = loader.load(properties, logger); Assertions.assertThat(dependencyList).isEmpty(); }