|
5 | 5 | import java.io.IOException;
|
6 | 6 | import java.util.function.BooleanSupplier;
|
7 | 7 |
|
| 8 | +import static org.codefx.lab.junitlambda.Console.print; |
8 | 9 | import static org.junit.gen5.api.Assertions.assertAll;
|
9 | 10 | import static org.junit.gen5.api.Assertions.assertEquals;
|
10 | 11 | import static org.junit.gen5.api.Assertions.assertFalse;
|
|
18 | 19 |
|
19 | 20 | public class _1_Assertions {
|
20 | 21 |
|
| 22 | + private static final boolean CATCH_GROUP_ASSERTION_FAILURE_MESSAGE = true; |
| 23 | + |
21 | 24 | @Test
|
22 | 25 | public void boringAssertions() {
|
23 | 26 | String mango = "Mango";
|
@@ -61,11 +64,18 @@ public void exceptionAssertions() {
|
61 | 64 |
|
62 | 65 | @Test
|
63 | 66 | public void groupedAssertions() {
|
64 |
| - assertAll("Multiplication", |
65 |
| - () -> assertEquals(15, 3 * 5, "3 x 5 = 15"), |
66 |
| - // this fails on purpose to see what the message looks like |
67 |
| - () -> assertEquals(15, 5 + 3, "5 x 3 = 15") |
68 |
| - ); |
| 67 | + try { |
| 68 | + assertAll("Multiplication", |
| 69 | + () -> assertEquals(15, 3 * 5, "3 x 5 = 15"), |
| 70 | + // this fails on purpose to see what the message looks like |
| 71 | + () -> assertEquals(15, 5 + 3, "5 x 3 = 15") |
| 72 | + ); |
| 73 | + } catch (AssertionError e) { |
| 74 | + if (CATCH_GROUP_ASSERTION_FAILURE_MESSAGE) |
| 75 | + print("Assertion failed - message starts in next line:\n" + e.getMessage()); |
| 76 | + else |
| 77 | + throw e; |
| 78 | + } |
69 | 79 | }
|
70 | 80 |
|
71 | 81 | }
|
0 commit comments