ConsistencyUtils { public static <T> Collection<T> checkNotEmpty(Collection<T> container) { if (checkNotNull(container).isEmpty()) { throw new IllegalArgumentException("Container cannot be null or empty"); } return container; } private  ConsistencyUtils(); static T checkNotNull(T object); static T checkNotNull(T object, String message); static String checkEmptyString(String object, String message); static String checkEmptyString(String object); static T checkInstance(Object obj, Class<T> type); static Collection<T> checkNotEmpty(Collection<T> container); static Collection<T> containsNoNulls(Collection<T> container);  }
@Test public void shouldReturnSameObjectWhenCollectionHasItems() throws Exception { List<String> list = new ArrayList<>(); list.add("0"); Collection<String> returnedList = ConsistencyUtils.checkNotEmpty(list); assertSame(list, returnedList); }
@Test public void shouldThrowNullPointerExceptionWhenCollectionIsNull() throws Exception { thrown.expect(NullPointerException.class); thrown.expectMessage("The object is null"); List<String> list = null; ConsistencyUtils.checkNotEmpty(list); }
@Test public void shouldThrowIllegalArgumentExceptionWhenCollectionIsEmpty() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Container cannot be null or empty"); List<String> list = new ArrayList<>(); ConsistencyUtils.checkNotEmpty(list); }