@Test void writeProperties_preserve_order() throws IOException, URISyntaxException { setupCurrentFile(TEST_PROPERTIES, PROPERTIES); final Properties properties = new Properties(); properties.putAll(ImmutableMap.of("key1", "value1", "key2", "value2")); WriterHelper.writePropertiesFile(testProjectDir, documentFileUtils, properties, TEST_PROPERTIES); final File propertiesFile = checkFileBasics(WriterHelperTest.TEST_PROPERTIES, PROPERTIES); final List<String> lines = readLines(propertiesFile, StandardCharsets.ISO_8859_1); assertEquals(4, lines.size()); assertTrue(lines.get(0).startsWith("key1")); assertTrue(lines.get(1).startsWith("key3")); assertTrue(lines.get(2).startsWith("key4")); assertTrue(lines.get(3).startsWith("key2")); }
private static <B extends GatewayEntity> void writePropertiesFile(File rootFolder, DocumentFileUtils documentFileUtils, Map<String, B> beans, String fileName) { File configFolder = new File(rootFolder, CONFIG_DIRECTORY); documentFileUtils.createFolder(configFolder.toPath()); Properties properties = new Properties(); properties.putAll(beans .values() .stream() .map(b -> { b.preWrite(configFolder, documentFileUtils); return (PropertiesEntity) b; }) .collect(toMap(PropertiesEntity::getKey, PropertiesEntity::getValue))); writePropertiesFile(rootFolder, documentFileUtils, properties, fileName); }
WriterHelper { private static <B extends GatewayEntity> void writePropertiesFile(File rootFolder, DocumentFileUtils documentFileUtils, Map<String, B> beans, String fileName) { File configFolder = new File(rootFolder, CONFIG_DIRECTORY); documentFileUtils.createFolder(configFolder.toPath()); Properties properties = new Properties(); properties.putAll(beans .values() .stream() .map(b -> { b.preWrite(configFolder, documentFileUtils); return (PropertiesEntity) b; }) .collect(toMap(PropertiesEntity::getKey, PropertiesEntity::getValue))); writePropertiesFile(rootFolder, documentFileUtils, properties, fileName); } }
WriterHelper { private static <B extends GatewayEntity> void writePropertiesFile(File rootFolder, DocumentFileUtils documentFileUtils, Map<String, B> beans, String fileName) { File configFolder = new File(rootFolder, CONFIG_DIRECTORY); documentFileUtils.createFolder(configFolder.toPath()); Properties properties = new Properties(); properties.putAll(beans .values() .stream() .map(b -> { b.preWrite(configFolder, documentFileUtils); return (PropertiesEntity) b; }) .collect(toMap(PropertiesEntity::getKey, PropertiesEntity::getValue))); writePropertiesFile(rootFolder, documentFileUtils, properties, fileName); } private  WriterHelper(); }
WriterHelper { private static <B extends GatewayEntity> void writePropertiesFile(File rootFolder, DocumentFileUtils documentFileUtils, Map<String, B> beans, String fileName) { File configFolder = new File(rootFolder, CONFIG_DIRECTORY); documentFileUtils.createFolder(configFolder.toPath()); Properties properties = new Properties(); properties.putAll(beans .values() .stream() .map(b -> { b.preWrite(configFolder, documentFileUtils); return (PropertiesEntity) b; }) .collect(toMap(PropertiesEntity::getKey, PropertiesEntity::getValue))); writePropertiesFile(rootFolder, documentFileUtils, properties, fileName); } private  WriterHelper();  }
WriterHelper { private static <B extends GatewayEntity> void writePropertiesFile(File rootFolder, DocumentFileUtils documentFileUtils, Map<String, B> beans, String fileName) { File configFolder = new File(rootFolder, CONFIG_DIRECTORY); documentFileUtils.createFolder(configFolder.toPath()); Properties properties = new Properties(); properties.putAll(beans .values() .stream() .map(b -> { b.preWrite(configFolder, documentFileUtils); return (PropertiesEntity) b; }) .collect(toMap(PropertiesEntity::getKey, PropertiesEntity::getValue))); writePropertiesFile(rootFolder, documentFileUtils, properties, fileName); } private  WriterHelper();   }