### Question:
NestedMaps { public static Map<String, Object> unflatten(Map<String, Object> flattened) { Map<String, Object> unflattened = new HashMap<>(); for (Map.Entry<String, Object> entry : flattened.entrySet()) { doUnflatten(unflattened, entry.getKey(), entry.getValue()); } return unflattened; } private  NestedMaps(); @SuppressWarnings("unchecked") static Optional<T> getValue(Map<String, Object> data, String path); static Map<String, T> deepMerge(final Stream<Map<String, T>> mapStream); @SuppressWarnings({ "rawtypes", "unchecked" }) static void deepMerge(Map left, Map right); static Map<String, Object> unflatten(Map<String, Object> flattened);  }### Answer:
@Test void testUnflatten() { final HashMap<String, Object> data = new HashMap<>(); data.put("foo.baz", "baz"); data.put("foo.foo", "bar"); data.put("foo.bar", "foo"); data.put("baz", "bar"); data.put("bar.foo.bar.foo", "bar"); data.put("bar.foo.bar.baz", "foo"); data.put("hello", "world"); data.put("list", Arrays.asList("foo", "bar", "baz")); final Map<String, Object> target = NestedMaps.unflatten(data); checkTargetMap(target); }
@Test void testUnflattenConflict() { final Map<String, Object> data = new LinkedHashMap<>(); data.put("foo.baz", "baz"); data.put("foo", "bar"); assertThatIllegalStateException() .isThrownBy(() -> NestedMaps.unflatten(data)) .withMessage("Conflicting data types for key 'foo'"); }
@Test void testUnflattenConflict2() { final Map<String, Object> data = new LinkedHashMap<>(); data.put("foo", "bar"); data.put("foo.baz", "baz"); assertThatIllegalStateException() .isThrownBy(() -> NestedMaps.unflatten(data)) .withMessage("Conflicting data types for key 'foo.baz'"); }