--- jsr166/src/test/tck/CompletableFutureTest.java 2014/06/01 23:20:19 1.37 +++ jsr166/src/test/tck/CompletableFutureTest.java 2014/06/01 23:51:44 1.38 @@ -318,14 +318,18 @@ public class CompletableFutureTest exten // Choose non-commutative actions for better coverage - // A non-commutative function that handles null values as well, - // and produces null values occasionally. - public static Integer subtract(Integer x, Integer y) { + // A non-commutative function that handles and produces null values as well. + static Integer subtract(Integer x, Integer y) { return (x == null && y == null) ? null : ((x == null) ? 42 : x.intValue()) - ((y == null) ? 99 : y.intValue()); } + // A function that handles and produces null values as well. + static Integer inc(Integer x) { + return (x == null) ? null : x + 1; + } + static final Supplier supplyOne = () -> Integer.valueOf(1); static final Function inc = @@ -333,8 +337,22 @@ public class CompletableFutureTest exten static final BiFunction subtract = (Integer x, Integer y) -> subtract(x, y); static final class IncAction implements Consumer { - int value; - public void accept(Integer x) { value = x.intValue() + 1; } + int invocationCount = 0; + Integer value; + public boolean ran() { return invocationCount == 1; } + public void accept(Integer x) { + invocationCount++; + value = inc(x); + } + } + static final class IncFunction implements Function { + int invocationCount = 0; + Integer value; + public boolean ran() { return invocationCount == 1; } + public Integer apply(Integer x) { + invocationCount++; + return value = inc(x); + } } static final class SubtractAction implements BiConsumer { int invocationCount = 0; @@ -449,6 +467,34 @@ public class CompletableFutureTest exten BiFunction a) { return f.thenCombine(g, a); } + public CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a) { + return f.applyToEither(g, a); + } + public CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a) { + return f.acceptEither(g, a); + } + public CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a) { + return f.runAfterEither(g, a); + } + public CompletableFuture thenCompose + (CompletableFuture f, + Function> a) { + return f.thenCompose(a); + } + public CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a) { + return f.whenComplete(a); + } }, // /** Experimental way to do more testing */ @@ -482,6 +528,34 @@ public class CompletableFutureTest exten BiFunction a) { return f.thenCombineAsync(g, a); } + public CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a) { + return f.applyToEitherAsync(g, a); + } + public CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a) { + return f.acceptEitherAsync(g, a); + } + public CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a) { + return f.runAfterEitherAsync(g, a); + } + public CompletableFuture thenCompose + (CompletableFuture f, + Function> a) { + return f.thenComposeAsync(a); + } + public CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a) { + return f.whenCompleteAsync(a); + } }, // REVERSE_DEFAULT_ASYNC { @@ -514,6 +588,34 @@ public class CompletableFutureTest exten BiFunction a) { return f.thenCombineAsync(g, a, new ThreadExecutor()); } + public CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a) { + return f.applyToEitherAsync(g, a, new ThreadExecutor()); + } + public CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a) { + return f.acceptEitherAsync(g, a, new ThreadExecutor()); + } + public CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a) { + return f.runAfterEitherAsync(g, a, new ThreadExecutor()); + } + public CompletableFuture thenCompose + (CompletableFuture f, + Function> a) { + return f.thenComposeAsync(a, new ThreadExecutor()); + } + public CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a) { + return f.whenCompleteAsync(a, new ThreadExecutor()); + } }; public abstract CompletableFuture runAfterBoth @@ -526,6 +628,26 @@ public class CompletableFutureTest exten (CompletableFuture f, CompletionStage g, BiFunction a); + public abstract CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a); + public abstract CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a); + public abstract CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a); + public abstract CompletableFuture thenCompose + (CompletableFuture f, + Function> a); + public abstract CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a); + + } /** @@ -778,7 +900,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.thenAccept(r); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -1797,7 +1919,7 @@ public class CompletableFutureTest exten checkCompletedNormally(g, null); f2.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); r = new IncAction(); f = new CompletableFuture<>(); @@ -1805,7 +1927,7 @@ public class CompletableFutureTest exten f2 = new CompletableFuture<>(); g = f.acceptEither(f2, r); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -2115,7 +2237,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.thenAcceptAsync(r); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -2229,7 +2351,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.acceptEitherAsync(f2, r); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); r = new IncAction(); f = new CompletableFuture<>(); @@ -2237,7 +2359,7 @@ public class CompletableFutureTest exten f2 = new CompletableFuture<>(); g = f.acceptEitherAsync(f2, r); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -2554,7 +2676,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.thenAcceptAsync(r, new ThreadExecutor()); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -2668,7 +2790,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); r = new IncAction(); f = new CompletableFuture<>(); @@ -2676,7 +2798,7 @@ public class CompletableFutureTest exten f2 = new CompletableFuture<>(); g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /**