@Test public void testFailedThrowsCorrectException() throws InterruptedException { IOException e = new IOException(); CompletableFuture<Void> f = CompletableFutures.failed(e); try { f.get(); fail("expected exception"); } catch (ExecutionException ex) { assertSame(e, ex.getCause()); } }
@Test public void testFutureGetThrowsUnwrappedException() throws InterruptedException, ExecutionException { IOException cause = new IOException(); Future<Void> f = CompletableFutures.failed(cause); ThrowingSupplier<?, ?> s = CompletableFutures.get(f); try { s.get(); fail("expected exception"); } catch (Throwable ex) { assertSame(cause, ex); } }