Preconditions { public static void checkArgument(boolean expression) { checkArgumentInternal(expression, true, "Illegal argument.", 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 checkArgument_success_shouldNotThrow() { Preconditions.checkArgument(true); }
@Test(expected = IllegalArgumentException.class) public void checkArgument_failure_shouldThrowIllegalArgumentException() { Preconditions.checkArgument(false); }
@Test public void checkArgument_failure_withMessage_shouldThrowIllegalArgumentException() { try { Preconditions.checkArgument(false, "message"); fail("no exception thrown"); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("message"); } }
@Test public void checkArgument_failure_withNullMessage_shouldThrowIllegalArgumentException() { try { Preconditions.checkArgument(false, null); fail("no exception thrown"); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("null"); } }
@Test public void checkArgument_failure_withComplexMessage_shouldThrowIllegalArgumentException() { try { Preconditions.checkArgument(false, "I %s fail", "should"); fail("no exception thrown"); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("I should fail"); } }
@Test public void checkState_success_shouldNotThrow() { Preconditions.checkArgument(true); }
@Test public void noThrow_checkArgument_success_shouldReturnTrue() { assertThat(NoThrow.checkArgument(true)).isTrue(); }
@Test public void noThrow_checkArgument_failure_shouldReturnFalse() { assertThat(NoThrow.checkArgument(false)).isFalse(); }
@Test(expected = IllegalArgumentException.class) public void noThrow_strictMode_checkArgument_failure_shouldThrowIllegalArgumentException() { NoThrow.setStrictMode(true); NoThrow.checkArgument(false); }
@Test public void noThrow_strictMode_checkArgument_failure_withMessage_shouldThrowIllegalArgumentException() { NoThrow.setStrictMode(true); try { NoThrow.checkArgument(false, "message"); fail("no exception thrown"); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("message"); } }
@Test public void noThrow_strictMode_checkArgument_failure_withNullMessage_shouldThrowIllegalArgumentException() { NoThrow.setStrictMode(true); try { NoThrow.checkArgument(false, null); fail("no exception thrown"); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("null"); } }
@Test public void noThrow_strictMode_checkArgument_failure_withComplexMessage_shouldThrowIllegalArgumentException() { NoThrow.setStrictMode(true); try { NoThrow.checkArgument(false, "I %s fail", "should"); fail("no exception thrown"); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("I should fail"); } }
@Test public void noThrow_checkState_success_shouldReturnTrue() { assertThat(NoThrow.checkArgument(true)).isTrue(); }
@Test public void checkArgument_failure_withInvalidMessage_shouldThrowIllegalArgumentException() { try { Preconditions.checkArgument(false, "messages: ", "message1", "message2"); fail("no exception thrown"); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("messages: "); } }