--- jsr166/src/test/tck/CompletableFutureTest.java 2013/04/03 16:59:57 1.15 +++ jsr166/src/test/tck/CompletableFutureTest.java 2013/04/04 04:16:02 1.17 @@ -345,7 +345,10 @@ public class CompletableFutureTest exten // Used for explicit executor tests static final class ThreadExecutor implements Executor { + AtomicInteger count = new AtomicInteger(0); + public void execute(Runnable r) { + count.getAndIncrement(); new Thread(r).start(); } } @@ -432,10 +435,12 @@ public class CompletableFutureTest exten */ public void testRunAsync2() { Noop r = new Noop(); - CompletableFuture f = CompletableFuture.runAsync(r, new ThreadExecutor()); + ThreadExecutor exec = new ThreadExecutor(); + CompletableFuture f = CompletableFuture.runAsync(r, exec); assertNull(f.join()); assertTrue(r.ran); checkCompletedNormally(f, null); + assertEquals(1, exec.count.get()); } /** @@ -452,16 +457,20 @@ public class CompletableFutureTest exten * supplyAsync completes with result of supplier */ public void testSupplyAsync() { - CompletableFuture f = CompletableFuture.supplyAsync(supplyOne); + CompletableFuture f; + f = CompletableFuture.supplyAsync(supplyOne); assertEquals(f.join(), one); + checkCompletedNormally(f, one); } /** * supplyAsync with executor completes with result of supplier */ public void testSupplyAsync2() { - CompletableFuture f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor()); + CompletableFuture f; + f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor()); assertEquals(f.join(), one); + checkCompletedNormally(f, one); } /** @@ -2418,12 +2427,12 @@ public class CompletableFutureTest exten CompletableFuture g = new CompletableFuture(); CompletableFuture nullFuture = (CompletableFuture)null; CompletableFuture h; - Executor exec = new ThreadExecutor(); + ThreadExecutor exec = new ThreadExecutor(); Runnable[] throwingActions = { () -> { CompletableFuture.supplyAsync(null); }, () -> { CompletableFuture.supplyAsync(null, exec); }, - () -> { CompletableFuture.supplyAsync(() -> one, null); }, + () -> { CompletableFuture.supplyAsync(supplyOne, null); }, () -> { CompletableFuture.runAsync(null); }, () -> { CompletableFuture.runAsync(null, exec); }, @@ -2512,14 +2521,10 @@ public class CompletableFutureTest exten () -> { CompletableFuture.anyOf((CompletableFuture[])null); }, () -> { CompletableFuture.anyOf(f, null); }, () -> { CompletableFuture.anyOf(null, f); }, - - // TODO: Crashes javac with lambda-8-2013-03-31... - //() -> { CompletableFuture x = f.thenAccept(null); }, - //() -> { CompletableFuture x = f.thenRun(null); }, - //() -> { CompletableFuture x = f.thenApply(() -> { ; }); }, }; assertThrows(NullPointerException.class, throwingActions); + assertEquals(0, exec.count.get()); } }