ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.30 by jsr166, Mon Jul 22 18:25:42 2013 UTC vs.
Revision 1.40 by jsr166, Mon Jun 2 01:11:53 2014 UTC

# Line 16 | Line 16 | import java.util.concurrent.ExecutionExc
16   import java.util.concurrent.Future;
17   import java.util.concurrent.CompletableFuture;
18   import java.util.concurrent.CompletionException;
19 + import java.util.concurrent.CompletionStage;
20   import java.util.concurrent.TimeoutException;
21   import java.util.concurrent.atomic.AtomicInteger;
22   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 102 | Line 103 | public class CompletableFutureTest exten
103          assertTrue(f.toString().contains("[Completed exceptionally]"));
104      }
105  
106 +    void checkCompletedWithWrappedCFException(CompletableFuture<?> f,
107 +                                              CFException ex) {
108 +        try {
109 +            f.get(LONG_DELAY_MS, MILLISECONDS);
110 +            shouldThrow();
111 +        } catch (ExecutionException success) {
112 +            assertSame(ex, success.getCause());
113 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
114 +        try {
115 +            f.join();
116 +            shouldThrow();
117 +        } catch (CompletionException success) {
118 +            assertSame(ex, success.getCause());
119 +        }
120 +        try {
121 +            f.getNow(null);
122 +            shouldThrow();
123 +        } catch (CompletionException success) {
124 +            assertSame(ex, success.getCause());
125 +        }
126 +        try {
127 +            f.get();
128 +            shouldThrow();
129 +        } catch (ExecutionException success) {
130 +            assertSame(ex, success.getCause());
131 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
132 +        assertTrue(f.isDone());
133 +        assertFalse(f.isCancelled());
134 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
135 +    }
136 +
137      void checkCancelled(CompletableFuture<?> f) {
138          try {
139              f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 286 | Line 318 | public class CompletableFutureTest exten
318  
319      // Choose non-commutative actions for better coverage
320  
321 +    // A non-commutative function that handles and produces null values as well.
322 +    static Integer subtract(Integer x, Integer y) {
323 +        return (x == null && y == null) ? null :
324 +            ((x == null) ? 42 : x.intValue())
325 +            - ((y == null) ? 99 : y.intValue());
326 +    }
327 +
328 +    // A function that handles and produces null values as well.
329 +    static Integer inc(Integer x) {
330 +        return (x == null) ? null : x + 1;
331 +    }
332 +
333      static final Supplier<Integer> supplyOne =
334          () -> Integer.valueOf(1);
335      static final Function<Integer, Integer> inc =
336          (Integer x) -> Integer.valueOf(x.intValue() + 1);
337      static final BiFunction<Integer, Integer, Integer> subtract =
338 <        (Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue());
338 >        (Integer x, Integer y) -> subtract(x, y);
339      static final class IncAction implements Consumer<Integer> {
340 <        int value;
341 <        public void accept(Integer x) { value = x.intValue() + 1; }
340 >        int invocationCount = 0;
341 >        Integer value;
342 >        public boolean ran() { return invocationCount == 1; }
343 >        public void accept(Integer x) {
344 >            invocationCount++;
345 >            value = inc(x);
346 >        }
347 >    }
348 >    static final class IncFunction implements Function<Integer,Integer> {
349 >        int invocationCount = 0;
350 >        Integer value;
351 >        public boolean ran() { return invocationCount == 1; }
352 >        public Integer apply(Integer x) {
353 >            invocationCount++;
354 >            return value = inc(x);
355 >        }
356      }
357      static final class SubtractAction implements BiConsumer<Integer, Integer> {
358 <        int value;
358 >        int invocationCount = 0;
359 >        Integer value;
360 >        // Check this action was invoked exactly once when result is computed.
361 >        public boolean ran() { return invocationCount == 1; }
362          public void accept(Integer x, Integer y) {
363 <            value = x.intValue() - y.intValue();
363 >            invocationCount++;
364 >            value = subtract(x, y);
365 >        }
366 >    }
367 >    static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> {
368 >        int invocationCount = 0;
369 >        Integer value;
370 >        // Check this action was invoked exactly once when result is computed.
371 >        public boolean ran() { return invocationCount == 1; }
372 >        public Integer apply(Integer x, Integer y) {
373 >            invocationCount++;
374 >            return value = subtract(x, y);
375          }
376      }
377      static final class Noop implements Runnable {
# Line 374 | Line 446 | public class CompletableFutureTest exten
446      }
447  
448      /**
449 +     * Permits the testing of parallel code for the 3 different
450 +     * execution modes without repeating all the testing code.
451 +     */
452 +    enum ExecutionMode {
453 +        DEFAULT {
454 +            public <T,U> CompletableFuture<Void> runAfterBoth
455 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
456 +                return f.runAfterBoth(g, a);
457 +            }
458 +            public <T,U> CompletableFuture<Void> thenAcceptBoth
459 +                (CompletableFuture<T> f,
460 +                 CompletionStage<? extends U> g,
461 +                 BiConsumer<? super T,? super U> a) {
462 +                return f.thenAcceptBoth(g, a);
463 +            }
464 +            public <T,U,V> CompletableFuture<V> thenCombine
465 +                (CompletableFuture<T> f,
466 +                 CompletionStage<? extends U> g,
467 +                 BiFunction<? super T,? super U,? extends V> a) {
468 +                return f.thenCombine(g, a);
469 +            }
470 +            public <T,U> CompletableFuture<U> applyToEither
471 +                (CompletableFuture<T> f,
472 +                 CompletionStage<? extends T> g,
473 +                 Function<? super T,U> a) {
474 +                return f.applyToEither(g, a);
475 +            }
476 +            public <T> CompletableFuture<Void> acceptEither
477 +                (CompletableFuture<T> f,
478 +                 CompletionStage<? extends T> g,
479 +                 Consumer<? super T> a) {
480 +                return f.acceptEither(g, a);
481 +            }
482 +            public <T> CompletableFuture<Void> runAfterEither
483 +                (CompletableFuture<T> f,
484 +                 CompletionStage<?> g,
485 +                 java.lang.Runnable a) {
486 +                return f.runAfterEither(g, a);
487 +            }
488 +            public <T,U> CompletableFuture<U> thenCompose
489 +                (CompletableFuture<T> f,
490 +                 Function<? super T,? extends CompletionStage<U>> a) {
491 +                return f.thenCompose(a);
492 +            }
493 +            public <T> CompletableFuture<T> whenComplete
494 +                (CompletableFuture<T> f,
495 +                 BiConsumer<? super T,? super Throwable> a) {
496 +                return f.whenComplete(a);
497 +            }
498 +        },
499 +
500 + //             /** Experimental way to do more testing */
501 + //         REVERSE_DEFAULT {
502 + //             public <T,U> CompletableFuture<Void> runAfterBoth
503 + //                 (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
504 + //                 return g.runAfterBoth(f, a);
505 + //             }
506 + //             public <T,U> CompletableFuture<Void> thenAcceptBoth
507 + //                 (CompletableFuture<T> f,
508 + //                  CompletionStage<? extends U> g,
509 + //                  BiConsumer<? super T,? super U> a) {
510 + //                 return DEFAULT.thenAcceptBoth(f, g, a);
511 + //             }
512 + //         },
513 +
514 +        DEFAULT_ASYNC {
515 +            public <T,U> CompletableFuture<Void> runAfterBoth
516 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
517 +                return f.runAfterBothAsync(g, a);
518 +            }
519 +            public <T,U> CompletableFuture<Void> thenAcceptBoth
520 +                (CompletableFuture<T> f,
521 +                 CompletionStage<? extends U> g,
522 +                 BiConsumer<? super T,? super U> a) {
523 +                return f.thenAcceptBothAsync(g, a);
524 +            }
525 +            public <T,U,V> CompletableFuture<V> thenCombine
526 +                (CompletableFuture<T> f,
527 +                 CompletionStage<? extends U> g,
528 +                 BiFunction<? super T,? super U,? extends V> a) {
529 +                return f.thenCombineAsync(g, a);
530 +            }
531 +            public <T,U> CompletableFuture<U> applyToEither
532 +                (CompletableFuture<T> f,
533 +                 CompletionStage<? extends T> g,
534 +                 Function<? super T,U> a) {
535 +                return f.applyToEitherAsync(g, a);
536 +            }
537 +            public <T> CompletableFuture<Void> acceptEither
538 +                (CompletableFuture<T> f,
539 +                 CompletionStage<? extends T> g,
540 +                 Consumer<? super T> a) {
541 +                return f.acceptEitherAsync(g, a);
542 +            }
543 +            public <T> CompletableFuture<Void> runAfterEither
544 +                (CompletableFuture<T> f,
545 +                 CompletionStage<?> g,
546 +                 java.lang.Runnable a) {
547 +                return f.runAfterEitherAsync(g, a);
548 +            }
549 +            public <T,U> CompletableFuture<U> thenCompose
550 +                (CompletableFuture<T> f,
551 +                 Function<? super T,? extends CompletionStage<U>> a) {
552 +                return f.thenComposeAsync(a);
553 +            }
554 +            public <T> CompletableFuture<T> whenComplete
555 +                (CompletableFuture<T> f,
556 +                 BiConsumer<? super T,? super Throwable> a) {
557 +                return f.whenCompleteAsync(a);
558 +            }
559 +        },
560 +
561 + //         REVERSE_DEFAULT_ASYNC {
562 + //             public <T,U> CompletableFuture<Void> runAfterBoth
563 + //                 (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
564 + //                 return f.runAfterBothAsync(g, a);
565 + //             }
566 + //             public <T,U> CompletableFuture<Void> thenAcceptBoth
567 + //                 (CompletableFuture<T> f,
568 + //                  CompletionStage<? extends U> g,
569 + //                  BiConsumer<? super T,? super U> a) {
570 + //                 return DEFAULT_ASYNC.thenAcceptBoth(f, g, a);
571 + //             }
572 + //         },
573 +
574 +        EXECUTOR {
575 +            public <T,U> CompletableFuture<Void> runAfterBoth
576 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
577 +                return f.runAfterBothAsync(g, a, new ThreadExecutor());
578 +            }
579 +            public <T,U> CompletableFuture<Void> thenAcceptBoth
580 +                (CompletableFuture<T> f,
581 +                 CompletionStage<? extends U> g,
582 +                 BiConsumer<? super T,? super U> a) {
583 +                return f.thenAcceptBothAsync(g, a, new ThreadExecutor());
584 +            }
585 +            public <T,U,V> CompletableFuture<V> thenCombine
586 +                (CompletableFuture<T> f,
587 +                 CompletionStage<? extends U> g,
588 +                 BiFunction<? super T,? super U,? extends V> a) {
589 +                return f.thenCombineAsync(g, a, new ThreadExecutor());
590 +            }
591 +            public <T,U> CompletableFuture<U> applyToEither
592 +                (CompletableFuture<T> f,
593 +                 CompletionStage<? extends T> g,
594 +                 Function<? super T,U> a) {
595 +                return f.applyToEitherAsync(g, a, new ThreadExecutor());
596 +            }
597 +            public <T> CompletableFuture<Void> acceptEither
598 +                (CompletableFuture<T> f,
599 +                 CompletionStage<? extends T> g,
600 +                 Consumer<? super T> a) {
601 +                return f.acceptEitherAsync(g, a, new ThreadExecutor());
602 +            }
603 +            public <T> CompletableFuture<Void> runAfterEither
604 +                (CompletableFuture<T> f,
605 +                 CompletionStage<?> g,
606 +                 java.lang.Runnable a) {
607 +                return f.runAfterEitherAsync(g, a, new ThreadExecutor());
608 +            }
609 +            public <T,U> CompletableFuture<U> thenCompose
610 +                (CompletableFuture<T> f,
611 +                 Function<? super T,? extends CompletionStage<U>> a) {
612 +                return f.thenComposeAsync(a, new ThreadExecutor());
613 +            }
614 +            public <T> CompletableFuture<T> whenComplete
615 +                (CompletableFuture<T> f,
616 +                 BiConsumer<? super T,? super Throwable> a) {
617 +                return f.whenCompleteAsync(a, new ThreadExecutor());
618 +            }
619 +        };
620 +
621 +        public abstract <T,U> CompletableFuture<Void> runAfterBoth
622 +            (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a);
623 +        public abstract <T,U> CompletableFuture<Void> thenAcceptBoth
624 +            (CompletableFuture<T> f,
625 +             CompletionStage<? extends U> g,
626 +             BiConsumer<? super T,? super U> a);
627 +        public abstract <T,U,V> CompletableFuture<V> thenCombine
628 +            (CompletableFuture<T> f,
629 +             CompletionStage<? extends U> g,
630 +             BiFunction<? super T,? super U,? extends V> a);
631 +        public abstract <T,U> CompletableFuture<U> applyToEither
632 +            (CompletableFuture<T> f,
633 +             CompletionStage<? extends T> g,
634 +             Function<? super T,U> a);
635 +        public abstract <T> CompletableFuture<Void> acceptEither
636 +            (CompletableFuture<T> f,
637 +             CompletionStage<? extends T> g,
638 +             Consumer<? super T> a);
639 +        public abstract <T> CompletableFuture<Void> runAfterEither
640 +            (CompletableFuture<T> f,
641 +             CompletionStage<?> g,
642 +             java.lang.Runnable a);
643 +        public abstract <T,U> CompletableFuture<U> thenCompose
644 +            (CompletableFuture<T> f,
645 +             Function<? super T,? extends CompletionStage<U>> a);
646 +        public abstract <T> CompletableFuture<T> whenComplete
647 +            (CompletableFuture<T> f,
648 +             BiConsumer<? super T,? super Throwable> a);
649 +
650 +
651 +    }
652 +
653 +    /**
654       * exceptionally action completes with function value on source
655       * exception; otherwise with source value
656       */
# Line 623 | Line 900 | public class CompletableFutureTest exten
900          CompletableFuture<Void> g = f.thenAccept(r);
901          f.complete(one);
902          checkCompletedNormally(g, null);
903 <        assertEquals(r.value, 2);
903 >        assertEquals(r.value, (Integer) 2);
904      }
905  
906      /**
# Line 665 | Line 942 | public class CompletableFutureTest exten
942       * thenCombine result completes normally after normal completion
943       * of sources
944       */
945 <    public void testThenCombine() {
946 <        CompletableFuture<Integer> f, g, h;
945 >    public void testThenCombine_normalCompletion1() {
946 >        for (ExecutionMode m : ExecutionMode.values())
947 >        for (Integer v1 : new Integer[] { 1, null })
948 >        for (Integer v2 : new Integer[] { 2, null }) {
949 >
950 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
951 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
952 >        final SubtractFunction r = new SubtractFunction();
953 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
954 >
955 >        f.complete(v1);
956 >        checkIncomplete(h);
957 >        assertFalse(r.ran());
958 >        g.complete(v2);
959 >
960 >        checkCompletedNormally(h, subtract(v1, v2));
961 >        checkCompletedNormally(f, v1);
962 >        checkCompletedNormally(g, v2);
963 >        }
964 >    }
965  
966 <        f = new CompletableFuture<>();
967 <        g = new CompletableFuture<>();
968 <        h = f.thenCombine(g, subtract);
969 <        f.complete(3);
970 <        checkIncomplete(h);
971 <        g.complete(1);
972 <        checkCompletedNormally(h, 2);
966 >    public void testThenCombine_normalCompletion2() {
967 >        for (ExecutionMode m : ExecutionMode.values())
968 >        for (Integer v1 : new Integer[] { 1, null })
969 >        for (Integer v2 : new Integer[] { 2, null }) {
970 >
971 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
972 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
973 >        final SubtractFunction r = new SubtractFunction();
974 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
975 >
976 >        g.complete(v2);
977 >        checkIncomplete(h);
978 >        assertFalse(r.ran());
979 >        f.complete(v1);
980 >
981 >        checkCompletedNormally(h, subtract(v1, v2));
982 >        checkCompletedNormally(f, v1);
983 >        checkCompletedNormally(g, v2);
984 >        }
985 >    }
986  
987 <        f = new CompletableFuture<>();
988 <        g = new CompletableFuture<>();
989 <        h = f.thenCombine(g, subtract);
990 <        g.complete(1);
991 <        checkIncomplete(h);
992 <        f.complete(3);
993 <        checkCompletedNormally(h, 2);
987 >    public void testThenCombine_normalCompletion3() {
988 >        for (ExecutionMode m : ExecutionMode.values())
989 >        for (Integer v1 : new Integer[] { 1, null })
990 >        for (Integer v2 : new Integer[] { 2, null }) {
991 >
992 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
993 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
994 >        final SubtractFunction r = new SubtractFunction();
995 >
996 >        g.complete(v2);
997 >        f.complete(v1);
998 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
999 >
1000 >        checkCompletedNormally(h, subtract(v1, v2));
1001 >        checkCompletedNormally(f, v1);
1002 >        checkCompletedNormally(g, v2);
1003 >        }
1004 >    }
1005  
1006 <        f = new CompletableFuture<>();
1007 <        g = new CompletableFuture<>();
1008 <        g.complete(1);
1009 <        f.complete(3);
1010 <        h = f.thenCombine(g, subtract);
1011 <        checkCompletedNormally(h, 2);
1006 >    public void testThenCombine_normalCompletion4() {
1007 >        for (ExecutionMode m : ExecutionMode.values())
1008 >        for (Integer v1 : new Integer[] { 1, null })
1009 >        for (Integer v2 : new Integer[] { 2, null }) {
1010 >
1011 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1012 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1013 >        final SubtractFunction r = new SubtractFunction();
1014 >
1015 >        f.complete(v1);
1016 >        g.complete(v2);
1017 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1018 >
1019 >        checkCompletedNormally(h, subtract(v1, v2));
1020 >        checkCompletedNormally(f, v1);
1021 >        checkCompletedNormally(g, v2);
1022 >        }
1023      }
1024  
1025      /**
1026       * thenCombine result completes exceptionally after exceptional
1027       * completion of either source
1028       */
1029 <    public void testThenCombine2() {
1030 <        CompletableFuture<Integer> f, g, h;
1031 <
1032 <        f = new CompletableFuture<>();
1033 <        g = new CompletableFuture<>();
1034 <        h = f.thenCombine(g, subtract);
1035 <        f.completeExceptionally(new CFException());
1036 <        checkIncomplete(h);
1037 <        g.complete(1);
1038 <        checkCompletedWithWrappedCFException(h);
1029 >    public void testThenCombine_exceptionalCompletion1() {
1030 >        for (ExecutionMode m : ExecutionMode.values())
1031 >        for (Integer v1 : new Integer[] { 1, null }) {
1032 >
1033 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1034 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1035 >        final SubtractFunction r = new SubtractFunction();
1036 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1037 >        final CFException ex = new CFException();
1038 >
1039 >        f.completeExceptionally(ex);
1040 >        checkIncomplete(h);
1041 >        g.complete(v1);
1042 >
1043 >        checkCompletedWithWrappedCFException(h, ex);
1044 >        checkCompletedWithWrappedCFException(f, ex);
1045 >        assertFalse(r.ran());
1046 >        checkCompletedNormally(g, v1);
1047 >        }
1048 >    }
1049  
1050 <        f = new CompletableFuture<>();
1051 <        g = new CompletableFuture<>();
1052 <        h = f.thenCombine(g, subtract);
1053 <        g.completeExceptionally(new CFException());
1054 <        checkIncomplete(h);
1055 <        f.complete(3);
1056 <        checkCompletedWithWrappedCFException(h);
1050 >    public void testThenCombine_exceptionalCompletion2() {
1051 >        for (ExecutionMode m : ExecutionMode.values())
1052 >        for (Integer v1 : new Integer[] { 1, null }) {
1053 >
1054 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1055 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1056 >        final SubtractFunction r = new SubtractFunction();
1057 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1058 >        final CFException ex = new CFException();
1059 >
1060 >        g.completeExceptionally(ex);
1061 >        checkIncomplete(h);
1062 >        f.complete(v1);
1063 >
1064 >        checkCompletedWithWrappedCFException(h, ex);
1065 >        checkCompletedWithWrappedCFException(g, ex);
1066 >        assertFalse(r.ran());
1067 >        checkCompletedNormally(f, v1);
1068 >        }
1069 >    }
1070  
1071 <        f = new CompletableFuture<>();
1072 <        g = new CompletableFuture<>();
1073 <        f.complete(3);
1074 <        g.completeExceptionally(new CFException());
1075 <        h = f.thenCombine(g, subtract);
1076 <        checkCompletedWithWrappedCFException(h);
1071 >    public void testThenCombine_exceptionalCompletion3() {
1072 >        for (ExecutionMode m : ExecutionMode.values())
1073 >        for (Integer v1 : new Integer[] { 1, null }) {
1074 >
1075 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1076 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1077 >        final SubtractFunction r = new SubtractFunction();
1078 >        final CFException ex = new CFException();
1079 >
1080 >        g.completeExceptionally(ex);
1081 >        f.complete(v1);
1082 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1083 >
1084 >        checkCompletedWithWrappedCFException(h, ex);
1085 >        checkCompletedWithWrappedCFException(g, ex);
1086 >        assertFalse(r.ran());
1087 >        checkCompletedNormally(f, v1);
1088 >        }
1089 >    }
1090  
1091 <        f = new CompletableFuture<>();
1092 <        g = new CompletableFuture<>();
1093 <        f.completeExceptionally(new CFException());
1094 <        g.complete(3);
1095 <        h = f.thenCombine(g, subtract);
1096 <        checkCompletedWithWrappedCFException(h);
1091 >    public void testThenCombine_exceptionalCompletion4() {
1092 >        for (ExecutionMode m : ExecutionMode.values())
1093 >        for (Integer v1 : new Integer[] { 1, null }) {
1094 >
1095 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1096 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1097 >        final SubtractFunction r = new SubtractFunction();
1098 >        final CFException ex = new CFException();
1099 >
1100 >        f.completeExceptionally(ex);
1101 >        g.complete(v1);
1102 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1103 >
1104 >        checkCompletedWithWrappedCFException(h, ex);
1105 >        checkCompletedWithWrappedCFException(f, ex);
1106 >        assertFalse(r.ran());
1107 >        checkCompletedNormally(g, v1);
1108 >        }
1109      }
1110  
1111      /**
1112       * thenCombine result completes exceptionally if action does
1113       */
1114 <    public void testThenCombine3() {
1115 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1116 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1117 <        FailingBiFunction r = new FailingBiFunction();
1118 <        CompletableFuture<Integer> g = f.thenCombine(f2, r);
1119 <        f.complete(one);
1120 <        checkIncomplete(g);
1121 <        assertFalse(r.ran);
1122 <        f2.complete(two);
1123 <        checkCompletedWithWrappedCFException(g);
1124 <        assertTrue(r.ran);
1114 >    public void testThenCombine_actionFailed1() {
1115 >        for (ExecutionMode m : ExecutionMode.values())
1116 >        for (Integer v1 : new Integer[] { 1, null })
1117 >        for (Integer v2 : new Integer[] { 2, null }) {
1118 >
1119 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1120 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1121 >        final FailingBiFunction r = new FailingBiFunction();
1122 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1123 >
1124 >        f.complete(v1);
1125 >        checkIncomplete(h);
1126 >        g.complete(v2);
1127 >
1128 >        checkCompletedWithWrappedCFException(h);
1129 >        checkCompletedNormally(f, v1);
1130 >        checkCompletedNormally(g, v2);
1131 >        }
1132 >    }
1133 >
1134 >    public void testThenCombine_actionFailed2() {
1135 >        for (ExecutionMode m : ExecutionMode.values())
1136 >        for (Integer v1 : new Integer[] { 1, null })
1137 >        for (Integer v2 : new Integer[] { 2, null }) {
1138 >
1139 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1140 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1141 >        final FailingBiFunction r = new FailingBiFunction();
1142 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1143 >
1144 >        g.complete(v2);
1145 >        checkIncomplete(h);
1146 >        f.complete(v1);
1147 >
1148 >        checkCompletedWithWrappedCFException(h);
1149 >        checkCompletedNormally(f, v1);
1150 >        checkCompletedNormally(g, v2);
1151 >        }
1152      }
1153  
1154      /**
1155       * thenCombine result completes exceptionally if either source cancelled
1156       */
1157 <    public void testThenCombine4() {
1158 <        CompletableFuture<Integer> f, g, h;
1157 >    public void testThenCombine_sourceCancelled1() {
1158 >        for (ExecutionMode m : ExecutionMode.values())
1159 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1160 >        for (Integer v1 : new Integer[] { 1, null }) {
1161 >
1162 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1163 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1164 >        final SubtractFunction r = new SubtractFunction();
1165 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1166  
1167 <        f = new CompletableFuture<>();
756 <        g = new CompletableFuture<>();
757 <        h = f.thenCombine(g, subtract);
758 <        assertTrue(f.cancel(true));
1167 >        assertTrue(f.cancel(mayInterruptIfRunning));
1168          checkIncomplete(h);
1169 <        g.complete(1);
1169 >        g.complete(v1);
1170 >
1171          checkCompletedWithWrappedCancellationException(h);
1172 +        checkCancelled(f);
1173 +        assertFalse(r.ran());
1174 +        checkCompletedNormally(g, v1);
1175 +        }
1176 +    }
1177  
1178 <        f = new CompletableFuture<>();
1179 <        g = new CompletableFuture<>();
1180 <        h = f.thenCombine(g, subtract);
1181 <        assertTrue(g.cancel(true));
1178 >    public void testThenCombine_sourceCancelled2() {
1179 >        for (ExecutionMode m : ExecutionMode.values())
1180 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1181 >        for (Integer v1 : new Integer[] { 1, null }) {
1182 >
1183 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1184 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1185 >        final SubtractFunction r = new SubtractFunction();
1186 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1187 >
1188 >        assertTrue(g.cancel(mayInterruptIfRunning));
1189          checkIncomplete(h);
1190 <        f.complete(3);
1190 >        f.complete(v1);
1191 >
1192          checkCompletedWithWrappedCancellationException(h);
1193 +        checkCancelled(g);
1194 +        assertFalse(r.ran());
1195 +        checkCompletedNormally(f, v1);
1196 +        }
1197 +    }
1198 +
1199 +    public void testThenCombine_sourceCancelled3() {
1200 +        for (ExecutionMode m : ExecutionMode.values())
1201 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1202 +        for (Integer v1 : new Integer[] { 1, null }) {
1203 +
1204 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1205 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1206 +        final SubtractFunction r = new SubtractFunction();
1207 +
1208 +        assertTrue(g.cancel(mayInterruptIfRunning));
1209 +        f.complete(v1);
1210 +        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1211 +
1212 +        checkCompletedWithWrappedCancellationException(h);
1213 +        checkCancelled(g);
1214 +        assertFalse(r.ran());
1215 +        checkCompletedNormally(f, v1);
1216 +        }
1217 +    }
1218 +
1219 +    public void testThenCombine_sourceCancelled4() {
1220 +        for (ExecutionMode m : ExecutionMode.values())
1221 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1222 +        for (Integer v1 : new Integer[] { 1, null }) {
1223 +
1224 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1225 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1226 +        final SubtractFunction r = new SubtractFunction();
1227 +
1228 +        assertTrue(f.cancel(mayInterruptIfRunning));
1229 +        g.complete(v1);
1230 +        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1231  
771        f = new CompletableFuture<>();
772        g = new CompletableFuture<>();
773        assertTrue(f.cancel(true));
774        assertTrue(g.cancel(true));
775        h = f.thenCombine(g, subtract);
1232          checkCompletedWithWrappedCancellationException(h);
1233 +        checkCancelled(f);
1234 +        assertFalse(r.ran());
1235 +        checkCompletedNormally(g, v1);
1236 +        }
1237      }
1238  
1239      /**
1240       * thenAcceptBoth result completes normally after normal
1241       * completion of sources
1242       */
1243 <    public void testThenAcceptBoth() {
1244 <        CompletableFuture<Integer> f, g;
1245 <        CompletableFuture<Void> h;
1246 <        SubtractAction r;
1243 >    public void testThenAcceptBoth_normalCompletion1() {
1244 >        for (ExecutionMode m : ExecutionMode.values())
1245 >        for (Integer v1 : new Integer[] { 1, null })
1246 >        for (Integer v2 : new Integer[] { 2, null }) {
1247 >
1248 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1249 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1250 >        final SubtractAction r = new SubtractAction();
1251 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1252  
1253 <        f = new CompletableFuture<>();
789 <        g = new CompletableFuture<>();
790 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
791 <        f.complete(3);
1253 >        f.complete(v1);
1254          checkIncomplete(h);
1255 <        g.complete(1);
1255 >        assertFalse(r.ran());
1256 >        g.complete(v2);
1257 >
1258          checkCompletedNormally(h, null);
1259 <        assertEquals(r.value, 2);
1259 >        assertEquals(r.value, subtract(v1, v2));
1260 >        checkCompletedNormally(f, v1);
1261 >        checkCompletedNormally(g, v2);
1262 >        }
1263 >    }
1264  
1265 <        f = new CompletableFuture<>();
1266 <        g = new CompletableFuture<>();
1267 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
1268 <        g.complete(1);
1265 >    public void testThenAcceptBoth_normalCompletion2() {
1266 >        for (ExecutionMode m : ExecutionMode.values())
1267 >        for (Integer v1 : new Integer[] { 1, null })
1268 >        for (Integer v2 : new Integer[] { 2, null }) {
1269 >
1270 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1271 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1272 >        final SubtractAction r = new SubtractAction();
1273 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1274 >
1275 >        g.complete(v2);
1276          checkIncomplete(h);
1277 <        f.complete(3);
1277 >        assertFalse(r.ran());
1278 >        f.complete(v1);
1279 >
1280          checkCompletedNormally(h, null);
1281 <        assertEquals(r.value, 2);
1281 >        assertEquals(r.value, subtract(v1, v2));
1282 >        checkCompletedNormally(f, v1);
1283 >        checkCompletedNormally(g, v2);
1284 >        }
1285 >    }
1286 >
1287 >    public void testThenAcceptBoth_normalCompletion3() {
1288 >        for (ExecutionMode m : ExecutionMode.values())
1289 >        for (Integer v1 : new Integer[] { 1, null })
1290 >        for (Integer v2 : new Integer[] { 2, null }) {
1291 >
1292 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1293 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1294 >        final SubtractAction r = new SubtractAction();
1295 >
1296 >        g.complete(v2);
1297 >        f.complete(v1);
1298 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1299  
806        f = new CompletableFuture<>();
807        g = new CompletableFuture<>();
808        g.complete(1);
809        f.complete(3);
810        h = f.thenAcceptBoth(g, r = new SubtractAction());
1300          checkCompletedNormally(h, null);
1301 <        assertEquals(r.value, 2);
1301 >        assertEquals(r.value, subtract(v1, v2));
1302 >        checkCompletedNormally(f, v1);
1303 >        checkCompletedNormally(g, v2);
1304 >        }
1305 >    }
1306 >
1307 >    public void testThenAcceptBoth_normalCompletion4() {
1308 >        for (ExecutionMode m : ExecutionMode.values())
1309 >        for (Integer v1 : new Integer[] { 1, null })
1310 >        for (Integer v2 : new Integer[] { 2, null }) {
1311 >
1312 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1313 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1314 >        final SubtractAction r = new SubtractAction();
1315 >
1316 >        f.complete(v1);
1317 >        g.complete(v2);
1318 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1319 >
1320 >        checkCompletedNormally(h, null);
1321 >        assertEquals(r.value, subtract(v1, v2));
1322 >        checkCompletedNormally(f, v1);
1323 >        checkCompletedNormally(g, v2);
1324 >        }
1325      }
1326  
1327      /**
1328       * thenAcceptBoth result completes exceptionally after exceptional
1329       * completion of either source
1330       */
1331 <    public void testThenAcceptBoth2() {
1332 <        CompletableFuture<Integer> f, g;
1333 <        CompletableFuture<Void> h;
1334 <        SubtractAction r;
1335 <
1336 <        f = new CompletableFuture<>();
1337 <        g = new CompletableFuture<>();
1338 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
1339 <        f.completeExceptionally(new CFException());
1340 <        checkIncomplete(h);
1341 <        g.complete(1);
1342 <        checkCompletedWithWrappedCFException(h);
1331 >    public void testThenAcceptBoth_exceptionalCompletion1() {
1332 >        for (ExecutionMode m : ExecutionMode.values())
1333 >        for (Integer v1 : new Integer[] { 1, null }) {
1334 >
1335 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1336 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1337 >        final SubtractAction r = new SubtractAction();
1338 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1339 >        final CFException ex = new CFException();
1340 >
1341 >        f.completeExceptionally(ex);
1342 >        checkIncomplete(h);
1343 >        g.complete(v1);
1344 >
1345 >        checkCompletedWithWrappedCFException(h, ex);
1346 >        checkCompletedWithWrappedCFException(f, ex);
1347 >        assertFalse(r.ran());
1348 >        checkCompletedNormally(g, v1);
1349 >        }
1350 >    }
1351  
1352 <        f = new CompletableFuture<>();
1353 <        g = new CompletableFuture<>();
1354 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
1355 <        g.completeExceptionally(new CFException());
1356 <        checkIncomplete(h);
1357 <        f.complete(3);
1358 <        checkCompletedWithWrappedCFException(h);
1352 >    public void testThenAcceptBoth_exceptionalCompletion2() {
1353 >        for (ExecutionMode m : ExecutionMode.values())
1354 >        for (Integer v1 : new Integer[] { 1, null }) {
1355 >
1356 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1357 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1358 >        final SubtractAction r = new SubtractAction();
1359 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1360 >        final CFException ex = new CFException();
1361 >
1362 >        g.completeExceptionally(ex);
1363 >        checkIncomplete(h);
1364 >        f.complete(v1);
1365 >
1366 >        checkCompletedWithWrappedCFException(h, ex);
1367 >        checkCompletedWithWrappedCFException(g, ex);
1368 >        assertFalse(r.ran());
1369 >        checkCompletedNormally(f, v1);
1370 >        }
1371 >    }
1372  
1373 <        f = new CompletableFuture<>();
1374 <        g = new CompletableFuture<>();
1375 <        f.complete(3);
1376 <        g.completeExceptionally(new CFException());
1377 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
1378 <        checkCompletedWithWrappedCFException(h);
1373 >    public void testThenAcceptBoth_exceptionalCompletion3() {
1374 >        for (ExecutionMode m : ExecutionMode.values())
1375 >        for (Integer v1 : new Integer[] { 1, null }) {
1376 >
1377 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1378 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1379 >        final SubtractAction r = new SubtractAction();
1380 >        final CFException ex = new CFException();
1381 >
1382 >        g.completeExceptionally(ex);
1383 >        f.complete(v1);
1384 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1385 >
1386 >        checkCompletedWithWrappedCFException(h, ex);
1387 >        checkCompletedWithWrappedCFException(g, ex);
1388 >        assertFalse(r.ran());
1389 >        checkCompletedNormally(f, v1);
1390 >        }
1391 >    }
1392  
1393 <        f = new CompletableFuture<>();
1394 <        g = new CompletableFuture<>();
1395 <        f.completeExceptionally(new CFException());
1396 <        g.complete(3);
1397 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
1398 <        checkCompletedWithWrappedCFException(h);
1393 >    public void testThenAcceptBoth_exceptionalCompletion4() {
1394 >        for (ExecutionMode m : ExecutionMode.values())
1395 >        for (Integer v1 : new Integer[] { 1, null }) {
1396 >
1397 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1398 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1399 >        final SubtractAction r = new SubtractAction();
1400 >        final CFException ex = new CFException();
1401 >
1402 >        f.completeExceptionally(ex);
1403 >        g.complete(v1);
1404 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1405 >
1406 >        checkCompletedWithWrappedCFException(h, ex);
1407 >        checkCompletedWithWrappedCFException(f, ex);
1408 >        assertFalse(r.ran());
1409 >        checkCompletedNormally(g, v1);
1410 >        }
1411      }
1412  
1413      /**
1414       * thenAcceptBoth result completes exceptionally if action does
1415       */
1416 <    public void testThenAcceptBoth3() {
1417 <        CompletableFuture<Integer> f, g;
1418 <        CompletableFuture<Void> h;
1419 <        FailingBiConsumer r;
1416 >    public void testThenAcceptBoth_actionFailed1() {
1417 >        for (ExecutionMode m : ExecutionMode.values())
1418 >        for (Integer v1 : new Integer[] { 1, null })
1419 >        for (Integer v2 : new Integer[] { 2, null }) {
1420  
1421 <        f = new CompletableFuture<>();
1422 <        g = new CompletableFuture<>();
1423 <        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
1424 <        f.complete(3);
1421 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1422 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1423 >        final FailingBiConsumer r = new FailingBiConsumer();
1424 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1425 >
1426 >        f.complete(v1);
1427          checkIncomplete(h);
1428 <        g.complete(1);
1428 >        g.complete(v2);
1429 >
1430          checkCompletedWithWrappedCFException(h);
1431 +        checkCompletedNormally(f, v1);
1432 +        checkCompletedNormally(g, v2);
1433 +        }
1434 +    }
1435 +
1436 +    public void testThenAcceptBoth_actionFailed2() {
1437 +        for (ExecutionMode m : ExecutionMode.values())
1438 +        for (Integer v1 : new Integer[] { 1, null })
1439 +        for (Integer v2 : new Integer[] { 2, null }) {
1440 +
1441 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1442 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1443 +        final FailingBiConsumer r = new FailingBiConsumer();
1444 +        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1445 +
1446 +        g.complete(v2);
1447 +        checkIncomplete(h);
1448 +        f.complete(v1);
1449  
871        f = new CompletableFuture<>();
872        g = new CompletableFuture<>();
873        f.complete(3);
874        g.complete(1);
875        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
1450          checkCompletedWithWrappedCFException(h);
1451 +        checkCompletedNormally(f, v1);
1452 +        checkCompletedNormally(g, v2);
1453 +        }
1454      }
1455  
1456      /**
1457       * thenAcceptBoth result completes exceptionally if either source cancelled
1458       */
1459 <    public void testThenAcceptBoth4() {
1460 <        CompletableFuture<Integer> f, g;
1461 <        CompletableFuture<Void> h;
1462 <        SubtractAction r;
1459 >    public void testThenAcceptBoth_sourceCancelled1() {
1460 >        for (ExecutionMode m : ExecutionMode.values())
1461 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1462 >        for (Integer v1 : new Integer[] { 1, null }) {
1463 >
1464 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1465 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1466 >        final SubtractAction r = new SubtractAction();
1467 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1468  
1469 <        f = new CompletableFuture<>();
888 <        g = new CompletableFuture<>();
889 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
890 <        assertTrue(f.cancel(true));
1469 >        assertTrue(f.cancel(mayInterruptIfRunning));
1470          checkIncomplete(h);
1471 <        g.complete(1);
1471 >        g.complete(v1);
1472 >
1473          checkCompletedWithWrappedCancellationException(h);
1474 +        checkCancelled(f);
1475 +        assertFalse(r.ran());
1476 +        checkCompletedNormally(g, v1);
1477 +        }
1478 +    }
1479  
1480 <        f = new CompletableFuture<>();
1481 <        g = new CompletableFuture<>();
1482 <        h = f.thenAcceptBoth(g, r = new SubtractAction());
1483 <        assertTrue(g.cancel(true));
1480 >    public void testThenAcceptBoth_sourceCancelled2() {
1481 >        for (ExecutionMode m : ExecutionMode.values())
1482 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1483 >        for (Integer v1 : new Integer[] { 1, null }) {
1484 >
1485 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1486 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1487 >        final SubtractAction r = new SubtractAction();
1488 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1489 >
1490 >        assertTrue(g.cancel(mayInterruptIfRunning));
1491          checkIncomplete(h);
1492 <        f.complete(3);
901 <        checkCompletedWithWrappedCancellationException(h);
1492 >        f.complete(v1);
1493  
903        f = new CompletableFuture<>();
904        g = new CompletableFuture<>();
905        f.complete(3);
906        assertTrue(g.cancel(true));
907        h = f.thenAcceptBoth(g, r = new SubtractAction());
1494          checkCompletedWithWrappedCancellationException(h);
1495 +        checkCancelled(g);
1496 +        assertFalse(r.ran());
1497 +        checkCompletedNormally(f, v1);
1498 +        }
1499 +    }
1500 +
1501 +    public void testThenAcceptBoth_sourceCancelled3() {
1502 +        for (ExecutionMode m : ExecutionMode.values())
1503 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1504 +        for (Integer v1 : new Integer[] { 1, null }) {
1505 +
1506 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1507 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1508 +        final SubtractAction r = new SubtractAction();
1509 +
1510 +        assertTrue(g.cancel(mayInterruptIfRunning));
1511 +        f.complete(v1);
1512 +        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1513 +
1514 +        checkCompletedWithWrappedCancellationException(h);
1515 +        checkCancelled(g);
1516 +        assertFalse(r.ran());
1517 +        checkCompletedNormally(f, v1);
1518 +        }
1519 +    }
1520 +
1521 +    public void testThenAcceptBoth_sourceCancelled4() {
1522 +        for (ExecutionMode m : ExecutionMode.values())
1523 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1524 +        for (Integer v1 : new Integer[] { 1, null }) {
1525 +
1526 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1527 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1528 +        final SubtractAction r = new SubtractAction();
1529 +
1530 +        assertTrue(f.cancel(mayInterruptIfRunning));
1531 +        g.complete(v1);
1532 +        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1533  
910        f = new CompletableFuture<>();
911        g = new CompletableFuture<>();
912        assertTrue(f.cancel(true));
913        g.complete(3);
914        h = f.thenAcceptBoth(g, r = new SubtractAction());
1534          checkCompletedWithWrappedCancellationException(h);
1535 +        checkCancelled(f);
1536 +        assertFalse(r.ran());
1537 +        checkCompletedNormally(g, v1);
1538 +        }
1539      }
1540  
1541      /**
1542       * runAfterBoth result completes normally after normal
1543       * completion of sources
1544       */
1545 <    public void testRunAfterBoth() {
1546 <        CompletableFuture<Integer> f, g;
1547 <        CompletableFuture<Void> h;
1548 <        Noop r;
1545 >    public void testRunAfterBoth_normalCompletion1() {
1546 >        for (ExecutionMode m : ExecutionMode.values())
1547 >        for (Integer v1 : new Integer[] { 1, null })
1548 >        for (Integer v2 : new Integer[] { 2, null }) {
1549 >
1550 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1551 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1552 >        final Noop r = new Noop();
1553 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1554  
1555 <        f = new CompletableFuture<>();
928 <        g = new CompletableFuture<>();
929 <        h = f.runAfterBoth(g, r = new Noop());
930 <        f.complete(3);
1555 >        f.complete(v1);
1556          checkIncomplete(h);
1557 <        g.complete(1);
1557 >        assertFalse(r.ran);
1558 >        g.complete(v2);
1559 >
1560          checkCompletedNormally(h, null);
1561          assertTrue(r.ran);
1562 +        checkCompletedNormally(f, v1);
1563 +        checkCompletedNormally(g, v2);
1564 +        }
1565 +    }
1566  
1567 <        f = new CompletableFuture<>();
1568 <        g = new CompletableFuture<>();
1569 <        h = f.runAfterBoth(g, r = new Noop());
1570 <        g.complete(1);
1567 >    public void testRunAfterBoth_normalCompletion2() {
1568 >        for (ExecutionMode m : ExecutionMode.values())
1569 >        for (Integer v1 : new Integer[] { 1, null })
1570 >        for (Integer v2 : new Integer[] { 2, null }) {
1571 >
1572 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1573 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1574 >        final Noop r = new Noop();
1575 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1576 >
1577 >        g.complete(v2);
1578          checkIncomplete(h);
1579 <        f.complete(3);
1579 >        assertFalse(r.ran);
1580 >        f.complete(v1);
1581 >
1582          checkCompletedNormally(h, null);
1583          assertTrue(r.ran);
1584 +        checkCompletedNormally(f, v1);
1585 +        checkCompletedNormally(g, v2);
1586 +        }
1587 +    }
1588 +
1589 +    public void testRunAfterBoth_normalCompletion3() {
1590 +        for (ExecutionMode m : ExecutionMode.values())
1591 +        for (Integer v1 : new Integer[] { 1, null })
1592 +        for (Integer v2 : new Integer[] { 2, null }) {
1593 +
1594 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1595 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1596 +        final Noop r = new Noop();
1597 +
1598 +        g.complete(v2);
1599 +        f.complete(v1);
1600 +        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1601  
945        f = new CompletableFuture<>();
946        g = new CompletableFuture<>();
947        g.complete(1);
948        f.complete(3);
949        h = f.runAfterBoth(g, r = new Noop());
1602          checkCompletedNormally(h, null);
1603          assertTrue(r.ran);
1604 +        checkCompletedNormally(f, v1);
1605 +        checkCompletedNormally(g, v2);
1606 +        }
1607 +    }
1608 +
1609 +    public void testRunAfterBoth_normalCompletion4() {
1610 +        for (ExecutionMode m : ExecutionMode.values())
1611 +        for (Integer v1 : new Integer[] { 1, null })
1612 +        for (Integer v2 : new Integer[] { 2, null }) {
1613 +
1614 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1615 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1616 +        final Noop r = new Noop();
1617 +
1618 +        f.complete(v1);
1619 +        g.complete(v2);
1620 +        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1621 +
1622 +        checkCompletedNormally(h, null);
1623 +        assertTrue(r.ran);
1624 +        checkCompletedNormally(f, v1);
1625 +        checkCompletedNormally(g, v2);
1626 +        }
1627      }
1628  
1629      /**
1630       * runAfterBoth result completes exceptionally after exceptional
1631       * completion of either source
1632       */
1633 <    public void testRunAfterBoth2() {
1634 <        CompletableFuture<Integer> f, g;
1635 <        CompletableFuture<Void> h;
1636 <        Noop r;
1633 >    public void testRunAfterBoth_exceptionalCompletion1() {
1634 >        for (ExecutionMode m : ExecutionMode.values())
1635 >        for (Integer v1 : new Integer[] { 1, null }) {
1636 >
1637 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1638 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1639 >        final Noop r = new Noop();
1640 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1641 >        final CFException ex = new CFException();
1642  
1643 <        f = new CompletableFuture<>();
964 <        g = new CompletableFuture<>();
965 <        h = f.runAfterBoth(g, r = new Noop());
966 <        f.completeExceptionally(new CFException());
1643 >        f.completeExceptionally(ex);
1644          checkIncomplete(h);
1645 <        g.complete(1);
1646 <        checkCompletedWithWrappedCFException(h);
1645 >        g.complete(v1);
1646 >
1647 >        checkCompletedWithWrappedCFException(h, ex);
1648 >        checkCompletedWithWrappedCFException(f, ex);
1649          assertFalse(r.ran);
1650 +        checkCompletedNormally(g, v1);
1651 +        }
1652 +    }
1653  
1654 <        f = new CompletableFuture<>();
1655 <        g = new CompletableFuture<>();
1656 <        h = f.runAfterBoth(g, r = new Noop());
1657 <        g.completeExceptionally(new CFException());
1654 >    public void testRunAfterBoth_exceptionalCompletion2() {
1655 >        for (ExecutionMode m : ExecutionMode.values())
1656 >        for (Integer v1 : new Integer[] { 1, null }) {
1657 >
1658 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1659 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1660 >        final Noop r = new Noop();
1661 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1662 >        final CFException ex = new CFException();
1663 >
1664 >        g.completeExceptionally(ex);
1665          checkIncomplete(h);
1666 <        f.complete(3);
1667 <        checkCompletedWithWrappedCFException(h);
1666 >        f.complete(v1);
1667 >
1668 >        checkCompletedWithWrappedCFException(h, ex);
1669 >        checkCompletedWithWrappedCFException(g, ex);
1670          assertFalse(r.ran);
1671 +        checkCompletedNormally(f, v1);
1672 +        }
1673 +    }
1674  
1675 <        f = new CompletableFuture<>();
1676 <        g = new CompletableFuture<>();
1677 <        g.completeExceptionally(new CFException());
1678 <        f.complete(3);
1679 <        h = f.runAfterBoth(g, r = new Noop());
1680 <        checkCompletedWithWrappedCFException(h);
1675 >    public void testRunAfterBoth_exceptionalCompletion3() {
1676 >        for (ExecutionMode m : ExecutionMode.values())
1677 >        for (Integer v1 : new Integer[] { 1, null }) {
1678 >
1679 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1680 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1681 >        final Noop r = new Noop();
1682 >        final CFException ex = new CFException();
1683 >
1684 >        g.completeExceptionally(ex);
1685 >        f.complete(v1);
1686 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1687 >
1688 >        checkCompletedWithWrappedCFException(h, ex);
1689 >        checkCompletedWithWrappedCFException(g, ex);
1690          assertFalse(r.ran);
1691 +        checkCompletedNormally(f, v1);
1692 +        }
1693 +    }
1694  
1695 <        f = new CompletableFuture<>();
1696 <        g = new CompletableFuture<>();
1697 <        f.completeExceptionally(new CFException());
1698 <        g.complete(1);
1699 <        h = f.runAfterBoth(g, r = new Noop());
1700 <        checkCompletedWithWrappedCFException(h);
1695 >    public void testRunAfterBoth_exceptionalCompletion4() {
1696 >        for (ExecutionMode m : ExecutionMode.values())
1697 >        for (Integer v1 : new Integer[] { 1, null }) {
1698 >
1699 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1700 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1701 >        final Noop r = new Noop();
1702 >        final CFException ex = new CFException();
1703 >
1704 >        f.completeExceptionally(ex);
1705 >        g.complete(v1);
1706 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1707 >
1708 >        checkCompletedWithWrappedCFException(h, ex);
1709 >        checkCompletedWithWrappedCFException(f, ex);
1710          assertFalse(r.ran);
1711 +        checkCompletedNormally(g, v1);
1712 +        }
1713      }
1714  
1715      /**
1716       * runAfterBoth result completes exceptionally if action does
1717       */
1718 <    public void testRunAfterBoth3() {
1719 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1720 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1721 <        FailingNoop r = new FailingNoop();
1722 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1723 <        f.complete(one);
1724 <        checkIncomplete(g);
1725 <        f2.complete(two);
1726 <        checkCompletedWithWrappedCFException(g);
1718 >    public void testRunAfterBoth_actionFailed1() {
1719 >        for (ExecutionMode m : ExecutionMode.values())
1720 >        for (Integer v1 : new Integer[] { 1, null })
1721 >        for (Integer v2 : new Integer[] { 2, null }) {
1722 >
1723 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1724 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1725 >        final FailingNoop r = new FailingNoop();
1726 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1727 >
1728 >        f.complete(v1);
1729 >        checkIncomplete(h);
1730 >        g.complete(v2);
1731 >
1732 >        checkCompletedWithWrappedCFException(h);
1733 >        checkCompletedNormally(f, v1);
1734 >        checkCompletedNormally(g, v2);
1735 >        }
1736 >    }
1737 >
1738 >    public void testRunAfterBoth_actionFailed2() {
1739 >        for (ExecutionMode m : ExecutionMode.values())
1740 >        for (Integer v1 : new Integer[] { 1, null })
1741 >        for (Integer v2 : new Integer[] { 2, null }) {
1742 >
1743 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1744 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1745 >        final FailingNoop r = new FailingNoop();
1746 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1747 >
1748 >        g.complete(v2);
1749 >        checkIncomplete(h);
1750 >        f.complete(v1);
1751 >
1752 >        checkCompletedWithWrappedCFException(h);
1753 >        checkCompletedNormally(f, v1);
1754 >        checkCompletedNormally(g, v2);
1755 >        }
1756      }
1757  
1758      /**
1759       * runAfterBoth result completes exceptionally if either source cancelled
1760       */
1761 <    public void testRunAfterBoth4() {
1762 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1763 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1764 <        Noop r = new Noop();
1765 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1766 <        assertTrue(f.cancel(true));
1767 <        f2.complete(two);
1768 <        checkCompletedWithWrappedCancellationException(g);
1769 <        f = new CompletableFuture<>();
1770 <        f2 = new CompletableFuture<>();
1771 <        r = new Noop();
1772 <        g = f.runAfterBoth(f2, r);
1773 <        f.complete(one);
1774 <        assertTrue(f2.cancel(true));
1775 <        checkCompletedWithWrappedCancellationException(g);
1761 >    public void testRunAfterBoth_sourceCancelled1() {
1762 >        for (ExecutionMode m : ExecutionMode.values())
1763 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1764 >        for (Integer v1 : new Integer[] { 1, null }) {
1765 >
1766 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1767 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1768 >        final Noop r = new Noop();
1769 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1770 >
1771 >        assertTrue(f.cancel(mayInterruptIfRunning));
1772 >        checkIncomplete(h);
1773 >        g.complete(v1);
1774 >
1775 >        checkCompletedWithWrappedCancellationException(h);
1776 >        checkCancelled(f);
1777 >        assertFalse(r.ran);
1778 >        checkCompletedNormally(g, v1);
1779 >        }
1780 >    }
1781 >
1782 >    public void testRunAfterBoth_sourceCancelled2() {
1783 >        for (ExecutionMode m : ExecutionMode.values())
1784 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1785 >        for (Integer v1 : new Integer[] { 1, null }) {
1786 >
1787 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1788 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1789 >        final Noop r = new Noop();
1790 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1791 >
1792 >        assertTrue(g.cancel(mayInterruptIfRunning));
1793 >        checkIncomplete(h);
1794 >        f.complete(v1);
1795 >
1796 >        checkCompletedWithWrappedCancellationException(h);
1797 >        checkCancelled(g);
1798 >        assertFalse(r.ran);
1799 >        checkCompletedNormally(f, v1);
1800 >        }
1801 >    }
1802 >
1803 >    public void testRunAfterBoth_sourceCancelled3() {
1804 >        for (ExecutionMode m : ExecutionMode.values())
1805 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1806 >        for (Integer v1 : new Integer[] { 1, null }) {
1807 >
1808 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1809 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1810 >        final Noop r = new Noop();
1811 >
1812 >        assertTrue(g.cancel(mayInterruptIfRunning));
1813 >        f.complete(v1);
1814 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1815 >
1816 >        checkCompletedWithWrappedCancellationException(h);
1817 >        checkCancelled(g);
1818 >        assertFalse(r.ran);
1819 >        checkCompletedNormally(f, v1);
1820 >        }
1821 >    }
1822 >
1823 >    public void testRunAfterBoth_sourceCancelled4() {
1824 >        for (ExecutionMode m : ExecutionMode.values())
1825 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1826 >        for (Integer v1 : new Integer[] { 1, null }) {
1827 >
1828 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1829 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1830 >        final Noop r = new Noop();
1831 >
1832 >        assertTrue(f.cancel(mayInterruptIfRunning));
1833 >        g.complete(v1);
1834 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1835 >
1836 >        checkCompletedWithWrappedCancellationException(h);
1837 >        checkCancelled(f);
1838 >        assertFalse(r.ran);
1839 >        checkCompletedNormally(g, v1);
1840 >        }
1841      }
1842  
1843      /**
1844       * applyToEither result completes normally after normal completion
1845       * of either source
1846       */
1847 <    public void testApplyToEither() {
1848 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1849 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1850 <        CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1851 <        f.complete(one);
1852 <        checkCompletedNormally(g, two);
1853 <        f2.complete(one);
1854 <        checkCompletedNormally(g, two);
1847 >    public void testApplyToEither_normalCompletion1() {
1848 >        for (ExecutionMode m : ExecutionMode.values())
1849 >        for (Integer v1 : new Integer[] { 1, null })
1850 >        for (Integer v2 : new Integer[] { 2, null }) {
1851 >
1852 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1853 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1854 >        final IncFunction r = new IncFunction();
1855 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1856 >
1857 >        f.complete(v1);
1858 >        checkCompletedNormally(h, inc(v1));
1859 >        g.complete(v2);
1860 >
1861 >        checkCompletedNormally(f, v1);
1862 >        checkCompletedNormally(g, v2);
1863 >        checkCompletedNormally(h, inc(v1));
1864 >        }
1865 >    }
1866  
1867 <        f = new CompletableFuture<>();
1868 <        f.complete(one);
1869 <        f2 = new CompletableFuture<>();
1870 <        g = f.applyToEither(f2, inc);
1871 <        checkCompletedNormally(g, two);
1867 >    public void testApplyToEither_normalCompletion2() {
1868 >        for (ExecutionMode m : ExecutionMode.values())
1869 >        for (Integer v1 : new Integer[] { 1, null })
1870 >        for (Integer v2 : new Integer[] { 2, null }) {
1871 >
1872 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1873 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1874 >        final IncFunction r = new IncFunction();
1875 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1876 >
1877 >        g.complete(v2);
1878 >        checkCompletedNormally(h, inc(v2));
1879 >        f.complete(v1);
1880 >
1881 >        checkCompletedNormally(f, v1);
1882 >        checkCompletedNormally(g, v2);
1883 >        checkCompletedNormally(h, inc(v2));
1884 >        }
1885 >    }
1886 >    public void testApplyToEither_normalCompletion3() {
1887 >        for (ExecutionMode m : ExecutionMode.values())
1888 >        for (Integer v1 : new Integer[] { 1, null })
1889 >        for (Integer v2 : new Integer[] { 2, null }) {
1890 >
1891 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1892 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1893 >        final IncFunction r = new IncFunction();
1894 >
1895 >        f.complete(v1);
1896 >        g.complete(v2);
1897 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1898 >
1899 >        checkCompletedNormally(f, v1);
1900 >        checkCompletedNormally(g, v2);
1901 >
1902 >        // unspecified behavior
1903 >        assertTrue(Objects.equals(h.join(), inc(v1)) ||
1904 >                   Objects.equals(h.join(), inc(v2)));
1905 >        }
1906      }
1907  
1908      /**
1909       * applyToEither result completes exceptionally after exceptional
1910       * completion of either source
1911       */
1912 <    public void testApplyToEither2() {
1913 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1914 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1915 <        CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1916 <        f.completeExceptionally(new CFException());
1917 <        f2.complete(one);
1918 <        checkCompletedWithWrappedCFException(g);
1912 >    public void testApplyToEither_exceptionalCompletion1() {
1913 >        for (ExecutionMode m : ExecutionMode.values())
1914 >        for (Integer v1 : new Integer[] { 1, null }) {
1915 >
1916 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1917 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1918 >        final IncFunction r = new IncFunction();
1919 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1920 >        final CFException ex = new CFException();
1921 >
1922 >        f.completeExceptionally(ex);
1923 >        checkCompletedWithWrappedCFException(h, ex);
1924 >        g.complete(v1);
1925 >
1926 >        assertFalse(r.ran());
1927 >        checkCompletedNormally(g, v1);
1928 >        checkCompletedWithWrappedCFException(f, ex);
1929 >        checkCompletedWithWrappedCFException(h, ex);
1930 >        }
1931 >    }
1932  
1933 <        f = new CompletableFuture<>();
1934 <        f2 = new CompletableFuture<>();
1935 <        f2.completeExceptionally(new CFException());
1936 <        g = f.applyToEither(f2, inc);
1937 <        checkCompletedWithWrappedCFException(g);
1933 >    public void testApplyToEither_exceptionalCompletion2() {
1934 >        for (ExecutionMode m : ExecutionMode.values())
1935 >        for (Integer v1 : new Integer[] { 1, null }) {
1936 >
1937 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1938 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1939 >        final IncFunction r = new IncFunction();
1940 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1941 >        final CFException ex = new CFException();
1942 >
1943 >        g.completeExceptionally(ex);
1944 >        checkCompletedWithWrappedCFException(h, ex);
1945 >        f.complete(v1);
1946 >
1947 >        assertFalse(r.ran());
1948 >        checkCompletedNormally(f, v1);
1949 >        checkCompletedWithWrappedCFException(g, ex);
1950 >        checkCompletedWithWrappedCFException(h, ex);
1951 >        }
1952 >    }
1953 >
1954 >    public void testApplyToEither_exceptionalCompletion3() {
1955 >        for (ExecutionMode m : ExecutionMode.values())
1956 >        for (Integer v1 : new Integer[] { 1, null }) {
1957 >
1958 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1959 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1960 >        final IncFunction r = new IncFunction();
1961 >        final CFException ex = new CFException();
1962 >
1963 >        g.completeExceptionally(ex);
1964 >        f.complete(v1);
1965 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1966 >
1967 >        // unspecified behavior
1968 >        Integer v;
1969 >        try {
1970 >            assertEquals(h.join(), inc(v1));
1971 >            assertTrue(r.ran());
1972 >        } catch (CompletionException ok) {
1973 >            checkCompletedWithWrappedCFException(h, ex);
1974 >            assertFalse(r.ran());
1975 >        }
1976 >
1977 >        checkCompletedWithWrappedCFException(g, ex);
1978 >        checkCompletedNormally(f, v1);
1979 >        }
1980 >    }
1981 >
1982 >    public void testApplyToEither_exceptionalCompletion4() {
1983 >        for (ExecutionMode m : ExecutionMode.values())
1984 >        for (Integer v1 : new Integer[] { 1, null }) {
1985 >
1986 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1987 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1988 >        final IncFunction r = new IncFunction();
1989 >        final CFException ex = new CFException();
1990 >
1991 >        f.completeExceptionally(ex);
1992 >        g.complete(v1);
1993 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1994 >
1995 >        // unspecified behavior
1996 >        Integer v;
1997 >        try {
1998 >            assertEquals(h.join(), inc(v1));
1999 >            assertTrue(r.ran());
2000 >        } catch (CompletionException ok) {
2001 >            checkCompletedWithWrappedCFException(h, ex);
2002 >            assertFalse(r.ran());
2003 >        }
2004 >
2005 >        checkCompletedWithWrappedCFException(f, ex);
2006 >        assertFalse(r.ran());
2007 >        checkCompletedNormally(g, v1);
2008 >        }
2009      }
2010  
2011      /**
2012       * applyToEither result completes exceptionally if action does
2013       */
2014 <    public void testApplyToEither3() {
2015 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2016 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2017 <        FailingFunction r = new FailingFunction();
2018 <        CompletableFuture<Integer> g = f.applyToEither(f2, r);
2019 <        f2.complete(two);
2020 <        checkCompletedWithWrappedCFException(g);
2014 >    public void testApplyToEither_actionFailed1() {
2015 >        for (ExecutionMode m : ExecutionMode.values())
2016 >        for (Integer v1 : new Integer[] { 1, null })
2017 >        for (Integer v2 : new Integer[] { 2, null }) {
2018 >
2019 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2020 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2021 >        final FailingFunction r = new FailingFunction();
2022 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2023 >
2024 >        f.complete(v1);
2025 >        checkCompletedWithWrappedCFException(h);
2026 >        g.complete(v2);
2027 >        checkCompletedNormally(f, v1);
2028 >        checkCompletedNormally(g, v2);
2029 >        }
2030 >    }
2031 >
2032 >    public void testApplyToEither_actionFailed2() {
2033 >        for (ExecutionMode m : ExecutionMode.values())
2034 >        for (Integer v1 : new Integer[] { 1, null })
2035 >        for (Integer v2 : new Integer[] { 2, null }) {
2036 >
2037 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2038 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2039 >        final FailingFunction r = new FailingFunction();
2040 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2041 >
2042 >        g.complete(v2);
2043 >        checkCompletedWithWrappedCFException(h);
2044 >        f.complete(v1);
2045 >        checkCompletedNormally(f, v1);
2046 >        checkCompletedNormally(g, v2);
2047 >        }
2048      }
2049  
2050      /**
2051       * applyToEither result completes exceptionally if either source cancelled
2052       */
2053 <    public void testApplyToEither4() {
2054 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2055 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2056 <        CompletableFuture<Integer> g = f.applyToEither(f2, inc);
2057 <        assertTrue(f.cancel(true));
2058 <        checkCompletedWithWrappedCancellationException(g);
2059 <        f = new CompletableFuture<>();
2060 <        f2 = new CompletableFuture<>();
2061 <        assertTrue(f2.cancel(true));
2062 <        checkCompletedWithWrappedCancellationException(g);
2053 >    public void testApplyToEither_sourceCancelled1() {
2054 >        for (ExecutionMode m : ExecutionMode.values())
2055 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2056 >        for (Integer v1 : new Integer[] { 1, null }) {
2057 >
2058 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2059 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2060 >        final IncFunction r = new IncFunction();
2061 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2062 >
2063 >        assertTrue(f.cancel(mayInterruptIfRunning));
2064 >        checkCompletedWithWrappedCancellationException(h);
2065 >        g.complete(v1);
2066 >
2067 >        checkCancelled(f);
2068 >        assertFalse(r.ran());
2069 >        checkCompletedNormally(g, v1);
2070 >        checkCompletedWithWrappedCancellationException(h);
2071 >        }
2072 >    }
2073 >
2074 >    public void testApplyToEither_sourceCancelled2() {
2075 >        for (ExecutionMode m : ExecutionMode.values())
2076 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2077 >        for (Integer v1 : new Integer[] { 1, null }) {
2078 >
2079 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2080 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2081 >        final IncFunction r = new IncFunction();
2082 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2083 >
2084 >        assertTrue(g.cancel(mayInterruptIfRunning));
2085 >        checkCompletedWithWrappedCancellationException(h);
2086 >        f.complete(v1);
2087 >
2088 >        checkCancelled(g);
2089 >        assertFalse(r.ran());
2090 >        checkCompletedNormally(f, v1);
2091 >        checkCompletedWithWrappedCancellationException(h);
2092 >        }
2093 >    }
2094 >
2095 >    public void testApplyToEither_sourceCancelled3() {
2096 >        for (ExecutionMode m : ExecutionMode.values())
2097 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2098 >        for (Integer v1 : new Integer[] { 1, null }) {
2099 >
2100 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2101 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2102 >        final IncFunction r = new IncFunction();
2103 >
2104 >        assertTrue(g.cancel(mayInterruptIfRunning));
2105 >        f.complete(v1);
2106 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2107 >
2108 >        // unspecified behavior
2109 >        Integer v;
2110 >        try {
2111 >            assertEquals(h.join(), inc(v1));
2112 >            assertTrue(r.ran());
2113 >        } catch (CompletionException ok) {
2114 >            checkCompletedWithWrappedCancellationException(h);
2115 >            assertFalse(r.ran());
2116 >        }
2117 >
2118 >        checkCancelled(g);
2119 >        checkCompletedNormally(f, v1);
2120 >        }
2121 >    }
2122 >
2123 >    public void testApplyToEither_sourceCancelled4() {
2124 >        for (ExecutionMode m : ExecutionMode.values())
2125 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2126 >        for (Integer v1 : new Integer[] { 1, null }) {
2127 >
2128 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2129 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2130 >        final IncFunction r = new IncFunction();
2131 >
2132 >        assertTrue(f.cancel(mayInterruptIfRunning));
2133 >        g.complete(v1);
2134 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2135 >
2136 >        // unspecified behavior
2137 >        Integer v;
2138 >        try {
2139 >            assertEquals(h.join(), inc(v1));
2140 >            assertTrue(r.ran());
2141 >        } catch (CompletionException ok) {
2142 >            checkCompletedWithWrappedCancellationException(h);
2143 >            assertFalse(r.ran());
2144 >        }
2145 >
2146 >        checkCancelled(f);
2147 >        checkCompletedNormally(g, v1);
2148 >        }
2149      }
2150  
2151      /**
2152       * acceptEither result completes normally after normal completion
2153       * of either source
2154       */
2155 <    public void testAcceptEither() {
2156 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2157 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2158 <        IncAction r = new IncAction();
2159 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2160 <        f.complete(one);
2161 <        checkCompletedNormally(g, null);
2162 <        f2.complete(one);
2163 <        checkCompletedNormally(g, null);
1111 <        assertEquals(r.value, 2);
2155 >    public void testAcceptEither_normalCompletion1() {
2156 >        for (ExecutionMode m : ExecutionMode.values())
2157 >        for (Integer v1 : new Integer[] { 1, null })
2158 >        for (Integer v2 : new Integer[] { 2, null }) {
2159 >
2160 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2161 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2162 >        final IncAction r = new IncAction();
2163 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2164  
2165 <        r = new IncAction();
2166 <        f = new CompletableFuture<>();
2167 <        f.complete(one);
2168 <        f2 = new CompletableFuture<>();
2169 <        g = f.acceptEither(f2, r);
2170 <        checkCompletedNormally(g, null);
2171 <        assertEquals(r.value, 2);
2165 >        f.complete(v1);
2166 >        checkCompletedNormally(h, null);
2167 >        assertEquals(r.value, inc(v1));
2168 >        g.complete(v2);
2169 >
2170 >        checkCompletedNormally(f, v1);
2171 >        checkCompletedNormally(g, v2);
2172 >        checkCompletedNormally(h, null);
2173 >        }
2174 >    }
2175 >
2176 >    public void testAcceptEither_normalCompletion2() {
2177 >        for (ExecutionMode m : ExecutionMode.values())
2178 >        for (Integer v1 : new Integer[] { 1, null })
2179 >        for (Integer v2 : new Integer[] { 2, null }) {
2180 >
2181 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2182 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2183 >        final IncAction r = new IncAction();
2184 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2185 >
2186 >        g.complete(v2);
2187 >        checkCompletedNormally(h, null);
2188 >        assertEquals(r.value, inc(v2));
2189 >        f.complete(v1);
2190 >
2191 >        checkCompletedNormally(f, v1);
2192 >        checkCompletedNormally(g, v2);
2193 >        checkCompletedNormally(h, null);
2194 >        }
2195 >    }
2196 >    public void testAcceptEither_normalCompletion3() {
2197 >        for (ExecutionMode m : ExecutionMode.values())
2198 >        for (Integer v1 : new Integer[] { 1, null })
2199 >        for (Integer v2 : new Integer[] { 2, null }) {
2200 >
2201 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2202 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2203 >        final IncAction r = new IncAction();
2204 >
2205 >        f.complete(v1);
2206 >        g.complete(v2);
2207 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2208 >
2209 >        checkCompletedNormally(h, null);
2210 >        checkCompletedNormally(f, v1);
2211 >        checkCompletedNormally(g, v2);
2212 >
2213 >        // unspecified behavior
2214 >        assertTrue(Objects.equals(r.value, inc(v1)) ||
2215 >                   Objects.equals(r.value, inc(v2)));
2216 >        }
2217      }
2218  
2219      /**
2220       * acceptEither result completes exceptionally after exceptional
2221       * completion of either source
2222       */
2223 <    public void testAcceptEither2() {
2224 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2225 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2226 <        IncAction r = new IncAction();
2227 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2228 <        f.completeExceptionally(new CFException());
2229 <        f2.complete(one);
2230 <        checkCompletedWithWrappedCFException(g);
2223 >    public void testAcceptEither_exceptionalCompletion1() {
2224 >        for (ExecutionMode m : ExecutionMode.values())
2225 >        for (Integer v1 : new Integer[] { 1, null }) {
2226 >
2227 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2228 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2229 >        final IncAction r = new IncAction();
2230 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2231 >        final CFException ex = new CFException();
2232 >
2233 >        f.completeExceptionally(ex);
2234 >        checkCompletedWithWrappedCFException(h, ex);
2235 >        g.complete(v1);
2236 >
2237 >        assertFalse(r.ran());
2238 >        checkCompletedNormally(g, v1);
2239 >        checkCompletedWithWrappedCFException(f, ex);
2240 >        checkCompletedWithWrappedCFException(h, ex);
2241 >        }
2242 >    }
2243  
2244 <        r = new IncAction();
2245 <        f = new CompletableFuture<>();
2246 <        f2 = new CompletableFuture<>();
2247 <        f2.completeExceptionally(new CFException());
2248 <        g = f.acceptEither(f2, r);
2249 <        checkCompletedWithWrappedCFException(g);
2244 >    public void testAcceptEither_exceptionalCompletion2() {
2245 >        for (ExecutionMode m : ExecutionMode.values())
2246 >        for (Integer v1 : new Integer[] { 1, null }) {
2247 >
2248 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2249 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2250 >        final IncAction r = new IncAction();
2251 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2252 >        final CFException ex = new CFException();
2253 >
2254 >        g.completeExceptionally(ex);
2255 >        checkCompletedWithWrappedCFException(h, ex);
2256 >        f.complete(v1);
2257 >
2258 >        assertFalse(r.ran());
2259 >        checkCompletedNormally(f, v1);
2260 >        checkCompletedWithWrappedCFException(g, ex);
2261 >        checkCompletedWithWrappedCFException(h, ex);
2262 >        }
2263 >    }
2264 >
2265 >    public void testAcceptEither_exceptionalCompletion3() {
2266 >        for (ExecutionMode m : ExecutionMode.values())
2267 >        for (Integer v1 : new Integer[] { 1, null }) {
2268 >
2269 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2270 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2271 >        final IncAction r = new IncAction();
2272 >        final CFException ex = new CFException();
2273 >
2274 >        g.completeExceptionally(ex);
2275 >        f.complete(v1);
2276 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2277 >
2278 >        // unspecified behavior
2279 >        Integer v;
2280 >        try {
2281 >            assertEquals(h.join(), null);
2282 >            assertTrue(r.ran());
2283 >            assertEquals(inc(v1), r.value);
2284 >        } catch (CompletionException ok) {
2285 >            checkCompletedWithWrappedCFException(h, ex);
2286 >            assertFalse(r.ran());
2287 >        }
2288 >
2289 >        checkCompletedWithWrappedCFException(g, ex);
2290 >        checkCompletedNormally(f, v1);
2291 >        }
2292 >    }
2293 >
2294 >    public void testAcceptEither_exceptionalCompletion4() {
2295 >        for (ExecutionMode m : ExecutionMode.values())
2296 >        for (Integer v1 : new Integer[] { 1, null }) {
2297 >
2298 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2299 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2300 >        final IncAction r = new IncAction();
2301 >        final CFException ex = new CFException();
2302 >
2303 >        f.completeExceptionally(ex);
2304 >        g.complete(v1);
2305 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2306 >
2307 >        // unspecified behavior
2308 >        Integer v;
2309 >        try {
2310 >            assertEquals(h.join(), null);
2311 >            assertTrue(r.ran());
2312 >            assertEquals(inc(v1), r.value);
2313 >        } catch (CompletionException ok) {
2314 >            checkCompletedWithWrappedCFException(h, ex);
2315 >            assertFalse(r.ran());
2316 >        }
2317 >
2318 >        checkCompletedWithWrappedCFException(f, ex);
2319 >        assertFalse(r.ran());
2320 >        checkCompletedNormally(g, v1);
2321 >        }
2322      }
2323  
2324      /**
2325       * acceptEither result completes exceptionally if action does
2326       */
2327 <    public void testAcceptEither3() {
2328 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2329 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2330 <        FailingConsumer r = new FailingConsumer();
2331 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2332 <        f2.complete(two);
2333 <        checkCompletedWithWrappedCFException(g);
2327 >    public void testAcceptEither_actionFailed1() {
2328 >        for (ExecutionMode m : ExecutionMode.values())
2329 >        for (Integer v1 : new Integer[] { 1, null })
2330 >        for (Integer v2 : new Integer[] { 2, null }) {
2331 >
2332 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2333 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2334 >        final FailingConsumer r = new FailingConsumer();
2335 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2336 >
2337 >        f.complete(v1);
2338 >        checkCompletedWithWrappedCFException(h);
2339 >        g.complete(v2);
2340 >        checkCompletedNormally(f, v1);
2341 >        checkCompletedNormally(g, v2);
2342 >        }
2343 >    }
2344 >
2345 >    public void testAcceptEither_actionFailed2() {
2346 >        for (ExecutionMode m : ExecutionMode.values())
2347 >        for (Integer v1 : new Integer[] { 1, null })
2348 >        for (Integer v2 : new Integer[] { 2, null }) {
2349 >
2350 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2351 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2352 >        final FailingConsumer r = new FailingConsumer();
2353 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2354 >
2355 >        g.complete(v2);
2356 >        checkCompletedWithWrappedCFException(h);
2357 >        f.complete(v1);
2358 >        checkCompletedNormally(f, v1);
2359 >        checkCompletedNormally(g, v2);
2360 >        }
2361      }
2362  
2363      /**
2364       * acceptEither result completes exceptionally if either source cancelled
2365       */
2366 <    public void testAcceptEither4() {
2367 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2368 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2369 <        IncAction r = new IncAction();
2370 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2371 <        assertTrue(f.cancel(true));
2372 <        checkCompletedWithWrappedCancellationException(g);
2373 <        f = new CompletableFuture<>();
2374 <        f2 = new CompletableFuture<>();
2375 <        assertTrue(f2.cancel(true));
2376 <        checkCompletedWithWrappedCancellationException(g);
2366 >    public void testAcceptEither_sourceCancelled1() {
2367 >        for (ExecutionMode m : ExecutionMode.values())
2368 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2369 >        for (Integer v1 : new Integer[] { 1, null }) {
2370 >
2371 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2372 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2373 >        final IncAction r = new IncAction();
2374 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2375 >
2376 >        assertTrue(f.cancel(mayInterruptIfRunning));
2377 >        checkCompletedWithWrappedCancellationException(h);
2378 >        g.complete(v1);
2379 >
2380 >        checkCancelled(f);
2381 >        assertFalse(r.ran());
2382 >        checkCompletedNormally(g, v1);
2383 >        checkCompletedWithWrappedCancellationException(h);
2384 >        }
2385 >    }
2386 >
2387 >    public void testAcceptEither_sourceCancelled2() {
2388 >        for (ExecutionMode m : ExecutionMode.values())
2389 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2390 >        for (Integer v1 : new Integer[] { 1, null }) {
2391 >
2392 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2393 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2394 >        final IncAction r = new IncAction();
2395 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2396 >
2397 >        assertTrue(g.cancel(mayInterruptIfRunning));
2398 >        checkCompletedWithWrappedCancellationException(h);
2399 >        f.complete(v1);
2400 >
2401 >        checkCancelled(g);
2402 >        assertFalse(r.ran());
2403 >        checkCompletedNormally(f, v1);
2404 >        checkCompletedWithWrappedCancellationException(h);
2405 >        }
2406 >    }
2407 >
2408 >    public void testAcceptEither_sourceCancelled3() {
2409 >        for (ExecutionMode m : ExecutionMode.values())
2410 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2411 >        for (Integer v1 : new Integer[] { 1, null }) {
2412 >
2413 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2414 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2415 >        final IncAction r = new IncAction();
2416 >
2417 >        assertTrue(g.cancel(mayInterruptIfRunning));
2418 >        f.complete(v1);
2419 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2420 >
2421 >        // unspecified behavior
2422 >        Integer v;
2423 >        try {
2424 >            assertEquals(h.join(), null);
2425 >            assertTrue(r.ran());
2426 >            assertEquals(inc(v1), r.value);
2427 >        } catch (CompletionException ok) {
2428 >            checkCompletedWithWrappedCancellationException(h);
2429 >            assertFalse(r.ran());
2430 >        }
2431 >
2432 >        checkCancelled(g);
2433 >        checkCompletedNormally(f, v1);
2434 >        }
2435 >    }
2436 >
2437 >    public void testAcceptEither_sourceCancelled4() {
2438 >        for (ExecutionMode m : ExecutionMode.values())
2439 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2440 >        for (Integer v1 : new Integer[] { 1, null }) {
2441 >
2442 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2443 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2444 >        final IncAction r = new IncAction();
2445 >
2446 >        assertTrue(f.cancel(mayInterruptIfRunning));
2447 >        g.complete(v1);
2448 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2449 >
2450 >        // unspecified behavior
2451 >        Integer v;
2452 >        try {
2453 >            assertEquals(h.join(), null);
2454 >            assertTrue(r.ran());
2455 >            assertEquals(inc(v1), r.value);
2456 >        } catch (CompletionException ok) {
2457 >            checkCompletedWithWrappedCancellationException(h);
2458 >            assertFalse(r.ran());
2459 >        }
2460 >
2461 >        checkCancelled(f);
2462 >        checkCompletedNormally(g, v1);
2463 >        }
2464      }
2465  
2466      /**
# Line 1426 | Line 2721 | public class CompletableFutureTest exten
2721          CompletableFuture<Void> g = f.thenAcceptAsync(r);
2722          f.complete(one);
2723          checkCompletedNormally(g, null);
2724 <        assertEquals(r.value, 2);
2724 >        assertEquals(r.value, (Integer) 2);
2725      }
2726  
2727      /**
# Line 1464 | Line 2759 | public class CompletableFutureTest exten
2759      }
2760  
2761      /**
1467     * thenCombineAsync result completes normally after normal
1468     * completion of sources
1469     */
1470    public void testThenCombineAsync() {
1471        CompletableFuture<Integer> f, g, h;
1472
1473        f = new CompletableFuture<>();
1474        g = new CompletableFuture<>();
1475        h = f.thenCombineAsync(g, subtract);
1476        f.complete(3);
1477        checkIncomplete(h);
1478        g.complete(1);
1479        checkCompletedNormally(h, 2);
1480
1481        f = new CompletableFuture<>();
1482        g = new CompletableFuture<>();
1483        h = f.thenCombineAsync(g, subtract);
1484        g.complete(1);
1485        checkIncomplete(h);
1486        f.complete(3);
1487        checkCompletedNormally(h, 2);
1488
1489        f = new CompletableFuture<>();
1490        g = new CompletableFuture<>();
1491        g.complete(1);
1492        f.complete(3);
1493        h = f.thenCombineAsync(g, subtract);
1494        checkCompletedNormally(h, 2);
1495    }
1496
1497    /**
1498     * thenCombineAsync result completes exceptionally after exceptional
1499     * completion of either source
1500     */
1501    public void testThenCombineAsync2() {
1502        CompletableFuture<Integer> f, g, h;
1503
1504        f = new CompletableFuture<>();
1505        g = new CompletableFuture<>();
1506        h = f.thenCombineAsync(g, subtract);
1507        f.completeExceptionally(new CFException());
1508        checkIncomplete(h);
1509        g.complete(1);
1510        checkCompletedWithWrappedCFException(h);
1511
1512        f = new CompletableFuture<>();
1513        g = new CompletableFuture<>();
1514        h = f.thenCombineAsync(g, subtract);
1515        g.completeExceptionally(new CFException());
1516        checkIncomplete(h);
1517        f.complete(3);
1518        checkCompletedWithWrappedCFException(h);
1519
1520        f = new CompletableFuture<>();
1521        g = new CompletableFuture<>();
1522        g.completeExceptionally(new CFException());
1523        f.complete(3);
1524        h = f.thenCombineAsync(g, subtract);
1525        checkCompletedWithWrappedCFException(h);
1526    }
1527
1528    /**
1529     * thenCombineAsync result completes exceptionally if action does
1530     */
1531    public void testThenCombineAsync3() {
1532        CompletableFuture<Integer> f = new CompletableFuture<>();
1533        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1534        FailingBiFunction r = new FailingBiFunction();
1535        CompletableFuture<Integer> g = f.thenCombineAsync(f2, r);
1536        f.complete(one);
1537        checkIncomplete(g);
1538        assertFalse(r.ran);
1539        f2.complete(two);
1540        checkCompletedWithWrappedCFException(g);
1541        assertTrue(r.ran);
1542    }
1543
1544    /**
1545     * thenCombineAsync result completes exceptionally if either source cancelled
1546     */
1547    public void testThenCombineAsync4() {
1548        CompletableFuture<Integer> f, g, h;
1549
1550        f = new CompletableFuture<>();
1551        g = new CompletableFuture<>();
1552        h = f.thenCombineAsync(g, subtract);
1553        assertTrue(f.cancel(true));
1554        checkIncomplete(h);
1555        g.complete(1);
1556        checkCompletedWithWrappedCancellationException(h);
1557
1558        f = new CompletableFuture<>();
1559        g = new CompletableFuture<>();
1560        h = f.thenCombineAsync(g, subtract);
1561        assertTrue(g.cancel(true));
1562        checkIncomplete(h);
1563        f.complete(3);
1564        checkCompletedWithWrappedCancellationException(h);
1565
1566        f = new CompletableFuture<>();
1567        g = new CompletableFuture<>();
1568        g.complete(3);
1569        assertTrue(f.cancel(true));
1570        h = f.thenCombineAsync(g, subtract);
1571        checkCompletedWithWrappedCancellationException(h);
1572
1573        f = new CompletableFuture<>();
1574        g = new CompletableFuture<>();
1575        f.complete(3);
1576        assertTrue(g.cancel(true));
1577        h = f.thenCombineAsync(g, subtract);
1578        checkCompletedWithWrappedCancellationException(h);
1579    }
1580
1581    /**
1582     * thenAcceptBothAsync result completes normally after normal
1583     * completion of sources
1584     */
1585    public void testThenAcceptBothAsync() {
1586        CompletableFuture<Integer> f, g;
1587        CompletableFuture<Void> h;
1588        SubtractAction r;
1589
1590        f = new CompletableFuture<>();
1591        g = new CompletableFuture<>();
1592        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1593        f.complete(3);
1594        checkIncomplete(h);
1595        g.complete(1);
1596        checkCompletedNormally(h, null);
1597        assertEquals(r.value, 2);
1598
1599        f = new CompletableFuture<>();
1600        g = new CompletableFuture<>();
1601        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1602        g.complete(1);
1603        checkIncomplete(h);
1604        f.complete(3);
1605        checkCompletedNormally(h, null);
1606        assertEquals(r.value, 2);
1607
1608        f = new CompletableFuture<>();
1609        g = new CompletableFuture<>();
1610        g.complete(1);
1611        f.complete(3);
1612        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1613        checkCompletedNormally(h, null);
1614        assertEquals(r.value, 2);
1615    }
1616
1617    /**
1618     * thenAcceptBothAsync result completes exceptionally after exceptional
1619     * completion of source
1620     */
1621    public void testThenAcceptBothAsync2() {
1622        CompletableFuture<Integer> f, g;
1623        CompletableFuture<Void> h;
1624        SubtractAction r;
1625
1626        f = new CompletableFuture<>();
1627        g = new CompletableFuture<>();
1628        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1629        f.completeExceptionally(new CFException());
1630        checkIncomplete(h);
1631        g.complete(1);
1632        checkCompletedWithWrappedCFException(h);
1633
1634        f = new CompletableFuture<>();
1635        g = new CompletableFuture<>();
1636        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1637        g.completeExceptionally(new CFException());
1638        checkIncomplete(h);
1639        f.complete(3);
1640        checkCompletedWithWrappedCFException(h);
1641
1642        f = new CompletableFuture<>();
1643        g = new CompletableFuture<>();
1644        f.complete(3);
1645        g.completeExceptionally(new CFException());
1646        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1647        checkCompletedWithWrappedCFException(h);
1648
1649        f = new CompletableFuture<>();
1650        g = new CompletableFuture<>();
1651        f.completeExceptionally(new CFException());
1652        g.complete(3);
1653        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1654        checkCompletedWithWrappedCFException(h);
1655    }
1656
1657    /**
1658     * thenAcceptBothAsync result completes exceptionally if action does
1659     */
1660    public void testThenAcceptBothAsync3() {
1661        CompletableFuture<Integer> f, g;
1662        CompletableFuture<Void> h;
1663        FailingBiConsumer r;
1664
1665        f = new CompletableFuture<>();
1666        g = new CompletableFuture<>();
1667        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1668        f.complete(3);
1669        checkIncomplete(h);
1670        g.complete(1);
1671        checkCompletedWithWrappedCFException(h);
1672
1673        f = new CompletableFuture<>();
1674        g = new CompletableFuture<>();
1675        f.complete(3);
1676        g.complete(1);
1677        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1678        checkCompletedWithWrappedCFException(h);
1679    }
1680
1681    /**
1682     * thenAcceptBothAsync result completes exceptionally if either source cancelled
1683     */
1684    public void testThenAcceptBothAsync4() {
1685        CompletableFuture<Integer> f, g;
1686        CompletableFuture<Void> h;
1687        SubtractAction r;
1688
1689        f = new CompletableFuture<>();
1690        g = new CompletableFuture<>();
1691        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1692        assertTrue(f.cancel(true));
1693        checkIncomplete(h);
1694        g.complete(1);
1695        checkCompletedWithWrappedCancellationException(h);
1696
1697        f = new CompletableFuture<>();
1698        g = new CompletableFuture<>();
1699        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1700        assertTrue(g.cancel(true));
1701        checkIncomplete(h);
1702        f.complete(3);
1703        checkCompletedWithWrappedCancellationException(h);
1704
1705        f = new CompletableFuture<>();
1706        g = new CompletableFuture<>();
1707        f.complete(3);
1708        assertTrue(g.cancel(true));
1709        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1710        checkCompletedWithWrappedCancellationException(h);
1711
1712        f = new CompletableFuture<>();
1713        g = new CompletableFuture<>();
1714        assertTrue(f.cancel(true));
1715        g.complete(3);
1716        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1717        checkCompletedWithWrappedCancellationException(h);
1718    }
1719
1720    /**
1721     * runAfterBothAsync result completes normally after normal
1722     * completion of sources
1723     */
1724    public void testRunAfterBothAsync() {
1725        CompletableFuture<Integer> f = new CompletableFuture<>();
1726        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1727        Noop r = new Noop();
1728        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1729        f.complete(one);
1730        checkIncomplete(g);
1731        f2.complete(two);
1732        checkCompletedNormally(g, null);
1733        assertTrue(r.ran);
1734    }
1735
1736    /**
1737     * runAfterBothAsync result completes exceptionally after exceptional
1738     * completion of source
1739     */
1740    public void testRunAfterBothAsync2() {
1741        CompletableFuture<Integer> f = new CompletableFuture<>();
1742        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1743        Noop r = new Noop();
1744        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1745        f.completeExceptionally(new CFException());
1746        f2.complete(two);
1747        checkCompletedWithWrappedCFException(g);
1748
1749        r = new Noop();
1750        f = new CompletableFuture<>();
1751        f2 = new CompletableFuture<>();
1752        g = f.runAfterBothAsync(f2, r);
1753        f.complete(one);
1754        f2.completeExceptionally(new CFException());
1755        checkCompletedWithWrappedCFException(g);
1756    }
1757
1758    /**
1759     * runAfterBothAsync result completes exceptionally if action does
1760     */
1761    public void testRunAfterBothAsync3() {
1762        CompletableFuture<Integer> f = new CompletableFuture<>();
1763        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1764        FailingNoop r = new FailingNoop();
1765        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1766        f.complete(one);
1767        checkIncomplete(g);
1768        f2.complete(two);
1769        checkCompletedWithWrappedCFException(g);
1770    }
1771
1772    /**
1773     * runAfterBothAsync result completes exceptionally if either source cancelled
1774     */
1775    public void testRunAfterBothAsync4() {
1776        CompletableFuture<Integer> f = new CompletableFuture<>();
1777        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1778        Noop r = new Noop();
1779        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1780        assertTrue(f.cancel(true));
1781        f2.complete(two);
1782        checkCompletedWithWrappedCancellationException(g);
1783
1784        r = new Noop();
1785        f = new CompletableFuture<>();
1786        f2 = new CompletableFuture<>();
1787        g = f.runAfterBothAsync(f2, r);
1788        f.complete(one);
1789        assertTrue(f2.cancel(true));
1790        checkCompletedWithWrappedCancellationException(g);
1791    }
1792
1793    /**
1794     * applyToEitherAsync result completes normally after normal
1795     * completion of sources
1796     */
1797    public void testApplyToEitherAsync() {
1798        CompletableFuture<Integer> f = new CompletableFuture<>();
1799        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1800        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1801        f.complete(one);
1802        checkCompletedNormally(g, two);
1803
1804        f = new CompletableFuture<>();
1805        f.complete(one);
1806        f2 = new CompletableFuture<>();
1807        g = f.applyToEitherAsync(f2, inc);
1808        checkCompletedNormally(g, two);
1809    }
1810
1811    /**
1812     * applyToEitherAsync result completes exceptionally after exceptional
1813     * completion of source
1814     */
1815    public void testApplyToEitherAsync2() {
1816        CompletableFuture<Integer> f = new CompletableFuture<>();
1817        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1818        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1819        f.completeExceptionally(new CFException());
1820        checkCompletedWithWrappedCFException(g);
1821
1822        f = new CompletableFuture<>();
1823        f2 = new CompletableFuture<>();
1824        f2.completeExceptionally(new CFException());
1825        g = f.applyToEitherAsync(f2, inc);
1826        f.complete(one);
1827        checkCompletedWithWrappedCFException(g);
1828    }
1829
1830    /**
1831     * applyToEitherAsync result completes exceptionally if action does
1832     */
1833    public void testApplyToEitherAsync3() {
1834        CompletableFuture<Integer> f = new CompletableFuture<>();
1835        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1836        FailingFunction r = new FailingFunction();
1837        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
1838        f.complete(one);
1839        checkCompletedWithWrappedCFException(g);
1840    }
1841
1842    /**
1843     * applyToEitherAsync result completes exceptionally if either source cancelled
1844     */
1845    public void testApplyToEitherAsync4() {
1846        CompletableFuture<Integer> f = new CompletableFuture<>();
1847        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1848        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1849        assertTrue(f.cancel(true));
1850        checkCompletedWithWrappedCancellationException(g);
1851
1852        f = new CompletableFuture<>();
1853        f2 = new CompletableFuture<>();
1854        assertTrue(f2.cancel(true));
1855        g = f.applyToEitherAsync(f2, inc);
1856        checkCompletedWithWrappedCancellationException(g);
1857    }
1858
1859    /**
1860     * acceptEitherAsync result completes normally after normal
1861     * completion of sources
1862     */
1863    public void testAcceptEitherAsync() {
1864        CompletableFuture<Integer> f = new CompletableFuture<>();
1865        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1866        IncAction r = new IncAction();
1867        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1868        f.complete(one);
1869        checkCompletedNormally(g, null);
1870        assertEquals(r.value, 2);
1871
1872        r = new IncAction();
1873        f = new CompletableFuture<>();
1874        f.complete(one);
1875        f2 = new CompletableFuture<>();
1876        g = f.acceptEitherAsync(f2, r);
1877        checkCompletedNormally(g, null);
1878        assertEquals(r.value, 2);
1879    }
1880
1881    /**
1882     * acceptEitherAsync result completes exceptionally after exceptional
1883     * completion of source
1884     */
1885    public void testAcceptEitherAsync2() {
1886        CompletableFuture<Integer> f = new CompletableFuture<>();
1887        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1888        IncAction r = new IncAction();
1889        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1890        f.completeExceptionally(new CFException());
1891        checkCompletedWithWrappedCFException(g);
1892
1893        r = new IncAction();
1894        f = new CompletableFuture<>();
1895        f2 = new CompletableFuture<>();
1896        f2.completeExceptionally(new CFException());
1897        g = f.acceptEitherAsync(f2, r);
1898        f.complete(one);
1899        checkCompletedWithWrappedCFException(g);
1900    }
1901
1902    /**
1903     * acceptEitherAsync result completes exceptionally if action does
1904     */
1905    public void testAcceptEitherAsync3() {
1906        CompletableFuture<Integer> f = new CompletableFuture<>();
1907        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1908        FailingConsumer r = new FailingConsumer();
1909        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1910        f.complete(one);
1911        checkCompletedWithWrappedCFException(g);
1912    }
1913
1914    /**
1915     * acceptEitherAsync result completes exceptionally if either
1916     * source cancelled
1917     */
1918    public void testAcceptEitherAsync4() {
1919        CompletableFuture<Integer> f = new CompletableFuture<>();
1920        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1921        IncAction r = new IncAction();
1922        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1923        assertTrue(f.cancel(true));
1924        checkCompletedWithWrappedCancellationException(g);
1925
1926        r = new IncAction();
1927        f = new CompletableFuture<>();
1928        f2 = new CompletableFuture<>();
1929        assertTrue(f2.cancel(true));
1930        g = f.acceptEitherAsync(f2, r);
1931        checkCompletedWithWrappedCancellationException(g);
1932    }
1933
1934    /**
2762       * runAfterEitherAsync result completes normally after normal
2763       * completion of sources
2764       */
# Line 2192 | Line 3019 | public class CompletableFutureTest exten
3019          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3020          f.complete(one);
3021          checkCompletedNormally(g, null);
3022 <        assertEquals(r.value, 2);
3022 >        assertEquals(r.value, (Integer) 2);
3023      }
3024  
3025      /**
# Line 2230 | Line 3057 | public class CompletableFutureTest exten
3057      }
3058  
3059      /**
2233     * thenCombineAsync result completes normally after normal
2234     * completion of sources
2235     */
2236    public void testThenCombineAsyncE() {
2237        CompletableFuture<Integer> f, g, h;
2238        ThreadExecutor e = new ThreadExecutor();
2239        int count = 0;
2240
2241        f = new CompletableFuture<>();
2242        g = new CompletableFuture<>();
2243        h = f.thenCombineAsync(g, subtract, e);
2244        f.complete(3);
2245        checkIncomplete(h);
2246        g.complete(1);
2247        checkCompletedNormally(h, 2);
2248        assertEquals(++count, e.count.get());
2249
2250        f = new CompletableFuture<>();
2251        g = new CompletableFuture<>();
2252        h = f.thenCombineAsync(g, subtract, e);
2253        g.complete(1);
2254        checkIncomplete(h);
2255        f.complete(3);
2256        checkCompletedNormally(h, 2);
2257        assertEquals(++count, e.count.get());
2258
2259        f = new CompletableFuture<>();
2260        g = new CompletableFuture<>();
2261        g.complete(1);
2262        f.complete(3);
2263        h = f.thenCombineAsync(g, subtract, e);
2264        checkCompletedNormally(h, 2);
2265        assertEquals(++count, e.count.get());
2266    }
2267
2268    /**
2269     * thenCombineAsync result completes exceptionally after exceptional
2270     * completion of either source
2271     */
2272    public void testThenCombineAsync2E() {
2273        CompletableFuture<Integer> f, g, h;
2274        ThreadExecutor e = new ThreadExecutor();
2275        int count = 0;
2276
2277        f = new CompletableFuture<>();
2278        g = new CompletableFuture<>();
2279        h = f.thenCombineAsync(g, subtract, e);
2280        f.completeExceptionally(new CFException());
2281        checkIncomplete(h);
2282        g.complete(1);
2283        checkCompletedWithWrappedCFException(h);
2284
2285        f = new CompletableFuture<>();
2286        g = new CompletableFuture<>();
2287        h = f.thenCombineAsync(g, subtract, e);
2288        g.completeExceptionally(new CFException());
2289        checkIncomplete(h);
2290        f.complete(3);
2291        checkCompletedWithWrappedCFException(h);
2292
2293        f = new CompletableFuture<>();
2294        g = new CompletableFuture<>();
2295        g.completeExceptionally(new CFException());
2296        h = f.thenCombineAsync(g, subtract, e);
2297        checkIncomplete(h);
2298        f.complete(3);
2299        checkCompletedWithWrappedCFException(h);
2300
2301        assertEquals(0, e.count.get());
2302    }
2303
2304    /**
2305     * thenCombineAsync result completes exceptionally if action does
2306     */
2307    public void testThenCombineAsync3E() {
2308        CompletableFuture<Integer> f = new CompletableFuture<>();
2309        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2310        FailingBiFunction r = new FailingBiFunction();
2311        CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor());
2312        f.complete(one);
2313        checkIncomplete(g);
2314        assertFalse(r.ran);
2315        f2.complete(two);
2316        checkCompletedWithWrappedCFException(g);
2317        assertTrue(r.ran);
2318    }
2319
2320    /**
2321     * thenCombineAsync result completes exceptionally if either source cancelled
2322     */
2323    public void testThenCombineAsync4E() {
2324        CompletableFuture<Integer> f, g, h;
2325        ThreadExecutor e = new ThreadExecutor();
2326
2327        f = new CompletableFuture<>();
2328        g = new CompletableFuture<>();
2329        h = f.thenCombineAsync(g, subtract, e);
2330        assertTrue(f.cancel(true));
2331        checkIncomplete(h);
2332        g.complete(1);
2333        checkCompletedWithWrappedCancellationException(h);
2334
2335        f = new CompletableFuture<>();
2336        g = new CompletableFuture<>();
2337        h = f.thenCombineAsync(g, subtract, e);
2338        assertTrue(g.cancel(true));
2339        checkIncomplete(h);
2340        f.complete(3);
2341        checkCompletedWithWrappedCancellationException(h);
2342
2343        f = new CompletableFuture<>();
2344        g = new CompletableFuture<>();
2345        assertTrue(g.cancel(true));
2346        h = f.thenCombineAsync(g, subtract, e);
2347        checkIncomplete(h);
2348        f.complete(3);
2349        checkCompletedWithWrappedCancellationException(h);
2350
2351        f = new CompletableFuture<>();
2352        g = new CompletableFuture<>();
2353        assertTrue(f.cancel(true));
2354        assertTrue(g.cancel(true));
2355        h = f.thenCombineAsync(g, subtract, e);
2356        checkCompletedWithWrappedCancellationException(h);
2357
2358        assertEquals(0, e.count.get());
2359    }
2360
2361    /**
2362     * thenAcceptBothAsync result completes normally after normal
2363     * completion of sources
2364     */
2365    public void testThenAcceptBothAsyncE() {
2366        CompletableFuture<Integer> f, g;
2367        CompletableFuture<Void> h;
2368        SubtractAction r;
2369        ThreadExecutor e = new ThreadExecutor();
2370
2371        f = new CompletableFuture<>();
2372        g = new CompletableFuture<>();
2373        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2374        f.complete(3);
2375        checkIncomplete(h);
2376        g.complete(1);
2377        checkCompletedNormally(h, null);
2378        assertEquals(r.value, 2);
2379
2380        f = new CompletableFuture<>();
2381        g = new CompletableFuture<>();
2382        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2383        g.complete(1);
2384        checkIncomplete(h);
2385        f.complete(3);
2386        checkCompletedNormally(h, null);
2387        assertEquals(r.value, 2);
2388
2389        f = new CompletableFuture<>();
2390        g = new CompletableFuture<>();
2391        g.complete(1);
2392        f.complete(3);
2393        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2394        checkCompletedNormally(h, null);
2395        assertEquals(r.value, 2);
2396
2397        assertEquals(3, e.count.get());
2398    }
2399
2400    /**
2401     * thenAcceptBothAsync result completes exceptionally after exceptional
2402     * completion of source
2403     */
2404    public void testThenAcceptBothAsync2E() {
2405        CompletableFuture<Integer> f, g;
2406        CompletableFuture<Void> h;
2407        SubtractAction r;
2408        ThreadExecutor e = new ThreadExecutor();
2409
2410        f = new CompletableFuture<>();
2411        g = new CompletableFuture<>();
2412        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2413        f.completeExceptionally(new CFException());
2414        checkIncomplete(h);
2415        g.complete(1);
2416        checkCompletedWithWrappedCFException(h);
2417
2418        f = new CompletableFuture<>();
2419        g = new CompletableFuture<>();
2420        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2421        g.completeExceptionally(new CFException());
2422        checkIncomplete(h);
2423        f.complete(3);
2424        checkCompletedWithWrappedCFException(h);
2425
2426        f = new CompletableFuture<>();
2427        g = new CompletableFuture<>();
2428        f.complete(3);
2429        g.completeExceptionally(new CFException());
2430        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2431        checkCompletedWithWrappedCFException(h);
2432
2433        f = new CompletableFuture<>();
2434        g = new CompletableFuture<>();
2435        f.completeExceptionally(new CFException());
2436        g.complete(3);
2437        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2438        checkCompletedWithWrappedCFException(h);
2439
2440        assertEquals(0, e.count.get());
2441    }
2442
2443    /**
2444     * thenAcceptBothAsync result completes exceptionally if action does
2445     */
2446    public void testThenAcceptBothAsync3E() {
2447        CompletableFuture<Integer> f, g;
2448        CompletableFuture<Void> h;
2449        FailingBiConsumer r;
2450        ThreadExecutor e = new ThreadExecutor();
2451
2452        f = new CompletableFuture<>();
2453        g = new CompletableFuture<>();
2454        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2455        f.complete(3);
2456        checkIncomplete(h);
2457        g.complete(1);
2458        checkCompletedWithWrappedCFException(h);
2459
2460        f = new CompletableFuture<>();
2461        g = new CompletableFuture<>();
2462        f.complete(3);
2463        g.complete(1);
2464        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2465        checkCompletedWithWrappedCFException(h);
2466
2467        assertEquals(2, e.count.get());
2468    }
2469
2470    /**
2471     * thenAcceptBothAsync result completes exceptionally if either source cancelled
2472     */
2473    public void testThenAcceptBothAsync4E() {
2474        CompletableFuture<Integer> f, g;
2475        CompletableFuture<Void> h;
2476        SubtractAction r;
2477        ThreadExecutor e = new ThreadExecutor();
2478
2479        f = new CompletableFuture<>();
2480        g = new CompletableFuture<>();
2481        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2482        assertTrue(f.cancel(true));
2483        checkIncomplete(h);
2484        g.complete(1);
2485        checkCompletedWithWrappedCancellationException(h);
2486
2487        f = new CompletableFuture<>();
2488        g = new CompletableFuture<>();
2489        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2490        assertTrue(g.cancel(true));
2491        checkIncomplete(h);
2492        f.complete(3);
2493        checkCompletedWithWrappedCancellationException(h);
2494
2495        f = new CompletableFuture<>();
2496        g = new CompletableFuture<>();
2497        f.complete(3);
2498        assertTrue(g.cancel(true));
2499        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2500        checkCompletedWithWrappedCancellationException(h);
2501
2502        f = new CompletableFuture<>();
2503        g = new CompletableFuture<>();
2504        assertTrue(f.cancel(true));
2505        g.complete(3);
2506        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2507        checkCompletedWithWrappedCancellationException(h);
2508
2509        assertEquals(0, e.count.get());
2510    }
2511
2512    /**
2513     * runAfterBothAsync result completes normally after normal
2514     * completion of sources
2515     */
2516    public void testRunAfterBothAsyncE() {
2517        CompletableFuture<Integer> f = new CompletableFuture<>();
2518        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2519        Noop r = new Noop();
2520        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2521        f.complete(one);
2522        checkIncomplete(g);
2523        f2.complete(two);
2524        checkCompletedNormally(g, null);
2525        assertTrue(r.ran);
2526    }
2527
2528    /**
2529     * runAfterBothAsync result completes exceptionally after exceptional
2530     * completion of source
2531     */
2532    public void testRunAfterBothAsync2E() {
2533        CompletableFuture<Integer> f = new CompletableFuture<>();
2534        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2535        Noop r = new Noop();
2536        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2537        f.completeExceptionally(new CFException());
2538        f2.complete(two);
2539        checkCompletedWithWrappedCFException(g);
2540
2541        r = new Noop();
2542        f = new CompletableFuture<>();
2543        f2 = new CompletableFuture<>();
2544        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2545        f.complete(one);
2546        f2.completeExceptionally(new CFException());
2547        checkCompletedWithWrappedCFException(g);
2548    }
2549
2550    /**
2551     * runAfterBothAsync result completes exceptionally if action does
2552     */
2553    public void testRunAfterBothAsync3E() {
2554        CompletableFuture<Integer> f = new CompletableFuture<>();
2555        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2556        FailingNoop r = new FailingNoop();
2557        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2558        f.complete(one);
2559        checkIncomplete(g);
2560        f2.complete(two);
2561        checkCompletedWithWrappedCFException(g);
2562    }
2563
2564    /**
2565     * runAfterBothAsync result completes exceptionally if either source cancelled
2566     */
2567    public void testRunAfterBothAsync4E() {
2568        CompletableFuture<Integer> f = new CompletableFuture<>();
2569        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2570        Noop r = new Noop();
2571        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2572        assertTrue(f.cancel(true));
2573        f2.complete(two);
2574        checkCompletedWithWrappedCancellationException(g);
2575
2576        r = new Noop();
2577        f = new CompletableFuture<>();
2578        f2 = new CompletableFuture<>();
2579        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2580        f.complete(one);
2581        assertTrue(f2.cancel(true));
2582        checkCompletedWithWrappedCancellationException(g);
2583    }
2584
2585    /**
2586     * applyToEitherAsync result completes normally after normal
2587     * completion of sources
2588     */
2589    public void testApplyToEitherAsyncE() {
2590        CompletableFuture<Integer> f = new CompletableFuture<>();
2591        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2592        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2593        f.complete(one);
2594        checkCompletedNormally(g, two);
2595
2596        f = new CompletableFuture<>();
2597        f.complete(one);
2598        f2 = new CompletableFuture<>();
2599        g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2600        checkCompletedNormally(g, two);
2601    }
2602
2603    /**
2604     * applyToEitherAsync result completes exceptionally after exceptional
2605     * completion of source
2606     */
2607    public void testApplyToEitherAsync2E() {
2608        CompletableFuture<Integer> f = new CompletableFuture<>();
2609        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2610        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2611        f.completeExceptionally(new CFException());
2612        checkCompletedWithWrappedCFException(g);
2613
2614        f = new CompletableFuture<>();
2615        f2 = new CompletableFuture<>();
2616        f2.completeExceptionally(new CFException());
2617        g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2618        f.complete(one);
2619        checkCompletedWithWrappedCFException(g);
2620    }
2621
2622    /**
2623     * applyToEitherAsync result completes exceptionally if action does
2624     */
2625    public void testApplyToEitherAsync3E() {
2626        CompletableFuture<Integer> f = new CompletableFuture<>();
2627        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2628        FailingFunction r = new FailingFunction();
2629        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2630        f.complete(one);
2631        checkCompletedWithWrappedCFException(g);
2632    }
2633
2634    /**
2635     * applyToEitherAsync result completes exceptionally if either source cancelled
2636     */
2637    public void testApplyToEitherAsync4E() {
2638        CompletableFuture<Integer> f = new CompletableFuture<>();
2639        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2640        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2641        assertTrue(f.cancel(true));
2642        checkCompletedWithWrappedCancellationException(g);
2643
2644        f = new CompletableFuture<>();
2645        f2 = new CompletableFuture<>();
2646        assertTrue(f2.cancel(true));
2647        g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2648        checkCompletedWithWrappedCancellationException(g);
2649    }
2650
2651    /**
2652     * acceptEitherAsync result completes normally after normal
2653     * completion of sources
2654     */
2655    public void testAcceptEitherAsyncE() {
2656        CompletableFuture<Integer> f = new CompletableFuture<>();
2657        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2658        IncAction r = new IncAction();
2659        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2660        f.complete(one);
2661        checkCompletedNormally(g, null);
2662        assertEquals(r.value, 2);
2663
2664        r = new IncAction();
2665        f = new CompletableFuture<>();
2666        f.complete(one);
2667        f2 = new CompletableFuture<>();
2668        g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2669        checkCompletedNormally(g, null);
2670        assertEquals(r.value, 2);
2671    }
2672
2673    /**
2674     * acceptEitherAsync result completes exceptionally after exceptional
2675     * completion of source
2676     */
2677    public void testAcceptEitherAsync2E() {
2678        CompletableFuture<Integer> f = new CompletableFuture<>();
2679        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2680        IncAction r = new IncAction();
2681        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2682        f.completeExceptionally(new CFException());
2683        checkCompletedWithWrappedCFException(g);
2684
2685        r = new IncAction();
2686        f = new CompletableFuture<>();
2687        f2 = new CompletableFuture<>();
2688        f2.completeExceptionally(new CFException());
2689        g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2690        f.complete(one);
2691        checkCompletedWithWrappedCFException(g);
2692    }
2693
2694    /**
2695     * acceptEitherAsync result completes exceptionally if action does
2696     */
2697    public void testAcceptEitherAsync3E() {
2698        CompletableFuture<Integer> f = new CompletableFuture<>();
2699        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2700        FailingConsumer r = new FailingConsumer();
2701        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2702        f.complete(one);
2703        checkCompletedWithWrappedCFException(g);
2704    }
2705
2706    /**
2707     * acceptEitherAsync result completes exceptionally if either
2708     * source cancelled
2709     */
2710    public void testAcceptEitherAsync4E() {
2711        CompletableFuture<Integer> f = new CompletableFuture<>();
2712        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2713        IncAction r = new IncAction();
2714        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2715        assertTrue(f.cancel(true));
2716        checkCompletedWithWrappedCancellationException(g);
2717
2718        r = new IncAction();
2719        f = new CompletableFuture<>();
2720        f2 = new CompletableFuture<>();
2721        assertTrue(f2.cancel(true));
2722        g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2723        checkCompletedWithWrappedCancellationException(g);
2724    }
2725
2726    /**
3060       * runAfterEitherAsync result completes normally after normal
3061       * completion of sources
3062       */
# Line 2931 | Line 3264 | public class CompletableFutureTest exten
3264          ThreadExecutor exec = new ThreadExecutor();
3265  
3266          Runnable[] throwingActions = {
3267 <            () -> { CompletableFuture.supplyAsync(null); },
3268 <            () -> { CompletableFuture.supplyAsync(null, exec); },
3269 <            () -> { CompletableFuture.supplyAsync(supplyOne, null); },
3270 <
3271 <            () -> { CompletableFuture.runAsync(null); },
3272 <            () -> { CompletableFuture.runAsync(null, exec); },
3273 <            () -> { CompletableFuture.runAsync(() -> {}, null); },
3274 <
3275 <            () -> { f.completeExceptionally(null); },
3276 <
3277 <            () -> { f.thenApply(null); },
3278 <            () -> { f.thenApplyAsync(null); },
3279 <            () -> { f.thenApplyAsync((x) -> x, null); },
3280 <            () -> { f.thenApplyAsync(null, exec); },
3281 <
3282 <            () -> { f.thenAccept(null); },
3283 <            () -> { f.thenAcceptAsync(null); },
3284 <            () -> { f.thenAcceptAsync((x) -> { ; }, null); },
3285 <            () -> { f.thenAcceptAsync(null, exec); },
3286 <
3287 <            () -> { f.thenRun(null); },
3288 <            () -> { f.thenRunAsync(null); },
3289 <            () -> { f.thenRunAsync(() -> { ; }, null); },
3290 <            () -> { f.thenRunAsync(null, exec); },
3291 <
3292 <            () -> { f.thenCombine(g, null); },
3293 <            () -> { f.thenCombineAsync(g, null); },
3294 <            () -> { f.thenCombineAsync(g, null, exec); },
3295 <            () -> { f.thenCombine(nullFuture, (x, y) -> x); },
3296 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x); },
3297 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); },
3298 <            () -> { f.thenCombineAsync(g, (x, y) -> x, null); },
3299 <
3300 <            () -> { f.thenAcceptBoth(g, null); },
3301 <            () -> { f.thenAcceptBothAsync(g, null); },
3302 <            () -> { f.thenAcceptBothAsync(g, null, exec); },
3303 <            () -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); },
3304 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); },
3305 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); },
3306 <            () -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); },
3307 <
3308 <            () -> { f.runAfterBoth(g, null); },
3309 <            () -> { f.runAfterBothAsync(g, null); },
3310 <            () -> { f.runAfterBothAsync(g, null, exec); },
3311 <            () -> { f.runAfterBoth(nullFuture, () -> {}); },
3312 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}); },
3313 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); },
3314 <            () -> { f.runAfterBothAsync(g, () -> {}, null); },
3315 <
3316 <            () -> { f.applyToEither(g, null); },
3317 <            () -> { f.applyToEitherAsync(g, null); },
3318 <            () -> { f.applyToEitherAsync(g, null, exec); },
3319 <            () -> { f.applyToEither(nullFuture, (x) -> x); },
3320 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x); },
3321 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); },
3322 <            () -> { f.applyToEitherAsync(g, (x) -> x, null); },
3323 <
3324 <            () -> { f.acceptEither(g, null); },
3325 <            () -> { f.acceptEitherAsync(g, null); },
3326 <            () -> { f.acceptEitherAsync(g, null, exec); },
3327 <            () -> { f.acceptEither(nullFuture, (x) -> {}); },
3328 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}); },
3329 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); },
3330 <            () -> { f.acceptEitherAsync(g, (x) -> {}, null); },
3331 <
3332 <            () -> { f.runAfterEither(g, null); },
3333 <            () -> { f.runAfterEitherAsync(g, null); },
3334 <            () -> { f.runAfterEitherAsync(g, null, exec); },
3335 <            () -> { f.runAfterEither(nullFuture, () -> {}); },
3336 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}); },
3337 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); },
3338 <            () -> { f.runAfterEitherAsync(g, () -> {}, null); },
3339 <
3340 <            () -> { f.thenCompose(null); },
3341 <            () -> { f.thenComposeAsync(null); },
3342 <            () -> { f.thenComposeAsync(new CompletableFutureInc(), null); },
3343 <            () -> { f.thenComposeAsync(null, exec); },
3344 <
3345 <            () -> { f.exceptionally(null); },
3346 <
3347 <            () -> { f.handle(null); },
3348 <
3349 <            () -> { CompletableFuture.allOf((CompletableFuture<?>)null); },
3350 <            () -> { CompletableFuture.allOf((CompletableFuture<?>[])null); },
3351 <            () -> { CompletableFuture.allOf(f, null); },
3352 <            () -> { CompletableFuture.allOf(null, f); },
3353 <
3354 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>)null); },
3355 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); },
3356 <            () -> { CompletableFuture.anyOf(f, null); },
3357 <            () -> { CompletableFuture.anyOf(null, f); },
3267 >            () -> CompletableFuture.supplyAsync(null),
3268 >            () -> CompletableFuture.supplyAsync(null, exec),
3269 >            () -> CompletableFuture.supplyAsync(supplyOne, null),
3270 >
3271 >            () -> CompletableFuture.runAsync(null),
3272 >            () -> CompletableFuture.runAsync(null, exec),
3273 >            () -> CompletableFuture.runAsync(() -> {}, null),
3274 >
3275 >            () -> f.completeExceptionally(null),
3276 >
3277 >            () -> f.thenApply(null),
3278 >            () -> f.thenApplyAsync(null),
3279 >            () -> f.thenApplyAsync((x) -> x, null),
3280 >            () -> f.thenApplyAsync(null, exec),
3281 >
3282 >            () -> f.thenAccept(null),
3283 >            () -> f.thenAcceptAsync(null),
3284 >            () -> f.thenAcceptAsync((x) -> {} , null),
3285 >            () -> f.thenAcceptAsync(null, exec),
3286 >
3287 >            () -> f.thenRun(null),
3288 >            () -> f.thenRunAsync(null),
3289 >            () -> f.thenRunAsync(() -> {} , null),
3290 >            () -> f.thenRunAsync(null, exec),
3291 >
3292 >            () -> f.thenCombine(g, null),
3293 >            () -> f.thenCombineAsync(g, null),
3294 >            () -> f.thenCombineAsync(g, null, exec),
3295 >            () -> f.thenCombine(nullFuture, (x, y) -> x),
3296 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x),
3297 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec),
3298 >            () -> f.thenCombineAsync(g, (x, y) -> x, null),
3299 >
3300 >            () -> f.thenAcceptBoth(g, null),
3301 >            () -> f.thenAcceptBothAsync(g, null),
3302 >            () -> f.thenAcceptBothAsync(g, null, exec),
3303 >            () -> f.thenAcceptBoth(nullFuture, (x, y) -> {}),
3304 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}),
3305 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec),
3306 >            () -> f.thenAcceptBothAsync(g, (x, y) -> {}, null),
3307 >
3308 >            () -> f.runAfterBoth(g, null),
3309 >            () -> f.runAfterBothAsync(g, null),
3310 >            () -> f.runAfterBothAsync(g, null, exec),
3311 >            () -> f.runAfterBoth(nullFuture, () -> {}),
3312 >            () -> f.runAfterBothAsync(nullFuture, () -> {}),
3313 >            () -> f.runAfterBothAsync(nullFuture, () -> {}, exec),
3314 >            () -> f.runAfterBothAsync(g, () -> {}, null),
3315 >
3316 >            () -> f.applyToEither(g, null),
3317 >            () -> f.applyToEitherAsync(g, null),
3318 >            () -> f.applyToEitherAsync(g, null, exec),
3319 >            () -> f.applyToEither(nullFuture, (x) -> x),
3320 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x),
3321 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x, exec),
3322 >            () -> f.applyToEitherAsync(g, (x) -> x, null),
3323 >
3324 >            () -> f.acceptEither(g, null),
3325 >            () -> f.acceptEitherAsync(g, null),
3326 >            () -> f.acceptEitherAsync(g, null, exec),
3327 >            () -> f.acceptEither(nullFuture, (x) -> {}),
3328 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}),
3329 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec),
3330 >            () -> f.acceptEitherAsync(g, (x) -> {}, null),
3331 >
3332 >            () -> f.runAfterEither(g, null),
3333 >            () -> f.runAfterEitherAsync(g, null),
3334 >            () -> f.runAfterEitherAsync(g, null, exec),
3335 >            () -> f.runAfterEither(nullFuture, () -> {}),
3336 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}),
3337 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}, exec),
3338 >            () -> f.runAfterEitherAsync(g, () -> {}, null),
3339 >
3340 >            () -> f.thenCompose(null),
3341 >            () -> f.thenComposeAsync(null),
3342 >            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
3343 >            () -> f.thenComposeAsync(null, exec),
3344 >
3345 >            () -> f.exceptionally(null),
3346 >
3347 >            () -> f.handle(null),
3348 >
3349 >            () -> CompletableFuture.allOf((CompletableFuture<?>)null),
3350 >            () -> CompletableFuture.allOf((CompletableFuture<?>[])null),
3351 >            () -> CompletableFuture.allOf(f, null),
3352 >            () -> CompletableFuture.allOf(null, f),
3353 >
3354 >            () -> CompletableFuture.anyOf((CompletableFuture<?>)null),
3355 >            () -> CompletableFuture.anyOf((CompletableFuture<?>[])null),
3356 >            () -> CompletableFuture.anyOf(f, null),
3357 >            () -> CompletableFuture.anyOf(null, f),
3358 >
3359 >            () -> f.obtrudeException(null),
3360          };
3361  
3362          assertThrows(NullPointerException.class, throwingActions);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines