NullUtil { public static <T> T[] requireNonNullElements(T[] array) { requireNonNull(array, "The provided array " + IS_NULL + "."); int len = array.length; for (int i = 0; i < len; i++) { if (array[i] == null) { throw new NullPointerException("Item " + i + " in the array " + Arrays.toString(array) + " " + IS_NULL); } } return array; } private  NullUtil(); static T[] requireNonNullElements(T[] array); static T requireNonNullElements(T collection); static T[] requireNonNullElements(T[] array, String msg); static void requireNonNulls(Object o0); static void requireNonNulls(Object o0, Object o1); static void requireNonNulls(Object o0, Object o1, Object o2); static void requireNonNulls(Object o0, Object o1, Object o2, Object o3); static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4); static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5); static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5, Object o6); static void requireNonNulls(Object o0, Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7); @SafeVarargs // Iterating over an array is safe @SuppressWarnings("varargs") static Map<K, V> requireKeys(Map<K, V> map, K... requiredKeys); static Map<K, V> requireKeys(Map<K, V> map, K requiredKey); static Map<K, V> requireKeys(Map<K, V> map, K requiredKeyA, K requiredKeyB); static Map<K, V> requireKeys(Map<K, V> map, K requiredKeyA, K requiredKeyB, K requiredKeyC);  }
@Test void testRequireNonNullElements_array_null() { assertThrows(NullPointerException.class, () -> { NullUtil.requireNonNullElements((Object[]) null); }); }
@Test void testRequireNonNullElements_array_no_nulls() { assertDoesNotThrow(() -> NullUtil.requireNonNullElements(ARRAY_WITHOUT_NULL) ); }
@Test void testRequireNonNullElements_array_contains_null() { assertThrows(NullPointerException.class, () -> { NullUtil.requireNonNullElements(ARRAY_WITH_NULL); }); }
@Test void testRequireNonNullElements_array_contains_no_nulls() { assertArrayEquals(ARRAY_WITHOUT_NULL, NullUtil.requireNonNullElements(ARRAY_WITHOUT_NULL)); }
@Test void testRequireNonNullElements_collection_null() { assertThrows(NullPointerException.class, () -> { Collection<String> collection = null; NullUtil.requireNonNullElements(collection); }); }
@Test void testRequireNonNullElements_collection_whithout_null() { assertEquals(LIST_WITHOUT_NULL, NullUtil.requireNonNullElements(LIST_WITHOUT_NULL)); }
@Test void testRequireNonNullElements_collection_containts_null() { assertThrows(NullPointerException.class, () -> { NullUtil.requireNonNullElements(LIST_WITH_NULL); }); }
@Test void testRequireNonNullElements_GenericType_String() { assertThrows(NullPointerException.class, () -> { final String msg = "OlleOchTryggve"; try { final String[] result = NullUtil.requireNonNullElements(ARRAY_WITH_NULL, msg); } catch (NullPointerException ex) { assertTrue(ex.getMessage().contains(msg)); throw ex; } }); }
@Test void testRequireNonNullElements_GenericType_String_Ok() { final String[] result = NullUtil.requireNonNullElements(ARRAY_WITHOUT_NULL, "A"); assertArrayEquals(ARRAY_WITHOUT_NULL, result); }