|
20 | 20 | import java.util.ArrayList; |
21 | 21 | import java.util.List; |
22 | 22 | import java.util.concurrent.CompletableFuture; |
| 23 | +import java.util.concurrent.CompletionException; |
23 | 24 | import java.util.concurrent.CountDownLatch; |
24 | 25 | import java.util.concurrent.Executor; |
25 | 26 | import java.util.concurrent.ExecutorService; |
|
48 | 49 | import static java.util.concurrent.TimeUnit.SECONDS; |
49 | 50 | import static org.junit.Assert.assertArrayEquals; |
50 | 51 | import static org.junit.Assert.assertEquals; |
| 52 | +import static org.junit.Assert.assertSame; |
51 | 53 | import static org.junit.Assert.assertTrue; |
52 | 54 | import static org.junit.Assert.fail; |
53 | 55 | import static testsupport.Constants.STACK_EXPLODING_NUMBER; |
@@ -149,16 +151,21 @@ public void catchError() { |
149 | 151 | } |
150 | 152 |
|
151 | 153 | @Test |
152 | | - public void catchErrorSuppressesSecondaryThrowable() { |
153 | | - Throwable foo = new UnsupportedOperationException("foo"); |
154 | | - Throwable bar = new UnsupportedOperationException("bar"); |
| 154 | + public void catchAndRethrow() { |
| 155 | + IllegalStateException expected = new IllegalStateException("expected"); |
| 156 | + IO<Object> catchAndRethrow = IO.throwing(expected) |
| 157 | + .catchError(IO::throwing); |
155 | 158 |
|
156 | 159 | try { |
157 | | - IO.throwing(foo).catchError(t -> IO.throwing(bar)).unsafePerformIO(); |
158 | | - fail("Expected exception to have been thrown, but wasn't."); |
159 | | - } catch (UnsupportedOperationException expected) { |
160 | | - assertEquals(expected, foo); |
161 | | - assertArrayEquals(new Throwable[]{bar}, expected.getSuppressed()); |
| 160 | + catchAndRethrow.unsafePerformIO(); |
| 161 | + } catch (Exception actual) { |
| 162 | + assertSame(expected, actual); |
| 163 | + } |
| 164 | + |
| 165 | + try { |
| 166 | + catchAndRethrow.unsafePerformAsyncIO().join(); |
| 167 | + } catch (CompletionException actual) { |
| 168 | + assertEquals(expected, actual.getCause()); |
162 | 169 | } |
163 | 170 | } |
164 | 171 |
|
|
0 commit comments