@Test
public void shouldEncryptAndSaveAllOccurrences() throws Exception {

    // given
    String propertyKey = "admin.password";
    String propertyValue = "5ecr3t";
    String propertyEncodedValue = "JP6lC6hVeu3wRZA1Tzigyg==";
    String mongoPropName = "mongodb.uri";
    String mongoPropValue = "mongodb://userName:5ecr3t@dataprep-server.org:27017/dataprep?toto=tata";
    String mongoPropValueEncrypted =
            "mongodb://userName:JP6lC6hVeu3wRZA1Tzigyg==@dataprep-server.org:27017/dataprep?toto=tata";
    Path tempFile = Files.createTempFile("dataprep-PropertiesEncryptionTest.", ".properties");
    try (BufferedWriter bufferedWriter = Files.newBufferedWriter(tempFile, Charsets.UTF_8)) {
        for (int i = 0; i < 5; i++) {
            bufferedWriter.write(propertyKey + "=" + propertyValue);
            bufferedWriter.newLine();
        }
        bufferedWriter.write(mongoPropName + "=" + mongoPropValue);
    }
    // when
    new PropertiesEncryption().encryptAndSave(tempFile.toString(), Sets.newHashSet(propertyKey, mongoPropName));
    // then
    Properties properties = new Properties();
    properties.load(new FileInputStream(tempFile.toFile()));
    assertEquals(propertyEncodedValue, properties.getProperty(propertyKey));
    assertEquals(mongoPropValueEncrypted, properties.getProperty(mongoPropName));
}