Environment { void reloadAccountabilityConfiguration(InputStream defaultConfigInputStream) { if (configFile != null) { File tempFile = new File(configFile.getParent(), "wineryAccountability.yml"); try { FileUtils.copyInputStreamToFile(defaultConfigInputStream, tempFile); } catch (IOException e) { LOGGER.debug("Error copying default file", e); } YAMLConfiguration defaultAccountabilityConfiguration; try (FileReader reader = new FileReader(tempFile)) { String accountabilityPrefix = "accountability"; defaultAccountabilityConfiguration = new YAMLConfiguration(); defaultAccountabilityConfiguration.read(reader); YAMLConfiguration currentConfiguration = this.getConfiguration(); Iterator<String> accountabilityAttributes = defaultAccountabilityConfiguration.getKeys(accountabilityPrefix); accountabilityAttributes.forEachRemaining(key -> currentConfiguration.setProperty(key, defaultAccountabilityConfiguration.getString(key))); this.save(); } catch (Exception e) { LOGGER.warn("Error while reading accountability configuration file", e); } FileUtils.deleteQuietly(tempFile); } } private  Environment(); File getConfigDirectory();  }
@Test public void testReloadAccountabilityConfiguration() { assertEquals("test.url", Environment.getInstance().getConfiguration().getString("accountability.geth-url")); Environment.getInstance().getConfiguration().setProperty("accountability.geth-url", "test2.url"); assertEquals("test2.url", Environment.getInstance().getConfiguration().getString("accountability.geth-url")); Environment.getInstance().save(); assertEquals("test2.url", Environment.getInstance().getConfiguration().getString("accountability.geth-url")); Environment.getInstance().reloadAccountabilityConfiguration(Environment.getTestConfigInputStream()); assertEquals("test.url", Environment.getInstance().getConfiguration().getString("accountability.geth-url")); }