Events { static List<Map<String, Object>> ensureListOfOrderedMapOfStringsToObjects(final List<?> list) { return list.stream().map(Map.class::cast).map(Events::ensureOrderedMapOfStringsToObjects).collect(toList()); }    }
@Test public void properListOfOrderedStringToObjectMapIsReturned_whenListOfObjectsIsProvided() { final List<?> list = newArrayList(ImmutableMap.<String, Object> of("x", 1, "y", 2), ImmutableMap.<String, Object> of("1", Boolean.TRUE, "2", "abc")); final List<Map<String, Object>> result = Events.ensureListOfOrderedMapOfStringsToObjects(list); assertThat(result).hasSize(2); assertThat(result.get(0)).isInstanceOf(LinkedHashMap.class); assertThat(result.get(0)).containsEntry("x", 1).containsEntry("y", 2); assertThat(result.get(1)).isInstanceOf(LinkedHashMap.class); assertThat(result.get(1)).containsEntry("1", Boolean.TRUE).containsEntry("2", "abc"); }
@Test public void classCastExceptionIsThrown_whenListContainsSomethingDifferentThanMap() { final List<?> list = newArrayList(ImmutableMap.of("x", 1, "y", 2), "foo"); assertThatExceptionOfType(ClassCastException.class) .isThrownBy(() -> Events.ensureListOfOrderedMapOfStringsToObjects(list)); }
@Test public void classCastExceptionIsThrown_whenListContainsMapWithNoStringKeys() { final List<?> list = newArrayList(ImmutableMap.of(1, 2, 2, 3)); assertThatExceptionOfType(ClassCastException.class) .isThrownBy(() -> Events.ensureListOfOrderedMapOfStringsToObjects(list)); }