public static Properties parse(final Stream<String> properties) { return properties.filter(wellDefinedProperties()) .map(splitPropertyInKeyValuePair()) .filter(propertiesWithBothKeyAndValue()) .reduce(new Properties(), propertiesAccumulator(), propertiesCombiner()); }
@Test public void test_propertiesAccumulator_whenAccumulatorIsNotEmpty() throws Exception { final Properties initialAccumulator = new Properties(); initialAccumulator.setProperty("key1", "value1"); final Properties accumulator = PropertiesUtil.propertiesAccumulator().apply(initialAccumulator, new String[]{"key2", "value2"}); assertThat(accumulator.getProperty("key1"), is("value1")); assertThat(accumulator.getProperty("key2"), is("value2")); }
@Test public void test_propertiesAccumulator_whenAccumulatorIsEmpty() throws Exception { final Properties accumulator = PropertiesUtil.propertiesAccumulator().apply(new Properties(), new String[]{"key", "value"}); assertThat(accumulator.getProperty("key"), is("value")); }
@Test public void test_propertiesAccumulator_whenAccumulatorIsNotEmptyAndKeyIsOverwritten() throws Exception { final Properties initialAccumulator = new Properties(); initialAccumulator.setProperty("key", "value1"); final Properties accumulator = PropertiesUtil.propertiesAccumulator().apply(initialAccumulator, new String[]{"key", "value2"}); assertThat(accumulator.getProperty("key"), is("value2")); }