Preconditions { public static <T> T checkNotNull(T object, String errorMessage) { return com.tngtech.junit.dataprovider.Preconditions.checkNotNull(object, errorMessage); }  static T checkNotNull(T object, String errorMessage); static void checkArgument(boolean expression, String errorMessage); static void checkArgument(boolean expression, String errorMessageFormat, Object... errorMessageArgs);  }
@SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Test that it works properly if null ;-)") @Test public void testCheckNotNullShouldThrowNullPointerExceptionWithGivenMessageStringIfObjectIsNull() { String errorMessage = "error message"; expectedException.expect(NullPointerException.class); expectedException.expectMessage(errorMessage); Preconditions.checkNotNull(null, errorMessage); }
@Test public void testCheckNotNullShouldNotThrowNullPointerExceptionAndReturnObjectIfObjectIsNull() { Object object = new Object(); Object result = Preconditions.checkNotNull(object, "error message"); assertThat(result).isSameAs(object); }