Skip to content

Commit 7423c2f

Browse files
committed
test: add CompletableFutures For method exception
1 parent 18f2d60 commit 7423c2f

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/test/java/com/github/lokic/javaplus/CompletableFuturesTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class CompletableFuturesTest {
1212

1313
@Test
14-
public void test_For() {
14+
public void test_For_success() {
1515
CompletableFuture<String> r = CompletableFuture.completedFuture("1")
1616
.thenCompose(For(t1 -> CompletableFuture.completedFuture("2")))
1717
.thenCompose(For((t1, t2) -> CompletableFuture.completedFuture("3")))
@@ -20,4 +20,19 @@ public void test_For() {
2020
Assert.assertEquals("1234", r.join());
2121
}
2222

23+
@Test
24+
public void test_For_exception() {
25+
CompletableFuture<String> r = CompletableFuture.completedFuture("1")
26+
.thenCompose(For(t1 -> CompletableFuture.completedFuture("2")))
27+
.thenCompose(For((t1, t2) -> {
28+
CompletableFuture<String> f = new CompletableFuture<>();
29+
f.completeExceptionally(new RuntimeException("test"));
30+
return f;
31+
}))
32+
.thenCompose(For((t1, t2, t3) -> CompletableFuture.completedFuture("4")))
33+
.thenApply(Yield((t1, t2, t3, t4) -> t1 + t2 + t3 + t4));
34+
35+
Assert.assertTrue(r.isCompletedExceptionally());
36+
}
37+
2338
}

0 commit comments

Comments
 (0)