--- jsr166/src/test/tck/CompletableFutureTest.java 2013/04/08 20:46:59 1.22 +++ jsr166/src/test/tck/CompletableFutureTest.java 2013/04/09 07:50:55 1.23 @@ -495,17 +495,21 @@ public class CompletableFutureTest exten * thenRun result completes normally after normal completion of source */ public void testThenRun() { - CompletableFuture f = new CompletableFuture<>(); - Noop r = new Noop(); - CompletableFuture g = f.thenRun(r); + CompletableFuture f; + CompletableFuture g; + Noop r; + + f = new CompletableFuture<>(); + g = f.thenRun(r = new Noop()); f.complete(null); checkCompletedNormally(g, null); - // reordered version + assertTrue(r.ran); + f = new CompletableFuture<>(); f.complete(null); - r = new Noop(); - g = f.thenRun(r); + g = f.thenRun(r = new Noop()); checkCompletedNormally(g, null); + assertTrue(r.ran); } /** @@ -513,32 +517,58 @@ public class CompletableFutureTest exten * completion of source */ public void testThenRun2() { - CompletableFuture f = new CompletableFuture<>(); - Noop r = new Noop(); - CompletableFuture g = f.thenRun(r); + CompletableFuture f; + CompletableFuture g; + Noop r; + + f = new CompletableFuture<>(); + g = f.thenRun(r = new Noop()); f.completeExceptionally(new CFException()); checkCompletedWithWrappedCFException(g); + assertFalse(r.ran); + + f = new CompletableFuture<>(); + f.completeExceptionally(new CFException()); + g = f.thenRun(r = new Noop()); + checkCompletedWithWrappedCFException(g); + assertFalse(r.ran); } /** * thenRun result completes exceptionally if action does */ public void testThenRun3() { - CompletableFuture f = new CompletableFuture<>(); - FailingNoop r = new FailingNoop(); - CompletableFuture g = f.thenRun(r); + CompletableFuture f; + CompletableFuture g; + FailingNoop r; + + f = new CompletableFuture<>(); + g = f.thenRun(r = new FailingNoop()); f.complete(null); checkCompletedWithWrappedCFException(g); + + f = new CompletableFuture<>(); + f.complete(null); + g = f.thenRun(r = new FailingNoop()); + checkCompletedWithWrappedCFException(g); } /** * thenRun result completes exceptionally if source cancelled */ public void testThenRun4() { - CompletableFuture f = new CompletableFuture<>(); - Noop r = new Noop(); - CompletableFuture g = f.thenRun(r); + CompletableFuture f; + CompletableFuture g; + Noop r; + + f = new CompletableFuture<>(); + g = f.thenRun(r = new Noop()); + assertTrue(f.cancel(true)); + checkCompletedWithWrappedCancellationException(g); + + f = new CompletableFuture<>(); assertTrue(f.cancel(true)); + g = f.thenRun(r = new Noop()); checkCompletedWithWrappedCancellationException(g); }