ValidationUtils { public static <T> T assertNotNull(T object, String fieldName) throws IllegalArgumentException { if (object == null) { throw new IllegalArgumentException(String.format("%s cannot be null", fieldName)); } return object; }  static T assertNotNull(T object, String fieldName); static void assertAllAreNull(String messageIfNull, Object... objects); static int assertIsPositive(int num, String fieldName); static T assertNotEmpty(T collection, String fieldName); static T[] assertNotEmpty(T[] array, String fieldName); static String assertStringNotEmpty(String string, String fieldName);  }
@Test(expected = IllegalArgumentException.class) public void assertNotNull_NullObject_ThrowsException() { ValidationUtils.assertNotNull(null, "someField"); }
@Test public void assertNotNull_NonNullObject_ReturnsSameObject() { String nonNullString = "foo"; assertEquals(nonNullString, ValidationUtils.assertNotNull(nonNullString, "nonNullString")); }