Preconditions { public static <T> T checkNotNull(T reference) { return checkNotNull(reference, "Provided reference must not be null"); } @VisibleForTesting  Preconditions(); static T checkNotNull(T reference); static T checkNotNull(T reference, String name); static T checkNotNullWithMessage(T reference, String message); static T checkNotNullWithMessage(T reference, String messageFormat, Object... args);  }
@Test(expected = NullPointerException.class) public void shouldThrow_whenNull() { checkNotNull(null); }
@Test public void shouldThrow_withCorrectErrorMessage() { try { checkNotNull(null, ERROR_MESSAGE_ARG); fail("NullPointerException expected"); } catch (NullPointerException npe) { assertThat(npe).hasMessageContaining(ERROR_MESSAGE_ARG); } }
@Test public void shouldReturnCheckingReference_whenNotNull() { String result = checkNotNull(NON_NULL_ARG); assertThat(NON_NULL_ARG).isEqualTo(result); }
@Test public void shouldReturnCheckingReference_whenNotNull_andWithErrorMessage() { String result = checkNotNull(NON_NULL_ARG, ERROR_MESSAGE_ARG); assertThat(NON_NULL_ARG).isEqualTo(result); }