--- jsr166/src/test/tck/CompletableFutureTest.java 2013/03/22 22:27:04 1.8 +++ jsr166/src/test/tck/CompletableFutureTest.java 2013/03/31 18:16:35 1.12 @@ -53,7 +53,7 @@ public class CompletableFutureTest exten catch (Throwable fail) { threadUnexpectedException(fail); } } - void checkCompletedNormally(CompletableFuture f, Object value) { + void checkCompletedNormally(CompletableFuture f, T value) { try { assertEquals(value, f.join()); } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -271,6 +271,14 @@ public class CompletableFutureTest exten assertTrue(f.toString().contains("[Completed exceptionally]")); } + /** + * completedFuture returns a completed CompletableFuture with given value + */ + public void testCompletedFuture() { + CompletableFuture f = CompletableFuture.completedFuture("test"); + checkCompletedNormally(f, "test"); + } + static final Supplier supplyOne = () -> Integer.valueOf(1); static final Function inc = @@ -2344,13 +2352,12 @@ public class CompletableFutureTest exten CompletableFuture[] fs = new CompletableFuture[k]; for (int i = 0; i < k; ++i) fs[i] = new CompletableFuture(); - CompletableFuture f = CompletableFuture.allOf(fs); + CompletableFuture f = CompletableFuture.allOf(fs); for (int i = 0; i < k; ++i) { checkIncomplete(f); fs[i].complete(one); } - assertTrue(f.isDone()); - assertFalse(f.isCancelled()); + checkCompletedNormally(f, null); } } @@ -2370,11 +2377,11 @@ public class CompletableFutureTest exten CompletableFuture[] fs = new CompletableFuture[k]; for (int i = 0; i < k; ++i) fs[i] = new CompletableFuture(); - CompletableFuture f = CompletableFuture.anyOf(fs); + CompletableFuture f = CompletableFuture.anyOf(fs); checkIncomplete(f); for (int i = 0; i < k; ++i) { fs[i].complete(one); - assertTrue(f.isDone()); + checkCompletedNormally(f, one); } } } @@ -2386,6 +2393,9 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture g = new CompletableFuture(); CompletableFuture h; + Runnable[] actions = { + () => f.thenApply(null), + } try { h = f.thenApply(null); } catch (NullPointerException ok) {} try { h = f.thenAccept(null); } catch (NullPointerException ok) {} try { h = f.thenRun(null); } catch (NullPointerException ok) {}