|
12 | 12 | import java.util.concurrent.CountDownLatch;
|
13 | 13 | import java.util.concurrent.TimeUnit;
|
14 | 14 |
|
15 |
| -import static org.reactivestreams.tck.support.NonFatal.isNonFatal; |
16 | 15 | import static org.testng.Assert.assertNotNull;
|
17 | 16 | import static org.testng.Assert.assertTrue;
|
18 | 17 | import static org.testng.Assert.fail;
|
@@ -77,31 +76,25 @@ public void flop(Throwable thr, String msg) {
|
77 | 76 | }
|
78 | 77 |
|
79 | 78 |
|
80 |
| - public <T extends Throwable> Throwable expectThrowingOf(Class<T> clazz, String errorMsg, Runnable block) throws Throwable { |
| 79 | + public <T extends Throwable> void expectThrowingOfWithMessage(Class<T> clazz, String requiredMessagePart, Runnable block) throws Throwable { |
| 80 | + String errorMsg = String.format("Expected [%s] to be thrown", clazz); |
| 81 | + |
81 | 82 | try {
|
82 | 83 | block.run();
|
83 |
| - flop(errorMsg); |
| 84 | + throw new AssertionError("Expected " + clazz.getCanonicalName() + ", yet no exception was thrown!"); |
84 | 85 | } catch (Throwable e) {
|
85 | 86 | if (clazz.isInstance(e)) {
|
86 | 87 | // ok
|
87 |
| - return e; |
88 |
| - } else if (isNonFatal(e)) { |
89 |
| - flop(errorMsg + " but was: " + e); |
| 88 | + String message = e.getMessage(); |
| 89 | + assertTrue(message.contains(requiredMessagePart), |
| 90 | + String.format("Got expected exception [%s] but missing message part [%s], was: %s", e.getClass(), requiredMessagePart, message)); |
90 | 91 | } else {
|
91 |
| - throw e; |
| 92 | + String msg = errorMsg + " but was: " + e; |
| 93 | + flop(e, msg); |
| 94 | + throw new AssertionError(msg); // would love to include the `e` cause, but that constructor is Java 7+ |
92 | 95 | }
|
93 | 96 | }
|
94 | 97 |
|
95 |
| - // make compiler happy |
96 |
| - return null; |
97 |
| - } |
98 |
| - |
99 |
| - @SuppressWarnings("ThrowableResultOfMethodCallIgnored") |
100 |
| - public <T extends Throwable> void expectThrowingOfWithMessage(Class<T> clazz, String requiredMessagePart, Runnable block) throws Throwable { |
101 |
| - Throwable err = expectThrowingOf(clazz, String.format("Expected [%s] to be thrown", clazz), block); |
102 |
| - String message = err.getMessage(); |
103 |
| - assertTrue(message.contains(requiredMessagePart), |
104 |
| - String.format("Got expected exception [%s] but missing message part [%s], was: %s", err.getClass(), requiredMessagePart, message)); |
105 | 98 | }
|
106 | 99 |
|
107 | 100 | public <T extends Throwable> void assertAsyncErrorWithMessage(Class<T> clazz, String requiredMessagePart) throws Throwable {
|
|
0 commit comments