Events { static List<String> ensureListOfStrings(final List<?> list) { return list.stream().map(String.class::cast).collect(toList()); }    }
@Test public void properListOfStringIsReturned_whenListOfObjectsIsProvided() { final List<?> list = newArrayList("a", "b", "c"); assertThat(Events.ensureListOfStrings(list)).containsExactly("a", "b", "c"); }
@Test public void classCastExceptionIsThrown_whenListOfObjectsContainsSomethingDifferentThanString() { final List<?> list = newArrayList("a", new Object(), "c"); assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> Events.ensureListOfStrings(list)); }