@Test public void shouldHandleNonExistingFile() throws LifecycleExecutionException { System.setProperty(ExtensionSettings.SETTINGS_FILE_KEY, "doesNotExist"); List<Repository> repositoryList = loader.load(logger); Assertions.assertThat(repositoryList).isEmpty(); }
@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 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 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(); }
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); }
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);  }