ValidationUtils { public static <T extends Collection<?>> T assertNotEmpty(T collection, String fieldName) throws IllegalArgumentException{ assertNotNull(collection, fieldName); if (collection.isEmpty()) { throw new IllegalArgumentException(String.format("%s cannot be empty", fieldName)); } return collection; }  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 public void assertNotEmpty_NonNullCollection_ReturnsSameObject() { List<String> testList = new ArrayList<String>(); testList.add("sample"); assertEquals(testList, ValidationUtils.assertNotEmpty(testList, "testList")); }
@Test(expected = IllegalArgumentException.class) public void assertNotEmpty_NullCollection_ThrowsException() { ValidationUtils.assertNotEmpty((Collection<String>) null, "someCollection"); }
@Test(expected = IllegalArgumentException.class) public void assertNotEmpty_EmptyCollection_ThrowsException() { List<String> testList = new ArrayList<String>(); ValidationUtils.assertNotEmpty(testList, "testList"); }
@Test public void assertNotEmpty_NonNullArray_ReturnsSameObject() { String[] array = new String[]{"foo", "bar"}; assertArrayEquals(array, ValidationUtils.assertNotEmpty(array, "array")); }
@Test(expected = IllegalArgumentException.class) public void assertNotEmpty_NullArray_ThrowsException() { ValidationUtils.assertNotEmpty((String[]) null, "array"); }
@Test(expected = IllegalArgumentException.class) public void assertNotEmpty_EmptyArray_ThrowsException() { ValidationUtils.assertNotEmpty(new String[0], "array"); }