Preconditions { @NonNull public static <T> Collection<T> checkNotEmpty(Collection<T> collection, @NonNull String errorMessage) { checkState(collection != null && !collection.isEmpty(), errorMessage); return collection; }  static void checkState(final boolean expression, @NonNull String errorMessage); @NonNull static T checkNotNull(T value, @NonNull String errorMessage); @NonNull static Collection<T> checkNotEmpty(Collection<T> collection, @NonNull String errorMessage);  }
@Test public void testCheckNotEmptyWithNotEmpty_shouldReturn() { final Collection<String> collection = Arrays.asList("value1", "value2"); assertThat(Preconditions.checkNotEmpty(collection, "TestError")).isSameAs(collection); }
@Test public void testCheckNotEmptyWithEmpty_shouldThrow() { exception.expect(IllegalStateException.class); exception.expectMessage("TestError"); final Collection<String> collection = Collections.EMPTY_LIST; assertThat(Preconditions.checkNotEmpty(collection, "TestError")); }
@Test public void testCheckNotEmptyWithNulkl_shouldThrow() { exception.expect(IllegalStateException.class); exception.expectMessage("TestError"); assertThat(Preconditions.checkNotEmpty(null, "TestError")); }