SessionSettingsLocator { public static SessionSettings loadSettings(String... locations) { try { for (String location : locations) { Optional<Resource> resource = load(location); if (resource.isPresent()) { log.info("Loading settings from '{}'", location); return new SessionSettings(resource.get().getInputStream()); } } throw new SettingsNotFoundException("Settings file not found"); } catch (RuntimeException | ConfigError | IOException e) { throw new SettingsNotFoundException(e.getMessage(), e); } } private  SessionSettingsLocator(); static SessionSettings loadSettings(String... locations);  }
@Test public void shouldLoadDefaultFromSystemProperty() throws URISyntaxException { SessionSettings settings = loadSettings("classpath:quickfixj.cfg", null, null, null); assertThat(settings).isNotNull(); URL resource = SessionSettingsLocatorTest.class.getResource("/quickfixj.cfg"); File file = Paths.get(resource.toURI()).toFile(); settings = loadSettings(null, null, "file: assertThat(settings).isNotNull(); settings = loadSettings(null, null, null, "classpath:quickfixj.cfg"); assertThat(settings).isNotNull(); }
@Test public void shouldThrowSettingsNotFoundExceptionIfNoneFound() { thrown.expect(SettingsNotFoundException.class); loadSettings(null, null, null, null); }