Configuration { public static Map<String, Object> mergeMap(final Map<String, Object> previous, final Map<String, Object> next) { Objects.requireNonNull(next, "Parameter next must not be null!"); if (null == previous || previous.isEmpty()) { return next; } return Stream.concat(previous.keySet().stream(), next.keySet().stream()) .sorted() .distinct() .collect(Collectors.toMap(Function.identity(), key -> mergeValue(key, previous.get(key), next.get(key)))); } private  Configuration(); static Configuration getInstance(); Object getConfig(final String param); Object getConfig(final String param, final Object defaultValue); T getConfigTyped(final String param, final Class<T> paramClass); T getConfigTyped(final String param, final Class<T> paramClass, final T defaultValue); Optional<Object> getConfigOptional(final String param); Optional<T> getConfigTypedOptional(final String param, final Class<T> paramClass); @Override String toString(); static Map<String, Object> mergeMap(final Map<String, Object> previous, final Map<String, Object> next);  }
@Test public void checkMerge() throws Exception { try { Assert.assertThat( "Result of map merge failed!", Configuration.mergeMap(previousMap, newMap), CoreMatchers.equalTo(resultMap)); if (!successful) { throw new AssertionError("Merging did not fail when it should have"); } } catch (final RuntimeException re) { if (successful) { throw new AssertionError("Merging failed when it shouldn't have", re); } } }