Preconditions { public static void checkState(boolean expression) { checkStateInternal(expression, true, "Illegal state.", 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(expected = IllegalStateException.class) public void checkState_failure_shouldThrowIllegalStateException() { Preconditions.checkState(false); }
@Test public void checkState_failure_withMessage_shouldThrowIllegalStateException() { try { Preconditions.checkState(false, "message"); fail("no exception thrown"); } catch (IllegalStateException exception) { assertThat(exception.getMessage()).isEqualTo("message"); } }
@Test public void checkState_failure_withNullMessage_shouldThrowIllegalStateException() { try { Preconditions.checkState(false, null); fail("no exception thrown"); } catch (IllegalStateException exception) { assertThat(exception.getMessage()).isEqualTo("null"); } }
@Test public void checkState_failure_withComplexMessage_shouldThrowIllegalStateException() { try { Preconditions.checkState(false, "I %s fail", "should"); fail("no exception thrown"); } catch (IllegalStateException exception) { assertThat(exception.getMessage()).isEqualTo("I should fail"); } }
@Test public void noThrow_checkState_failure_shouldReturnFalse() { assertThat(NoThrow.checkState(false)).isFalse(); }
@Test(expected = IllegalStateException.class) public void noThrow_strictMode_checkState_failure_shouldThrowIllegalStateException() { NoThrow.setStrictMode(true); NoThrow.checkState(false); }
@Test public void noThrow_strictMode_checkState_failure_withMessage_shouldThrowIllegalStateException() { NoThrow.setStrictMode(true); try { NoThrow.checkState(false, "message"); fail("no exception thrown"); } catch (IllegalStateException exception) { assertThat(exception.getMessage()).isEqualTo("message"); } }
@Test public void noThrow_strictMode_checkState_failure_withNullMessage_shouldThrowIllegalStateException() { NoThrow.setStrictMode(true); try { NoThrow.checkState(false, null); fail("no exception thrown"); } catch (IllegalStateException exception) { assertThat(exception.getMessage()).isEqualTo("null"); } }
@Test public void noThrow_strictMode_checkState_failure_withComplexMessage_shouldThrowIllegalStateException() { NoThrow.setStrictMode(true); try { NoThrow.checkState(false, "I %s fail", "should"); fail("no exception thrown"); } catch (IllegalStateException exception) { assertThat(exception.getMessage()).isEqualTo("I should fail"); } }