Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ExpectFailure instead of try-catch-fail. #1093

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,16 @@ public void testContainsAtLeast_inOrder() throws Exception {

@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
Expand All @@ -237,17 +236,19 @@ public void testContainsAtLeastElementsIn_inOrder() throws Exception {

@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
Expand All @@ -257,13 +258,10 @@ public void testContainsExactly() throws Exception {

@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
Expand All @@ -273,13 +271,12 @@ public void testContainsExactly_inOrder() throws Exception {

@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
Expand All @@ -290,13 +287,12 @@ public void testContainsExactlyElementsIn() throws Exception {

@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
Expand All @@ -306,13 +302,15 @@ public void testContainsExactlyElementsIn_inOrder() throws Exception {

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,16 @@ public void testContainsAtLeast_inOrder() throws Exception {

@Test
public void testContainsAtLeast_inOrder_fails() throws Exception {
try {
assertThat(LongStream.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(LongStream.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
Expand Down Expand Up @@ -248,17 +247,19 @@ public void testContainsAtLeastElementsIn_inOrder() throws Exception {

@Test
public void testContainsAtLeastElementsIn_inOrder_fails() throws Exception {
try {
assertThat(LongStream.of(42, 43)).containsAtLeastElementsIn(asList(43L, 42L)).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(LongStream.of(42, 43))
.containsAtLeastElementsIn(asList(43L, 42L))
.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
Expand All @@ -279,13 +280,10 @@ public void testContainsExactly() throws Exception {

@Test
public void testContainsExactly_fails() throws Exception {
try {
assertThat(LongStream.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(LongStream.of(42, 43)).containsExactly(42));
assertFailureKeys(expected, "unexpected (1)", "---", "expected", "but was");
assertFailureValue(expected, "expected", "[42]");
}

@Test
Expand All @@ -295,13 +293,12 @@ public void testContainsExactly_inOrder() throws Exception {

@Test
public void testContainsExactly_inOrder_fails() throws Exception {
try {
assertThat(LongStream.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(LongStream.of(42, 43)).containsExactly(43, 42).inOrder());
assertFailureKeys(expected, "contents match, but order was wrong", "expected", "but was");
assertFailureValue(expected, "expected", "[43, 42]");
}

@Test
Expand All @@ -312,13 +309,12 @@ public void testContainsExactlyElementsIn() throws Exception {

@Test
public void testContainsExactlyElementsIn_fails() throws Exception {
try {
assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(42L));
fail();
} catch (AssertionError expected) {
assertFailureKeys(expected, "unexpected (1)", "---", "expected", "but was");
assertFailureValue(expected, "expected", "[42]");
}
AssertionError expected =
expectFailure(
whenTesting ->
whenTesting.that(LongStream.of(42, 43)).containsExactlyElementsIn(asList(42L)));
assertFailureKeys(expected, "unexpected (1)", "---", "expected", "but was");
assertFailureValue(expected, "expected", "[42]");
}

@Test
Expand All @@ -336,13 +332,15 @@ public void testContainsExactlyElementsIn_inOrder() throws Exception {

@Test
public void testContainsExactlyElementsIn_inOrder_fails() throws Exception {
try {
assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(43L, 42L)).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(LongStream.of(42, 43))
.containsExactlyElementsIn(asList(43L, 42L))
.inOrder());
assertFailureKeys(expected, "contents match, but order was wrong", "expected", "but was");
assertFailureValue(expected, "expected", "[43, 42]");
}

@Test
Expand Down
Loading