Events { static Map<String, String> ensureOrderedMapOfStringsToStrings(final Map<?, ?> map) { final Map<String, String> result = new LinkedHashMap<>(); map.forEach((key, value) -> result.put((String) key, (String) value)); return result; }    }
@Test public void orderedMapFromStringsToStringsIsReturned_whenAnyMapIsProvided() { final Map<?, ?> map = ImmutableMap.of("x", "a", "y", "b"); final Map<String, String> result = Events.ensureOrderedMapOfStringsToStrings(map); assertThat(result).hasSize(2).isInstanceOf(LinkedHashMap.class); assertThat(result).containsKeys("x", "y").containsValues("a", "b"); }
@Test public void classCastExceptionIsThrown_whenMapHasKeyOtherThenStrings() { final Map<?, ?> map = ImmutableMap.of("x", "a", new Object(), "b"); assertThatExceptionOfType(ClassCastException.class) .isThrownBy(() -> Events.ensureOrderedMapOfStringsToStrings(map)); }
@Test public void classCastExceptionIsThrown_whenMapHasValueOtherThenStrings() { final Map<?, ?> map = ImmutableMap.of("x", "a", "y", new Object()); assertThatExceptionOfType(ClassCastException.class) .isThrownBy(() -> Events.ensureOrderedMapOfStringsToStrings(map)); }