Preconditions { @NonNull public static <T> T checkNotNull(T value, @NonNull String errorMessage) { if (value == null) { throw new NullPointerException(errorMessage); } return value; }  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 testCheckNotNullWithNotNull_shouldReturn() { final Object object = new Object(); assertThat(Preconditions.checkNotNull(object, "TestError")).isSameAs(object); }
@Test public void testCheckNotNullWithNull_shouldThrow() { exception.expect(NullPointerException.class); exception.expectMessage("TestError"); Preconditions.checkNotNull(null, "TestError"); }