public void testCheckState_simple_failure() { try { Preconditions.checkState(false); fail("no exception thrown"); } catch (IllegalStateException expected) { } }
public void testCheckState_complexMessage_failure() { try { Preconditions.checkState(false, FORMAT, 5); fail("no exception thrown"); } catch (IllegalStateException expected) { verifyComplexMessage(expected); } }
public void testCheckElementIndex_badSize() { try { Preconditions.checkElementIndex(1, -1); fail(); } catch (IllegalArgumentException expected) { // don't care what the message text is, as this is an invalid usage of // the Preconditions class, unlike all the other exceptions it throws } }
public void testCheckPositionIndex_badSize() { try { Preconditions.checkPositionIndex(1, -1); fail(); } catch (IllegalArgumentException expected) { // don't care what the message text is, as this is an invalid usage of // the Preconditions class, unlike all the other exceptions it throws } }
public void testCheckArgument_complexMessage_failure() { try { Preconditions.checkArgument(false, FORMAT, 5); fail("no exception thrown"); } catch (IllegalArgumentException expected) { verifyComplexMessage(expected); } }
public void testCheckPositionIndexes_badSize() { try { Preconditions.checkPositionIndexes(1, 1, -1); fail(); } catch (IllegalArgumentException expected) { } }
public void testCheckArgument_nullMessageWithArgs_failure() { try { Preconditions.checkArgument(false, null, "b", "d"); fail("no exception thrown"); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat().isEqualTo("null [b, d]"); } }
public void testCheckArgument_nullArgs_failure() { try { Preconditions.checkArgument(false, "A %s C %s E", null, null); fail("no exception thrown"); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat().isEqualTo("A null C null E"); } }
public void testCheckArgument_tooManyArgs_failure() { try { Preconditions.checkArgument(false, "A %s C %s E", "b", "d", "f"); fail("no exception thrown"); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat().isEqualTo("A b C d E [f]"); } }
public void testCheckState_nullMessage_failure() { try { Preconditions.checkState(false, null); fail("no exception thrown"); } catch (IllegalStateException expected) { assertThat(expected).hasMessageThat().isEqualTo("null"); } }
public void testCheckState_simpleMessage_failure() { try { Preconditions.checkState(false, new Message()); fail("no exception thrown"); } catch (IllegalStateException expected) { verifySimpleMessage(expected); } }
public void testCheckNotNull_simpleMessage_failure() { try { Preconditions.checkNotNull(null, new Message()); fail("no exception thrown"); } catch (NullPointerException expected) { verifySimpleMessage(expected); } }
public void testCheckArgument_simpleMessage_failure() { try { Preconditions.checkArgument(false, new Message()); fail("no exception thrown"); } catch (IllegalArgumentException expected) { verifySimpleMessage(expected); } }
public void testCheckElementIndex_tooHigh() { try { Preconditions.checkElementIndex(1, 1); fail(); } catch (IndexOutOfBoundsException expected) { assertThat(expected).hasMessageThat().isEqualTo("index (1) must be less than size (1)"); } }
public void testCheckElementIndex_negative() { try { Preconditions.checkElementIndex(-1, 1); fail(); } catch (IndexOutOfBoundsException expected) { assertThat(expected).hasMessageThat().isEqualTo("index (-1) must not be negative"); } }
public void testCheckElementIndex_withDesc_tooHigh() { try { Preconditions.checkElementIndex(1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { assertThat(expected).hasMessageThat().isEqualTo("foo (1) must be less than size (1)"); } }
public void testCheckPositionIndex_withDesc_tooHigh() { try { Preconditions.checkPositionIndex(2, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { assertThat(expected).hasMessageThat().isEqualTo("foo (2) must not be greater than size (1)"); } }
public void testCheckPositionIndex_negative() { try { Preconditions.checkPositionIndex(-1, 1); fail(); } catch (IndexOutOfBoundsException expected) { assertThat(expected).hasMessageThat().isEqualTo("index (-1) must not be negative"); } }
public void testCheckPositionIndex_startNegative() { try { Preconditions.checkPositionIndexes(-1, 1, 1); fail(); } catch (IndexOutOfBoundsException expected) { assertThat(expected).hasMessageThat().isEqualTo("start index (-1) must not be negative"); } }
public void testCheckElementIndex_withDesc_negative() { try { Preconditions.checkElementIndex(-1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { assertThat(expected).hasMessageThat().isEqualTo("foo (-1) must not be negative"); } }