Preconditions { public static void checkNotNull(Object reference) { checkNotNullInternal(reference, true, "Object can not be null.", EMPTY_ARGUMENTS); } private  Preconditions(); static void checkArgument(boolean expression); static void checkArgument(boolean expression, String errorMessage); static void checkArgument(boolean expression,
            String errorMessageTemplate, Object... errorMessageArgs); static void checkState(boolean expression); static void checkState(boolean expression, String errorMessage); static void checkState(boolean expression,
            String errorMessageTemplate, Object... errorMessageArgs); static void checkNotNull(Object reference); static void checkNotNull(Object reference, String errorMessage); static void checkNotNull(Object reference,
            String errorMessageTemplate, Object... errorMessageArgs); static void checkUiThread(); static void checkUiThread(String errorMessage); static void checkUiThread(String errorMessageTemplate, Object... errorMessageArgs); static final String EMPTY_ARGUMENTS; }
@Test public void checkNotNull_success_shouldNotThrow() { Preconditions.checkNotNull(new Object()); }
@Test(expected = NullPointerException.class) public void checkNotNull_failure_shouldThrowNullPointerException() { Preconditions.checkNotNull(null); }
@Test public void checkNotNull_failure_withMessage_shouldThrowNullPointerException() { try { Preconditions.checkNotNull(null, "message"); fail("no exception thrown"); } catch (NullPointerException exception) { assertThat(exception.getMessage()).isEqualTo("message"); } }
@Test public void checkNotNull_failure_withNullMessage_shouldThrowNullPointerException() { try { Preconditions.checkNotNull(null, null); fail("no exception thrown"); } catch (NullPointerException exception) { assertThat(exception.getMessage()).isEqualTo("null"); } }
@Test public void checkNotNull_failure_withComplexMessage_shouldThrowNullPointerException() { try { Preconditions.checkNotNull(null, "I %s fail", "should"); fail("no exception thrown"); } catch (NullPointerException exception) { assertThat(exception.getMessage()).isEqualTo("I should fail"); } }
@Test public void noThrow_checkNotNull_success_shouldReturnTrue() { assertThat(NoThrow.checkNotNull(new Object())).isTrue(); }
@Test public void noThrow_checkNotNull_failure_shouldReturnFalse() { assertThat(NoThrow.checkNotNull(null)).isFalse(); }
@Test(expected = NullPointerException.class) public void noThrow_strictMode_checkNotNull_failure_shouldThrowNullPointerException() { NoThrow.setStrictMode(true); NoThrow.checkNotNull(null); }
@Test public void noThrow_strictMode_checkNotNull_failure_withMessage_shouldThrowNullPointerException() { NoThrow.setStrictMode(true); try { NoThrow.checkNotNull(null, "message"); fail("no exception thrown"); } catch (NullPointerException exception) { assertThat(exception.getMessage()).isEqualTo("message"); } }
@Test public void noThrow_strictMode_checkNotNull_failure_withNullMessage_shouldThrowNullPointerException() { NoThrow.setStrictMode(true); try { NoThrow.checkNotNull(null, null); fail("no exception thrown"); } catch (NullPointerException exception) { assertThat(exception.getMessage()).isEqualTo("null"); } }
@Test public void noThrow_strictMode_checkNotNull_failure_withComplexMessage_shouldThrowNullPointerException() { NoThrow.setStrictMode(true); try { NoThrow.checkNotNull(null, "I %s fail", "should"); fail("no exception thrown"); } catch (NullPointerException exception) { assertThat(exception.getMessage()).isEqualTo("I should fail"); } }