diff options
Diffstat (limited to 'extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java')
-rw-r--r-- | extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java | 98 |
1 files changed, 48 insertions, 50 deletions
diff --git a/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java b/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java index bcb11bd9..9fc8ee41 100644 --- a/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java +++ b/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java @@ -202,17 +202,16 @@ public final class IntStreamSubjectTest { @Test public void testContainsAtLeast_inOrder_fails() throws Exception { - try { - assertThat(IntStream.of(42, 43)).containsAtLeast(43, 42).inOrder(); - fail(); - } catch (AssertionError expected) { - assertFailureKeys( - expected, - "required elements were all found, but order was wrong", - "expected order for required elements", - "but was"); - assertFailureValue(expected, "expected order for required elements", "[43, 42]"); - } + AssertionError expected = + expectFailure( + whenTesting -> + whenTesting.that(IntStream.of(42, 43)).containsAtLeast(43, 42).inOrder()); + assertFailureKeys( + expected, + "required elements were all found, but order was wrong", + "expected order for required elements", + "but was"); + assertFailureValue(expected, "expected order for required elements", "[43, 42]"); } @Test @@ -237,17 +236,19 @@ public final class IntStreamSubjectTest { @Test public void testContainsAtLeastElementsIn_inOrder_fails() throws Exception { - try { - assertThat(IntStream.of(42, 43)).containsAtLeastElementsIn(asList(43, 42)).inOrder(); - fail(); - } catch (AssertionError expected) { - assertFailureKeys( - expected, - "required elements were all found, but order was wrong", - "expected order for required elements", - "but was"); - assertFailureValue(expected, "expected order for required elements", "[43, 42]"); - } + AssertionError expected = + expectFailure( + whenTesting -> + whenTesting + .that(IntStream.of(42, 43)) + .containsAtLeastElementsIn(asList(43, 42)) + .inOrder()); + assertFailureKeys( + expected, + "required elements were all found, but order was wrong", + "expected order for required elements", + "but was"); + assertFailureValue(expected, "expected order for required elements", "[43, 42]"); } @Test @@ -257,13 +258,10 @@ public final class IntStreamSubjectTest { @Test public void testContainsExactly_fails() throws Exception { - try { - assertThat(IntStream.of(42, 43)).containsExactly(42); - fail(); - } catch (AssertionError expected) { - assertFailureKeys(expected, "unexpected (1)", "---", "expected", "but was"); - assertFailureValue(expected, "expected", "[42]"); - } + AssertionError expected = + expectFailure(whenTesting -> whenTesting.that(IntStream.of(42, 43)).containsExactly(42)); + assertFailureKeys(expected, "unexpected (1)", "---", "expected", "but was"); + assertFailureValue(expected, "expected", "[42]"); } @Test @@ -273,13 +271,12 @@ public final class IntStreamSubjectTest { @Test public void testContainsExactly_inOrder_fails() throws Exception { - try { - assertThat(IntStream.of(42, 43)).containsExactly(43, 42).inOrder(); - fail(); - } catch (AssertionError expected) { - assertFailureKeys(expected, "contents match, but order was wrong", "expected", "but was"); - assertFailureValue(expected, "expected", "[43, 42]"); - } + AssertionError expected = + expectFailure( + whenTesting -> + whenTesting.that(IntStream.of(42, 43)).containsExactly(43, 42).inOrder()); + assertFailureKeys(expected, "contents match, but order was wrong", "expected", "but was"); + assertFailureValue(expected, "expected", "[43, 42]"); } @Test @@ -290,13 +287,12 @@ public final class IntStreamSubjectTest { @Test public void testContainsExactlyElementsIn_fails() throws Exception { - try { - assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(42)); - fail(); - } catch (AssertionError expected) { - assertFailureKeys(expected, "unexpected (1)", "---", "expected", "but was"); - assertFailureValue(expected, "expected", "[42]"); - } + AssertionError expected = + expectFailure( + whenTesting -> + whenTesting.that(IntStream.of(42, 43)).containsExactlyElementsIn(asList(42))); + assertFailureKeys(expected, "unexpected (1)", "---", "expected", "but was"); + assertFailureValue(expected, "expected", "[42]"); } @Test @@ -306,13 +302,15 @@ public final class IntStreamSubjectTest { @Test public void testContainsExactlyElementsIn_inOrder_fails() throws Exception { - try { - assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(43, 42)).inOrder(); - fail(); - } catch (AssertionError expected) { - assertFailureKeys(expected, "contents match, but order was wrong", "expected", "but was"); - assertFailureValue(expected, "expected", "[43, 42]"); - } + AssertionError expected = + expectFailure( + whenTesting -> + whenTesting + .that(IntStream.of(42, 43)) + .containsExactlyElementsIn(asList(43, 42)) + .inOrder()); + assertFailureKeys(expected, "contents match, but order was wrong", "expected", "but was"); + assertFailureValue(expected, "expected", "[43, 42]"); } @Test |