### Question:
Preconditions { public static <T> Collection<T> doesNotContainNull(Collection<T> collection) { return doesNotContainNull(collection, "The collection must not contain null"); } private  Preconditions(); static T notNull(T object); static T notNull(T object, String message); static T notNull(T object, Supplier<String> messageSupplier); static Collection<T> doesNotContainNull(Collection<T> collection); static Collection<T> doesNotContainNull(Collection<T> collection, String message); static Collection<T> doesNotContainNull(Collection<T> collection, Supplier<String> messageSupplier); static void check(boolean expression); static void check(boolean expression, String message); static void check(boolean expression, Supplier<String> messageSupplier);  }### Answer:
@Test void doesNotContainNullThrowsIfCollectionContainsOneNullElement() { assertThrows(IllegalArgumentException.class, () -> Preconditions.doesNotContainNull(Collections.singletonList(null))); assertThrows(IllegalArgumentException.class, () -> Preconditions.doesNotContainNull(Collections.singleton(null))); assertThrows(IllegalArgumentException.class, () -> Preconditions.doesNotContainNull(Arrays.asList("test", null, "test"))); assertThrows(IllegalArgumentException.class, () -> Preconditions.doesNotContainNull(Arrays.asList(null, "test"))); assertThrows(IllegalArgumentException.class, () -> Preconditions.doesNotContainNull(Arrays.asList("test", null))); }
@Test void doesNotContainNullThrowsCorrectMessageIfContainsNull() { final Throwable throwable = assertThrows(IllegalArgumentException.class, () -> Preconditions.doesNotContainNull(Arrays.asList(null, "test"), "testMessage")); assertEquals("testMessage", throwable.getMessage()); }
@Test void doesNotContainNullThrowsCorrectSuppliedMessageIfContainsNull() { final Throwable throwable = assertThrows(IllegalArgumentException.class, () -> Preconditions.doesNotContainNull(Collections.singleton(null), () -> "testMessage")); assertEquals("testMessage", throwable.getMessage()); }