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.20 by jsr166, Mon Apr 8 16:45:15 2013 UTC vs.
Revision 1.34 by jsr166, Sun Jun 1 21:17:05 2014 UTC

# Line 68 | Line 68 | public class CompletableFutureTest exten
68          } catch (Throwable fail) { threadUnexpectedException(fail); }
69          assertTrue(f.isDone());
70          assertFalse(f.isCancelled());
71 +        assertFalse(f.isCompletedExceptionally());
72          assertTrue(f.toString().contains("[Completed normally]"));
73      }
74  
# Line 101 | Line 102 | public class CompletableFutureTest exten
102          assertTrue(f.toString().contains("[Completed exceptionally]"));
103      }
104  
105 +    void checkCompletedWithWrappedCFException(CompletableFuture<?> f,
106 +                                              CFException ex) {
107 +        try {
108 +            f.get(LONG_DELAY_MS, MILLISECONDS);
109 +            shouldThrow();
110 +        } catch (ExecutionException success) {
111 +            assertSame(ex, success.getCause());
112 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
113 +        try {
114 +            f.join();
115 +            shouldThrow();
116 +        } catch (CompletionException success) {
117 +            assertSame(ex, success.getCause());
118 +        }
119 +        try {
120 +            f.getNow(null);
121 +            shouldThrow();
122 +        } catch (CompletionException success) {
123 +            assertSame(ex, success.getCause());
124 +        }
125 +        try {
126 +            f.get();
127 +            shouldThrow();
128 +        } catch (ExecutionException success) {
129 +            assertSame(ex, success.getCause());
130 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
131 +        assertTrue(f.isDone());
132 +        assertFalse(f.isCancelled());
133 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
134 +    }
135 +
136      void checkCancelled(CompletableFuture<?> f) {
137          try {
138              f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 121 | Line 153 | public class CompletableFutureTest exten
153          } catch (CancellationException success) {
154          } catch (Throwable fail) { threadUnexpectedException(fail); }
155          assertTrue(f.isDone());
156 +        assertTrue(f.isCompletedExceptionally());
157          assertTrue(f.isCancelled());
158          assertTrue(f.toString().contains("[Completed exceptionally]"));
159      }
# Line 152 | Line 185 | public class CompletableFutureTest exten
185          } catch (Throwable fail) { threadUnexpectedException(fail); }
186          assertTrue(f.isDone());
187          assertFalse(f.isCancelled());
188 +        assertTrue(f.isCompletedExceptionally());
189          assertTrue(f.toString().contains("[Completed exceptionally]"));
190      }
191  
# Line 160 | Line 194 | public class CompletableFutureTest exten
194       * by methods isDone, isCancelled, and getNow
195       */
196      public void testConstructor() {
197 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
197 >        CompletableFuture<Integer> f = new CompletableFuture<>();
198          checkIncomplete(f);
199      }
200  
# Line 169 | Line 203 | public class CompletableFutureTest exten
203       * isCancelled, join, get, and getNow
204       */
205      public void testComplete() {
206 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
206 >        CompletableFuture<Integer> f = new CompletableFuture<>();
207          checkIncomplete(f);
208          f.complete(one);
209          checkCompletedNormally(f, one);
# Line 180 | Line 214 | public class CompletableFutureTest exten
214       * methods isDone, isCancelled, join, get, and getNow
215       */
216      public void testCompleteExceptionally() {
217 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
217 >        CompletableFuture<Integer> f = new CompletableFuture<>();
218          checkIncomplete(f);
219          f.completeExceptionally(new CFException());
220          checkCompletedWithWrappedCFException(f);
# Line 191 | Line 225 | public class CompletableFutureTest exten
225       * methods isDone, isCancelled, join, get, and getNow
226       */
227      public void testCancel() {
228 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
228 >        CompletableFuture<Integer> f = new CompletableFuture<>();
229          checkIncomplete(f);
230          assertTrue(f.cancel(true));
231          checkCancelled(f);
# Line 201 | Line 235 | public class CompletableFutureTest exten
235       * obtrudeValue forces completion with given value
236       */
237      public void testObtrudeValue() {
238 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
238 >        CompletableFuture<Integer> f = new CompletableFuture<>();
239          checkIncomplete(f);
240          f.complete(one);
241          checkCompletedNormally(f, one);
# Line 209 | Line 243 | public class CompletableFutureTest exten
243          checkCompletedNormally(f, three);
244          f.obtrudeValue(two);
245          checkCompletedNormally(f, two);
246 <        f = new CompletableFuture<Integer>();
246 >        f = new CompletableFuture<>();
247          f.obtrudeValue(three);
248          checkCompletedNormally(f, three);
249 <        f = new CompletableFuture<Integer>();
249 >        f = new CompletableFuture<>();
250          f.completeExceptionally(new CFException());
251          f.obtrudeValue(four);
252          checkCompletedNormally(f, four);
# Line 222 | Line 256 | public class CompletableFutureTest exten
256       * obtrudeException forces completion with given exception
257       */
258      public void testObtrudeException() {
259 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
259 >        CompletableFuture<Integer> f = new CompletableFuture<>();
260          checkIncomplete(f);
261          f.complete(one);
262          checkCompletedNormally(f, one);
263          f.obtrudeException(new CFException());
264          checkCompletedWithWrappedCFException(f);
265 <        f = new CompletableFuture<Integer>();
265 >        f = new CompletableFuture<>();
266          f.obtrudeException(new CFException());
267          checkCompletedWithWrappedCFException(f);
268 <        f = new CompletableFuture<Integer>();
268 >        f = new CompletableFuture<>();
269          f.completeExceptionally(new CFException());
270          f.obtrudeValue(four);
271          checkCompletedNormally(f, four);
# Line 243 | Line 277 | public class CompletableFutureTest exten
277       * getNumberOfDependents returns number of dependent tasks
278       */
279      public void testGetNumberOfDependents() {
280 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
280 >        CompletableFuture<Integer> f = new CompletableFuture<>();
281          assertEquals(f.getNumberOfDependents(), 0);
282          CompletableFuture g = f.thenRun(new Noop());
283          assertEquals(f.getNumberOfDependents(), 1);
# Line 256 | Line 290 | public class CompletableFutureTest exten
290          assertEquals(g.getNumberOfDependents(), 0);
291      }
292  
259
293      /**
294       * toString indicates current completion state
295       */
# Line 294 | Line 327 | public class CompletableFutureTest exten
327          int value;
328          public void accept(Integer x) { value = x.intValue() + 1; }
329      }
330 <    static final class AddAction implements BiConsumer<Integer, Integer> {
330 >    static final class SubtractAction implements BiConsumer<Integer, Integer> {
331          int value;
332          public void accept(Integer x, Integer y) {
333 <            value = x.intValue() + y.intValue();
333 >            value = x.intValue() - y.intValue();
334          }
335      }
336      static final class Noop implements Runnable {
# Line 335 | Line 368 | public class CompletableFutureTest exten
368          boolean ran;
369          public CompletableFuture<Integer> apply(Integer x) {
370              ran = true;
371 <            CompletableFuture<Integer> f = new CompletableFuture<Integer>();
371 >            CompletableFuture<Integer> f = new CompletableFuture<>();
372              f.complete(Integer.valueOf(x.intValue() + 1));
373              return f;
374          }
# Line 371 | Line 404 | public class CompletableFutureTest exten
404          }
405      }
406  
374
407      /**
408       * exceptionally action completes with function value on source
409 <     * exception;  otherwise with source value
409 >     * exception; otherwise with source value
410       */
411      public void testExceptionally() {
412 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
412 >        CompletableFuture<Integer> f = new CompletableFuture<>();
413          ExceptionToInteger r = new ExceptionToInteger();
414          CompletableFuture<Integer> g = f.exceptionally(r);
415          f.completeExceptionally(new CFException());
416          checkCompletedNormally(g, three);
417  
418 <        f = new CompletableFuture<Integer>();
418 >        f = new CompletableFuture<>();
419          r = new ExceptionToInteger();
420          g = f.exceptionally(r);
421          f.complete(one);
# Line 398 | Line 430 | public class CompletableFutureTest exten
430          CompletableFuture<Integer> f, g;
431          IntegerHandler r;
432  
433 <        f = new CompletableFuture<Integer>();
433 >        f = new CompletableFuture<>();
434          f.completeExceptionally(new CFException());
435          g = f.handle(r = new IntegerHandler());
436          assertTrue(r.ran);
437          checkCompletedNormally(g, three);
438  
439 <        f = new CompletableFuture<Integer>();
439 >        f = new CompletableFuture<>();
440          g = f.handle(r = new IntegerHandler());
441          assertFalse(r.ran);
442          f.completeExceptionally(new CFException());
443          checkCompletedNormally(g, three);
444          assertTrue(r.ran);
445  
446 <        f = new CompletableFuture<Integer>();
446 >        f = new CompletableFuture<>();
447          f.complete(one);
448          g = f.handle(r = new IntegerHandler());
449          assertTrue(r.ran);
450          checkCompletedNormally(g, two);
451  
452 <        f = new CompletableFuture<Integer>();
452 >        f = new CompletableFuture<>();
453          g = f.handle(r = new IntegerHandler());
454          assertFalse(r.ran);
455          f.complete(one);
# Line 495 | Line 527 | public class CompletableFutureTest exten
527       * thenRun result completes normally after normal completion of source
528       */
529      public void testThenRun() {
530 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
531 <        Noop r = new Noop();
532 <        CompletableFuture<Void> g = f.thenRun(r);
530 >        CompletableFuture<Integer> f;
531 >        CompletableFuture<Void> g;
532 >        Noop r;
533 >
534 >        f = new CompletableFuture<>();
535 >        g = f.thenRun(r = new Noop());
536          f.complete(null);
537          checkCompletedNormally(g, null);
538 <        // reordered version
539 <        f = new CompletableFuture<Integer>();
538 >        assertTrue(r.ran);
539 >
540 >        f = new CompletableFuture<>();
541          f.complete(null);
542 <        r = new Noop();
507 <        g = f.thenRun(r);
542 >        g = f.thenRun(r = new Noop());
543          checkCompletedNormally(g, null);
544 +        assertTrue(r.ran);
545      }
546  
547      /**
# Line 513 | Line 549 | public class CompletableFutureTest exten
549       * completion of source
550       */
551      public void testThenRun2() {
552 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
553 <        Noop r = new Noop();
554 <        CompletableFuture<Void> g = f.thenRun(r);
552 >        CompletableFuture<Integer> f;
553 >        CompletableFuture<Void> g;
554 >        Noop r;
555 >
556 >        f = new CompletableFuture<>();
557 >        g = f.thenRun(r = new Noop());
558          f.completeExceptionally(new CFException());
559          checkCompletedWithWrappedCFException(g);
560 +        assertFalse(r.ran);
561 +
562 +        f = new CompletableFuture<>();
563 +        f.completeExceptionally(new CFException());
564 +        g = f.thenRun(r = new Noop());
565 +        checkCompletedWithWrappedCFException(g);
566 +        assertFalse(r.ran);
567      }
568  
569      /**
570       * thenRun result completes exceptionally if action does
571       */
572      public void testThenRun3() {
573 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
574 <        FailingNoop r = new FailingNoop();
575 <        CompletableFuture<Void> g = f.thenRun(r);
573 >        CompletableFuture<Integer> f;
574 >        CompletableFuture<Void> g;
575 >        FailingNoop r;
576 >
577 >        f = new CompletableFuture<>();
578 >        g = f.thenRun(r = new FailingNoop());
579 >        f.complete(null);
580 >        checkCompletedWithWrappedCFException(g);
581 >
582 >        f = new CompletableFuture<>();
583          f.complete(null);
584 +        g = f.thenRun(r = new FailingNoop());
585          checkCompletedWithWrappedCFException(g);
586      }
587  
# Line 535 | Line 589 | public class CompletableFutureTest exten
589       * thenRun result completes exceptionally if source cancelled
590       */
591      public void testThenRun4() {
592 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
593 <        Noop r = new Noop();
594 <        CompletableFuture<Void> g = f.thenRun(r);
592 >        CompletableFuture<Integer> f;
593 >        CompletableFuture<Void> g;
594 >        Noop r;
595 >
596 >        f = new CompletableFuture<>();
597 >        g = f.thenRun(r = new Noop());
598          assertTrue(f.cancel(true));
599          checkCompletedWithWrappedCancellationException(g);
600 +
601 +        f = new CompletableFuture<>();
602 +        assertTrue(f.cancel(true));
603 +        g = f.thenRun(r = new Noop());
604 +        checkCompletedWithWrappedCancellationException(g);
605      }
606  
607      /**
608       * thenApply result completes normally after normal completion of source
609       */
610      public void testThenApply() {
611 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
611 >        CompletableFuture<Integer> f = new CompletableFuture<>();
612          CompletableFuture<Integer> g = f.thenApply(inc);
613          f.complete(one);
614          checkCompletedNormally(g, two);
# Line 557 | Line 619 | public class CompletableFutureTest exten
619       * completion of source
620       */
621      public void testThenApply2() {
622 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
622 >        CompletableFuture<Integer> f = new CompletableFuture<>();
623          CompletableFuture<Integer> g = f.thenApply(inc);
624          f.completeExceptionally(new CFException());
625          checkCompletedWithWrappedCFException(g);
# Line 567 | Line 629 | public class CompletableFutureTest exten
629       * thenApply result completes exceptionally if action does
630       */
631      public void testThenApply3() {
632 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
632 >        CompletableFuture<Integer> f = new CompletableFuture<>();
633          CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
634          f.complete(one);
635          checkCompletedWithWrappedCFException(g);
# Line 577 | Line 639 | public class CompletableFutureTest exten
639       * thenApply result completes exceptionally if source cancelled
640       */
641      public void testThenApply4() {
642 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
642 >        CompletableFuture<Integer> f = new CompletableFuture<>();
643          CompletableFuture<Integer> g = f.thenApply(inc);
644          assertTrue(f.cancel(true));
645          checkCompletedWithWrappedCancellationException(g);
# Line 587 | Line 649 | public class CompletableFutureTest exten
649       * thenAccept result completes normally after normal completion of source
650       */
651      public void testThenAccept() {
652 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
652 >        CompletableFuture<Integer> f = new CompletableFuture<>();
653          IncAction r = new IncAction();
654          CompletableFuture<Void> g = f.thenAccept(r);
655          f.complete(one);
# Line 600 | Line 662 | public class CompletableFutureTest exten
662       * completion of source
663       */
664      public void testThenAccept2() {
665 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
665 >        CompletableFuture<Integer> f = new CompletableFuture<>();
666          IncAction r = new IncAction();
667          CompletableFuture<Void> g = f.thenAccept(r);
668          f.completeExceptionally(new CFException());
# Line 611 | Line 673 | public class CompletableFutureTest exten
673       * thenAccept result completes exceptionally if action does
674       */
675      public void testThenAccept3() {
676 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
676 >        CompletableFuture<Integer> f = new CompletableFuture<>();
677          FailingConsumer r = new FailingConsumer();
678          CompletableFuture<Void> g = f.thenAccept(r);
679          f.complete(one);
# Line 623 | Line 685 | public class CompletableFutureTest exten
685       * thenAccept result completes exceptionally if source cancelled
686       */
687      public void testThenAccept4() {
688 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
688 >        CompletableFuture<Integer> f = new CompletableFuture<>();
689          IncAction r = new IncAction();
690          CompletableFuture<Void> g = f.thenAccept(r);
691          assertTrue(f.cancel(true));
692          checkCompletedWithWrappedCancellationException(g);
693      }
694  
633
695      /**
696       * thenCombine result completes normally after normal completion
697       * of sources
# Line 638 | Line 699 | public class CompletableFutureTest exten
699      public void testThenCombine() {
700          CompletableFuture<Integer> f, g, h;
701  
702 <        f = new CompletableFuture<Integer>();
703 <        g = new CompletableFuture<Integer>();
702 >        f = new CompletableFuture<>();
703 >        g = new CompletableFuture<>();
704          h = f.thenCombine(g, subtract);
705          f.complete(3);
706          checkIncomplete(h);
707          g.complete(1);
708          checkCompletedNormally(h, 2);
709  
710 <        f = new CompletableFuture<Integer>();
711 <        g = new CompletableFuture<Integer>();
710 >        f = new CompletableFuture<>();
711 >        g = new CompletableFuture<>();
712          h = f.thenCombine(g, subtract);
713          g.complete(1);
714          checkIncomplete(h);
715          f.complete(3);
716          checkCompletedNormally(h, 2);
717  
718 <        f = new CompletableFuture<Integer>();
719 <        g = new CompletableFuture<Integer>();
718 >        f = new CompletableFuture<>();
719 >        g = new CompletableFuture<>();
720          g.complete(1);
721          f.complete(3);
722          h = f.thenCombine(g, subtract);
# Line 669 | Line 730 | public class CompletableFutureTest exten
730      public void testThenCombine2() {
731          CompletableFuture<Integer> f, g, h;
732  
733 <        f = new CompletableFuture<Integer>();
734 <        g = new CompletableFuture<Integer>();
733 >        f = new CompletableFuture<>();
734 >        g = new CompletableFuture<>();
735          h = f.thenCombine(g, subtract);
736          f.completeExceptionally(new CFException());
737          checkIncomplete(h);
738          g.complete(1);
739          checkCompletedWithWrappedCFException(h);
740  
741 <        f = new CompletableFuture<Integer>();
742 <        g = new CompletableFuture<Integer>();
741 >        f = new CompletableFuture<>();
742 >        g = new CompletableFuture<>();
743          h = f.thenCombine(g, subtract);
744          g.completeExceptionally(new CFException());
745          checkIncomplete(h);
746          f.complete(3);
747          checkCompletedWithWrappedCFException(h);
748  
749 <        f = new CompletableFuture<Integer>();
750 <        g = new CompletableFuture<Integer>();
749 >        f = new CompletableFuture<>();
750 >        g = new CompletableFuture<>();
751          f.complete(3);
752          g.completeExceptionally(new CFException());
753          h = f.thenCombine(g, subtract);
754          checkCompletedWithWrappedCFException(h);
755  
756 <        f = new CompletableFuture<Integer>();
757 <        g = new CompletableFuture<Integer>();
756 >        f = new CompletableFuture<>();
757 >        g = new CompletableFuture<>();
758          f.completeExceptionally(new CFException());
759          g.complete(3);
760          h = f.thenCombine(g, subtract);
# Line 704 | Line 765 | public class CompletableFutureTest exten
765       * thenCombine result completes exceptionally if action does
766       */
767      public void testThenCombine3() {
768 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
769 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
768 >        CompletableFuture<Integer> f = new CompletableFuture<>();
769 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
770          FailingBiFunction r = new FailingBiFunction();
771          CompletableFuture<Integer> g = f.thenCombine(f2, r);
772          f.complete(one);
# Line 722 | Line 783 | public class CompletableFutureTest exten
783      public void testThenCombine4() {
784          CompletableFuture<Integer> f, g, h;
785  
786 <        f = new CompletableFuture<Integer>();
787 <        g = new CompletableFuture<Integer>();
786 >        f = new CompletableFuture<>();
787 >        g = new CompletableFuture<>();
788          h = f.thenCombine(g, subtract);
789          assertTrue(f.cancel(true));
790          checkIncomplete(h);
791          g.complete(1);
792          checkCompletedWithWrappedCancellationException(h);
793  
794 <        f = new CompletableFuture<Integer>();
795 <        g = new CompletableFuture<Integer>();
794 >        f = new CompletableFuture<>();
795 >        g = new CompletableFuture<>();
796          h = f.thenCombine(g, subtract);
797          assertTrue(g.cancel(true));
798          checkIncomplete(h);
799          f.complete(3);
800          checkCompletedWithWrappedCancellationException(h);
801  
802 <        f = new CompletableFuture<Integer>();
803 <        g = new CompletableFuture<Integer>();
802 >        f = new CompletableFuture<>();
803 >        g = new CompletableFuture<>();
804          assertTrue(f.cancel(true));
805          assertTrue(g.cancel(true));
806          h = f.thenCombine(g, subtract);
# Line 751 | Line 812 | public class CompletableFutureTest exten
812       * completion of sources
813       */
814      public void testThenAcceptBoth() {
815 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
816 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
817 <        AddAction r = new AddAction();
757 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
758 <        f.complete(one);
759 <        checkIncomplete(g);
760 <        f2.complete(two);
761 <        checkCompletedNormally(g, null);
762 <        assertEquals(r.value, 3);
815 >        CompletableFuture<Integer> f, g;
816 >        CompletableFuture<Void> h;
817 >        SubtractAction r;
818  
819 <        r = new AddAction();
820 <        f = new CompletableFuture<Integer>();
821 <        f.complete(one);
822 <        f2 = new CompletableFuture<Integer>();
823 <        g = f.thenAcceptBoth(f2, r);
824 <        checkIncomplete(g);
825 <        f2.complete(two);
826 <        checkCompletedNormally(g, null);
827 <        assertEquals(r.value, 3);
819 >        f = new CompletableFuture<>();
820 >        g = new CompletableFuture<>();
821 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
822 >        f.complete(3);
823 >        checkIncomplete(h);
824 >        g.complete(1);
825 >        checkCompletedNormally(h, null);
826 >        assertEquals(r.value, 2);
827 >
828 >        f = new CompletableFuture<>();
829 >        g = new CompletableFuture<>();
830 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
831 >        g.complete(1);
832 >        checkIncomplete(h);
833 >        f.complete(3);
834 >        checkCompletedNormally(h, null);
835 >        assertEquals(r.value, 2);
836 >
837 >        f = new CompletableFuture<>();
838 >        g = new CompletableFuture<>();
839 >        g.complete(1);
840 >        f.complete(3);
841 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
842 >        checkCompletedNormally(h, null);
843 >        assertEquals(r.value, 2);
844      }
845  
846      /**
# Line 777 | Line 848 | public class CompletableFutureTest exten
848       * completion of either source
849       */
850      public void testThenAcceptBoth2() {
851 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
852 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
853 <        AddAction r = new AddAction();
854 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
851 >        CompletableFuture<Integer> f, g;
852 >        CompletableFuture<Void> h;
853 >        SubtractAction r;
854 >
855 >        f = new CompletableFuture<>();
856 >        g = new CompletableFuture<>();
857 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
858          f.completeExceptionally(new CFException());
859 <        f2.complete(two);
860 <        checkCompletedWithWrappedCFException(g);
859 >        checkIncomplete(h);
860 >        g.complete(1);
861 >        checkCompletedWithWrappedCFException(h);
862  
863 <        r = new AddAction();
864 <        f = new CompletableFuture<Integer>();
865 <        f.complete(one);
866 <        f2 = new CompletableFuture<Integer>();
867 <        g = f.thenAcceptBoth(f2, r);
868 <        f2.completeExceptionally(new CFException());
869 <        checkCompletedWithWrappedCFException(g);
863 >        f = new CompletableFuture<>();
864 >        g = new CompletableFuture<>();
865 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
866 >        g.completeExceptionally(new CFException());
867 >        checkIncomplete(h);
868 >        f.complete(3);
869 >        checkCompletedWithWrappedCFException(h);
870 >
871 >        f = new CompletableFuture<>();
872 >        g = new CompletableFuture<>();
873 >        f.complete(3);
874 >        g.completeExceptionally(new CFException());
875 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
876 >        checkCompletedWithWrappedCFException(h);
877 >
878 >        f = new CompletableFuture<>();
879 >        g = new CompletableFuture<>();
880 >        f.completeExceptionally(new CFException());
881 >        g.complete(3);
882 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
883 >        checkCompletedWithWrappedCFException(h);
884      }
885  
886      /**
887       * thenAcceptBoth result completes exceptionally if action does
888       */
889      public void testThenAcceptBoth3() {
890 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
891 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
892 <        FailingBiConsumer r = new FailingBiConsumer();
893 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
894 <        f.complete(one);
895 <        checkIncomplete(g);
896 <        f2.complete(two);
897 <        checkCompletedWithWrappedCFException(g);
890 >        CompletableFuture<Integer> f, g;
891 >        CompletableFuture<Void> h;
892 >        FailingBiConsumer r;
893 >
894 >        f = new CompletableFuture<>();
895 >        g = new CompletableFuture<>();
896 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
897 >        f.complete(3);
898 >        checkIncomplete(h);
899 >        g.complete(1);
900 >        checkCompletedWithWrappedCFException(h);
901 >
902 >        f = new CompletableFuture<>();
903 >        g = new CompletableFuture<>();
904 >        f.complete(3);
905 >        g.complete(1);
906 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
907 >        checkCompletedWithWrappedCFException(h);
908      }
909  
910      /**
911       * thenAcceptBoth result completes exceptionally if either source cancelled
912       */
913      public void testThenAcceptBoth4() {
914 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
915 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
916 <        AddAction r = new AddAction();
917 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
914 >        CompletableFuture<Integer> f, g;
915 >        CompletableFuture<Void> h;
916 >        SubtractAction r;
917 >
918 >        f = new CompletableFuture<>();
919 >        g = new CompletableFuture<>();
920 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
921          assertTrue(f.cancel(true));
922 <        f2.complete(two);
923 <        checkCompletedWithWrappedCancellationException(g);
924 <        f = new CompletableFuture<Integer>();
925 <        f2 = new CompletableFuture<Integer>();
926 <        r = new AddAction();
927 <        g = f.thenAcceptBoth(f2, r);
928 <        f.complete(one);
929 <        assertTrue(f2.cancel(true));
930 <        checkCompletedWithWrappedCancellationException(g);
922 >        checkIncomplete(h);
923 >        g.complete(1);
924 >        checkCompletedWithWrappedCancellationException(h);
925 >
926 >        f = new CompletableFuture<>();
927 >        g = new CompletableFuture<>();
928 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
929 >        assertTrue(g.cancel(true));
930 >        checkIncomplete(h);
931 >        f.complete(3);
932 >        checkCompletedWithWrappedCancellationException(h);
933 >
934 >        f = new CompletableFuture<>();
935 >        g = new CompletableFuture<>();
936 >        f.complete(3);
937 >        assertTrue(g.cancel(true));
938 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
939 >        checkCompletedWithWrappedCancellationException(h);
940 >
941 >        f = new CompletableFuture<>();
942 >        g = new CompletableFuture<>();
943 >        assertTrue(f.cancel(true));
944 >        g.complete(3);
945 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
946 >        checkCompletedWithWrappedCancellationException(h);
947 >    }
948 >
949 >    /**
950 >     * Permits the testing of parallel code for the 3 different
951 >     * execution modes without repeating all the testing code.
952 >     */
953 >    enum ExecutionMode {
954 >        DEFAULT {
955 >            public <T,U> CompletableFuture<Void> runAfterBoth
956 >                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
957 >                return f.runAfterBoth(g, r);
958 >            }
959 >        },
960 >
961 >        DEFAULT_ASYNC {
962 >            public <T,U> CompletableFuture<Void> runAfterBoth
963 >                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
964 >                return f.runAfterBothAsync(g, r);
965 >            }
966 >        },
967 >
968 >        EXECUTOR {
969 >            public <T,U> CompletableFuture<Void> runAfterBoth
970 >                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
971 >                return f.runAfterBothAsync(g, r, new ThreadExecutor());
972 >            }
973 >        };
974 >
975 >        public abstract <T,U> CompletableFuture<Void> runAfterBoth
976 >            (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r);
977      }
978  
979      /**
980       * runAfterBoth result completes normally after normal
981       * completion of sources
982       */
983 <    public void testRunAfterBoth() {
984 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
985 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
986 <        Noop r = new Noop();
987 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
988 <        f.complete(one);
989 <        checkIncomplete(g);
990 <        f2.complete(two);
991 <        checkCompletedNormally(g, null);
983 >    public void testRunAfterBoth_normalCompletion1() {
984 >        for (ExecutionMode m : ExecutionMode.values())
985 >        for (Integer v1 : new Integer[] { 1, null })
986 >        for (Integer v2 : new Integer[] { 2, null }) {
987 >
988 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
989 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
990 >        final Noop r = new Noop();
991 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
992 >
993 >        f.complete(v1);
994 >        checkIncomplete(h);
995 >        assertFalse(r.ran);
996 >        g.complete(v2);
997 >
998 >        checkCompletedNormally(h, null);
999          assertTrue(r.ran);
1000 +        checkCompletedNormally(f, v1);
1001 +        checkCompletedNormally(g, v2);
1002 +        }
1003 +    }
1004  
1005 <        r = new Noop();
1006 <        f = new CompletableFuture<Integer>();
1007 <        f.complete(one);
1008 <        f2 = new CompletableFuture<Integer>();
1009 <        g = f.runAfterBoth(f2, r);
1010 <        checkIncomplete(g);
1011 <        f2.complete(two);
1012 <        checkCompletedNormally(g, null);
1005 >    public void testRunAfterBoth_normalCompletion2() {
1006 >        for (ExecutionMode m : ExecutionMode.values())
1007 >        for (Integer v1 : new Integer[] { 1, null })
1008 >        for (Integer v2 : new Integer[] { 2, null }) {
1009 >
1010 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1011 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1012 >        final Noop r = new Noop();
1013 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1014 >
1015 >        g.complete(v2);
1016 >        checkIncomplete(h);
1017 >        assertFalse(r.ran);
1018 >        f.complete(v1);
1019 >
1020 >        checkCompletedNormally(h, null);
1021 >        assertTrue(r.ran);
1022 >        checkCompletedNormally(f, v1);
1023 >        checkCompletedNormally(g, v2);
1024 >        }
1025 >    }
1026 >
1027 >    public void testRunAfterBoth_normalCompletion3() {
1028 >        for (ExecutionMode m : ExecutionMode.values())
1029 >        for (Integer v1 : new Integer[] { 1, null })
1030 >        for (Integer v2 : new Integer[] { 2, null }) {
1031 >
1032 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1033 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1034 >        final Noop r = new Noop();
1035 >
1036 >        g.complete(v2);
1037 >        f.complete(v1);
1038 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1039 >
1040 >        checkCompletedNormally(h, null);
1041          assertTrue(r.ran);
1042 +        checkCompletedNormally(f, v1);
1043 +        checkCompletedNormally(g, v2);
1044 +        }
1045 +    }
1046 +
1047 +    public void testRunAfterBoth_normalCompletion4() {
1048 +        for (ExecutionMode m : ExecutionMode.values())
1049 +        for (Integer v1 : new Integer[] { 1, null })
1050 +        for (Integer v2 : new Integer[] { 2, null }) {
1051 +
1052 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1053 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1054 +        final Noop r = new Noop();
1055 +
1056 +        f.complete(v1);
1057 +        g.complete(v2);
1058 +        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1059 +
1060 +        checkCompletedNormally(h, null);
1061 +        assertTrue(r.ran);
1062 +        checkCompletedNormally(f, v1);
1063 +        checkCompletedNormally(g, v2);
1064 +        }
1065      }
1066  
1067      /**
1068       * runAfterBoth result completes exceptionally after exceptional
1069       * completion of either source
1070       */
1071 <    public void testRunAfterBoth2() {
1072 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1073 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1074 <        Noop r = new Noop();
1075 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1076 <        f.completeExceptionally(new CFException());
1077 <        f2.complete(two);
1078 <        checkCompletedWithWrappedCFException(g);
1071 >    public void testRunAfterBoth_exceptionalCompletion1() {
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 Noop r = new Noop();
1078 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1079 >        final CFException ex = new CFException();
1080  
1081 <        r = new Noop();
1082 <        f = new CompletableFuture<Integer>();
1083 <        f.complete(one);
1084 <        f2 = new CompletableFuture<Integer>();
1085 <        g = f.runAfterBoth(f2, r);
1086 <        f2.completeExceptionally(new CFException());
1087 <        checkCompletedWithWrappedCFException(g);
1081 >        f.completeExceptionally(ex);
1082 >        checkIncomplete(h);
1083 >        g.complete(v1);
1084 >
1085 >        checkCompletedWithWrappedCFException(h, ex);
1086 >        checkCompletedWithWrappedCFException(f, ex);
1087 >        assertFalse(r.ran);
1088 >        checkCompletedNormally(g, v1);
1089 >        }
1090 >    }
1091 >
1092 >    public void testRunAfterBoth_exceptionalCompletion2() {
1093 >        for (ExecutionMode m : ExecutionMode.values())
1094 >        for (Integer v1 : new Integer[] { 1, null }) {
1095 >
1096 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1097 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1098 >        final Noop r = new Noop();
1099 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1100 >        final CFException ex = new CFException();
1101 >
1102 >        g.completeExceptionally(ex);
1103 >        checkIncomplete(h);
1104 >        f.complete(v1);
1105 >
1106 >        checkCompletedWithWrappedCFException(h, ex);
1107 >        checkCompletedWithWrappedCFException(g, ex);
1108 >        assertFalse(r.ran);
1109 >        checkCompletedNormally(f, v1);
1110 >        }
1111 >    }
1112 >
1113 >    public void testRunAfterBoth_exceptionalCompletion3() {
1114 >        for (ExecutionMode m : ExecutionMode.values())
1115 >        for (Integer v1 : new Integer[] { 1, null }) {
1116 >
1117 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1118 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1119 >        final Noop r = new Noop();
1120 >        final CFException ex = new CFException();
1121 >
1122 >        g.completeExceptionally(ex);
1123 >        f.complete(v1);
1124 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1125 >
1126 >        checkCompletedWithWrappedCFException(h, ex);
1127 >        checkCompletedWithWrappedCFException(g, ex);
1128 >        assertFalse(r.ran);
1129 >        checkCompletedNormally(f, v1);
1130 >        }
1131 >    }
1132 >
1133 >    public void testRunAfterBoth_exceptionalCompletion4() {
1134 >        for (ExecutionMode m : ExecutionMode.values())
1135 >        for (Integer v1 : new Integer[] { 1, null }) {
1136 >
1137 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1138 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1139 >        final Noop r = new Noop();
1140 >        final CFException ex = new CFException();
1141 >
1142 >        f.completeExceptionally(ex);
1143 >        g.complete(v1);
1144 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1145 >
1146 >        checkCompletedWithWrappedCFException(h, ex);
1147 >        checkCompletedWithWrappedCFException(f, ex);
1148 >        assertFalse(r.ran);
1149 >        checkCompletedNormally(g, v1);
1150 >        }
1151      }
1152  
1153      /**
1154       * runAfterBoth result completes exceptionally if action does
1155       */
1156 <    public void testRunAfterBoth3() {
1157 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1158 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1159 <        FailingNoop r = new FailingNoop();
1160 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1161 <        f.complete(one);
1162 <        checkIncomplete(g);
1163 <        f2.complete(two);
1164 <        checkCompletedWithWrappedCFException(g);
1156 >    public void testRunAfterBoth_actionFailed1() {
1157 >        for (ExecutionMode m : ExecutionMode.values())
1158 >        for (Integer v1 : new Integer[] { 1, null })
1159 >        for (Integer v2 : new Integer[] { 2, null }) {
1160 >
1161 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1162 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1163 >        final FailingNoop r = new FailingNoop();
1164 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1165 >
1166 >        f.complete(v1);
1167 >        checkIncomplete(h);
1168 >        g.complete(v2);
1169 >
1170 >        checkCompletedWithWrappedCFException(h);
1171 >        checkCompletedNormally(f, v1);
1172 >        checkCompletedNormally(g, v2);
1173 >        }
1174 >    }
1175 >
1176 >    public void testRunAfterBoth_actionFailed2() {
1177 >        for (ExecutionMode m : ExecutionMode.values())
1178 >        for (Integer v1 : new Integer[] { 1, null })
1179 >        for (Integer v2 : new Integer[] { 2, null }) {
1180 >
1181 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1182 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1183 >        final FailingNoop r = new FailingNoop();
1184 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1185 >
1186 >        g.complete(v2);
1187 >        checkIncomplete(h);
1188 >        f.complete(v1);
1189 >
1190 >        checkCompletedWithWrappedCFException(h);
1191 >        checkCompletedNormally(f, v1);
1192 >        checkCompletedNormally(g, v2);
1193 >        }
1194      }
1195  
1196      /**
1197       * runAfterBoth result completes exceptionally if either source cancelled
1198       */
1199 <    public void testRunAfterBoth4() {
1200 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1201 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1202 <        Noop r = new Noop();
1203 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1204 <        assertTrue(f.cancel(true));
1205 <        f2.complete(two);
1206 <        checkCompletedWithWrappedCancellationException(g);
1207 <        f = new CompletableFuture<Integer>();
1208 <        f2 = new CompletableFuture<Integer>();
1209 <        r = new Noop();
1210 <        g = f.runAfterBoth(f2, r);
1211 <        f.complete(one);
1212 <        assertTrue(f2.cancel(true));
1213 <        checkCompletedWithWrappedCancellationException(g);
1199 >    public void testRunAfterBoth_sourceCancelled1() {
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 Noop r = new Noop();
1207 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1208 >
1209 >        assertTrue(f.cancel(mayInterruptIfRunning));
1210 >        checkIncomplete(h);
1211 >        g.complete(v1);
1212 >
1213 >        checkCompletedWithWrappedCancellationException(h);
1214 >        checkCancelled(f);
1215 >        assertFalse(r.ran);
1216 >        checkCompletedNormally(g, v1);
1217 >        }
1218 >    }
1219 >
1220 >    public void testRunAfterBoth_sourceCancelled2() {
1221 >        for (ExecutionMode m : ExecutionMode.values())
1222 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1223 >        for (Integer v1 : new Integer[] { 1, null }) {
1224 >
1225 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1226 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1227 >        final Noop r = new Noop();
1228 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1229 >
1230 >        assertTrue(g.cancel(mayInterruptIfRunning));
1231 >        checkIncomplete(h);
1232 >        f.complete(v1);
1233 >
1234 >        checkCompletedWithWrappedCancellationException(h);
1235 >        checkCancelled(g);
1236 >        assertFalse(r.ran);
1237 >        checkCompletedNormally(f, v1);
1238 >        }
1239 >    }
1240 >
1241 >    public void testRunAfterBoth_sourceCancelled3() {
1242 >        for (ExecutionMode m : ExecutionMode.values())
1243 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1244 >        for (Integer v1 : new Integer[] { 1, null }) {
1245 >
1246 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1247 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1248 >        final Noop r = new Noop();
1249 >
1250 >        assertTrue(g.cancel(mayInterruptIfRunning));
1251 >        f.complete(v1);
1252 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1253 >
1254 >        checkCompletedWithWrappedCancellationException(h);
1255 >        checkCancelled(g);
1256 >        assertFalse(r.ran);
1257 >        checkCompletedNormally(f, v1);
1258 >        }
1259 >    }
1260 >
1261 >    public void testRunAfterBoth_sourceCancelled4() {
1262 >        for (ExecutionMode m : ExecutionMode.values())
1263 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1264 >        for (Integer v1 : new Integer[] { 1, null }) {
1265 >
1266 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1267 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1268 >        final Noop r = new Noop();
1269 >
1270 >        assertTrue(f.cancel(mayInterruptIfRunning));
1271 >        g.complete(v1);
1272 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1273 >
1274 >        checkCompletedWithWrappedCancellationException(h);
1275 >        checkCancelled(f);
1276 >        assertFalse(r.ran);
1277 >        checkCompletedNormally(g, v1);
1278 >        }
1279      }
1280  
1281      /**
# Line 915 | Line 1283 | public class CompletableFutureTest exten
1283       * of either source
1284       */
1285      public void testApplyToEither() {
1286 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1287 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1286 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1287 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1288          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1289          f.complete(one);
1290          checkCompletedNormally(g, two);
1291          f2.complete(one);
1292          checkCompletedNormally(g, two);
1293  
1294 <        f = new CompletableFuture<Integer>();
1294 >        f = new CompletableFuture<>();
1295          f.complete(one);
1296 <        f2 = new CompletableFuture<Integer>();
1296 >        f2 = new CompletableFuture<>();
1297          g = f.applyToEither(f2, inc);
1298          checkCompletedNormally(g, two);
1299      }
# Line 935 | Line 1303 | public class CompletableFutureTest exten
1303       * completion of either source
1304       */
1305      public void testApplyToEither2() {
1306 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1307 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1306 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1307 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1308          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1309          f.completeExceptionally(new CFException());
1310          f2.complete(one);
1311          checkCompletedWithWrappedCFException(g);
1312  
1313 <        f = new CompletableFuture<Integer>();
1314 <        f2 = new CompletableFuture<Integer>();
1313 >        f = new CompletableFuture<>();
1314 >        f2 = new CompletableFuture<>();
1315          f2.completeExceptionally(new CFException());
1316          g = f.applyToEither(f2, inc);
1317          checkCompletedWithWrappedCFException(g);
# Line 953 | Line 1321 | public class CompletableFutureTest exten
1321       * applyToEither result completes exceptionally if action does
1322       */
1323      public void testApplyToEither3() {
1324 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1325 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1324 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1325 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1326          FailingFunction r = new FailingFunction();
1327          CompletableFuture<Integer> g = f.applyToEither(f2, r);
1328          f2.complete(two);
# Line 965 | Line 1333 | public class CompletableFutureTest exten
1333       * applyToEither result completes exceptionally if either source cancelled
1334       */
1335      public void testApplyToEither4() {
1336 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1337 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1336 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1337 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1338          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1339          assertTrue(f.cancel(true));
1340          checkCompletedWithWrappedCancellationException(g);
1341 <        f = new CompletableFuture<Integer>();
1342 <        f2 = new CompletableFuture<Integer>();
1341 >        f = new CompletableFuture<>();
1342 >        f2 = new CompletableFuture<>();
1343          assertTrue(f2.cancel(true));
1344          checkCompletedWithWrappedCancellationException(g);
1345      }
# Line 981 | Line 1349 | public class CompletableFutureTest exten
1349       * of either source
1350       */
1351      public void testAcceptEither() {
1352 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1353 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1352 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1353 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1354          IncAction r = new IncAction();
1355          CompletableFuture<Void> g = f.acceptEither(f2, r);
1356          f.complete(one);
# Line 992 | Line 1360 | public class CompletableFutureTest exten
1360          assertEquals(r.value, 2);
1361  
1362          r = new IncAction();
1363 <        f = new CompletableFuture<Integer>();
1363 >        f = new CompletableFuture<>();
1364          f.complete(one);
1365 <        f2 = new CompletableFuture<Integer>();
1365 >        f2 = new CompletableFuture<>();
1366          g = f.acceptEither(f2, r);
1367          checkCompletedNormally(g, null);
1368          assertEquals(r.value, 2);
# Line 1005 | Line 1373 | public class CompletableFutureTest exten
1373       * completion of either source
1374       */
1375      public void testAcceptEither2() {
1376 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1377 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1376 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1377 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1378          IncAction r = new IncAction();
1379          CompletableFuture<Void> g = f.acceptEither(f2, r);
1380          f.completeExceptionally(new CFException());
# Line 1014 | Line 1382 | public class CompletableFutureTest exten
1382          checkCompletedWithWrappedCFException(g);
1383  
1384          r = new IncAction();
1385 <        f = new CompletableFuture<Integer>();
1386 <        f2 = new CompletableFuture<Integer>();
1385 >        f = new CompletableFuture<>();
1386 >        f2 = new CompletableFuture<>();
1387          f2.completeExceptionally(new CFException());
1388          g = f.acceptEither(f2, r);
1389          checkCompletedWithWrappedCFException(g);
# Line 1025 | Line 1393 | public class CompletableFutureTest exten
1393       * acceptEither result completes exceptionally if action does
1394       */
1395      public void testAcceptEither3() {
1396 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1397 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1396 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1397 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1398          FailingConsumer r = new FailingConsumer();
1399          CompletableFuture<Void> g = f.acceptEither(f2, r);
1400          f2.complete(two);
# Line 1037 | Line 1405 | public class CompletableFutureTest exten
1405       * acceptEither result completes exceptionally if either source cancelled
1406       */
1407      public void testAcceptEither4() {
1408 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1409 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1408 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1409 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1410          IncAction r = new IncAction();
1411          CompletableFuture<Void> g = f.acceptEither(f2, r);
1412          assertTrue(f.cancel(true));
1413          checkCompletedWithWrappedCancellationException(g);
1414 <        f = new CompletableFuture<Integer>();
1415 <        f2 = new CompletableFuture<Integer>();
1414 >        f = new CompletableFuture<>();
1415 >        f2 = new CompletableFuture<>();
1416          assertTrue(f2.cancel(true));
1417          checkCompletedWithWrappedCancellationException(g);
1418      }
1419  
1052
1420      /**
1421       * runAfterEither result completes normally after normal completion
1422       * of either source
1423       */
1424      public void testRunAfterEither() {
1425 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1426 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1425 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1426 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1427          Noop r = new Noop();
1428          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1429          f.complete(one);
# Line 1066 | Line 1433 | public class CompletableFutureTest exten
1433          assertTrue(r.ran);
1434  
1435          r = new Noop();
1436 <        f = new CompletableFuture<Integer>();
1436 >        f = new CompletableFuture<>();
1437          f.complete(one);
1438 <        f2 = new CompletableFuture<Integer>();
1438 >        f2 = new CompletableFuture<>();
1439          g = f.runAfterEither(f2, r);
1440          checkCompletedNormally(g, null);
1441          assertTrue(r.ran);
# Line 1079 | Line 1446 | public class CompletableFutureTest exten
1446       * completion of either source
1447       */
1448      public void testRunAfterEither2() {
1449 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1450 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1449 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1450 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1451          Noop r = new Noop();
1452          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1453          f.completeExceptionally(new CFException());
# Line 1088 | Line 1455 | public class CompletableFutureTest exten
1455          checkCompletedWithWrappedCFException(g);
1456  
1457          r = new Noop();
1458 <        f = new CompletableFuture<Integer>();
1459 <        f2 = new CompletableFuture<Integer>();
1458 >        f = new CompletableFuture<>();
1459 >        f2 = new CompletableFuture<>();
1460          f2.completeExceptionally(new CFException());
1461          g = f.runAfterEither(f2, r);
1462          checkCompletedWithWrappedCFException(g);
# Line 1099 | Line 1466 | public class CompletableFutureTest exten
1466       * runAfterEither result completes exceptionally if action does
1467       */
1468      public void testRunAfterEither3() {
1469 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1470 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1469 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1470 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1471          FailingNoop r = new FailingNoop();
1472          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1473          f2.complete(two);
# Line 1111 | Line 1478 | public class CompletableFutureTest exten
1478       * runAfterEither result completes exceptionally if either source cancelled
1479       */
1480      public void testRunAfterEither4() {
1481 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1482 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1481 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1482 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1483          Noop r = new Noop();
1484          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1485          assertTrue(f.cancel(true));
1486          checkCompletedWithWrappedCancellationException(g);
1487 <        f = new CompletableFuture<Integer>();
1488 <        f2 = new CompletableFuture<Integer>();
1487 >        f = new CompletableFuture<>();
1488 >        f2 = new CompletableFuture<>();
1489          assertTrue(f2.cancel(true));
1490          checkCompletedWithWrappedCancellationException(g);
1491      }
# Line 1127 | Line 1494 | public class CompletableFutureTest exten
1494       * thenCompose result completes normally after normal completion of source
1495       */
1496      public void testThenCompose() {
1497 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1498 <        CompletableFutureInc r = new CompletableFutureInc();
1499 <        CompletableFuture<Integer> g = f.thenCompose(r);
1497 >        CompletableFuture<Integer> f, g;
1498 >        CompletableFutureInc r;
1499 >
1500 >        f = new CompletableFuture<>();
1501 >        g = f.thenCompose(r = new CompletableFutureInc());
1502          f.complete(one);
1503          checkCompletedNormally(g, two);
1504 +        assertTrue(r.ran);
1505 +
1506 +        f = new CompletableFuture<>();
1507 +        f.complete(one);
1508 +        g = f.thenCompose(r = new CompletableFutureInc());
1509 +        checkCompletedNormally(g, two);
1510 +        assertTrue(r.ran);
1511      }
1512  
1513      /**
# Line 1139 | Line 1515 | public class CompletableFutureTest exten
1515       * completion of source
1516       */
1517      public void testThenCompose2() {
1518 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1519 <        CompletableFutureInc r = new CompletableFutureInc();
1520 <        CompletableFuture<Integer> g = f.thenCompose(r);
1518 >        CompletableFuture<Integer> f, g;
1519 >        CompletableFutureInc r;
1520 >
1521 >        f = new CompletableFuture<>();
1522 >        g = f.thenCompose(r = new CompletableFutureInc());
1523          f.completeExceptionally(new CFException());
1524          checkCompletedWithWrappedCFException(g);
1525 +
1526 +        f = new CompletableFuture<>();
1527 +        f.completeExceptionally(new CFException());
1528 +        g = f.thenCompose(r = new CompletableFutureInc());
1529 +        checkCompletedWithWrappedCFException(g);
1530      }
1531  
1532      /**
1533       * thenCompose result completes exceptionally if action does
1534       */
1535      public void testThenCompose3() {
1536 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1537 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
1538 <        CompletableFuture<Integer> g = f.thenCompose(r);
1536 >        CompletableFuture<Integer> f, g;
1537 >        FailingCompletableFutureFunction r;
1538 >
1539 >        f = new CompletableFuture<>();
1540 >        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1541          f.complete(one);
1542          checkCompletedWithWrappedCFException(g);
1543 +
1544 +        f = new CompletableFuture<>();
1545 +        f.complete(one);
1546 +        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1547 +        checkCompletedWithWrappedCFException(g);
1548      }
1549  
1550      /**
1551       * thenCompose result completes exceptionally if source cancelled
1552       */
1553      public void testThenCompose4() {
1554 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1555 <        CompletableFutureInc r = new CompletableFutureInc();
1556 <        CompletableFuture<Integer> g = f.thenCompose(r);
1554 >        CompletableFuture<Integer> f, g;
1555 >        CompletableFutureInc r;
1556 >
1557 >        f = new CompletableFuture<>();
1558 >        g = f.thenCompose(r = new CompletableFutureInc());
1559          assertTrue(f.cancel(true));
1560          checkCompletedWithWrappedCancellationException(g);
1169    }
1561  
1562 +        f = new CompletableFuture<>();
1563 +        assertTrue(f.cancel(true));
1564 +        g = f.thenCompose(r = new CompletableFutureInc());
1565 +        checkCompletedWithWrappedCancellationException(g);
1566 +    }
1567  
1568      // asyncs
1569  
# Line 1175 | Line 1571 | public class CompletableFutureTest exten
1571       * thenRunAsync result completes normally after normal completion of source
1572       */
1573      public void testThenRunAsync() {
1574 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1574 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1575          Noop r = new Noop();
1576          CompletableFuture<Void> g = f.thenRunAsync(r);
1577          f.complete(null);
1578          checkCompletedNormally(g, null);
1579  
1580          // reordered version
1581 <        f = new CompletableFuture<Integer>();
1581 >        f = new CompletableFuture<>();
1582          f.complete(null);
1583          r = new Noop();
1584          g = f.thenRunAsync(r);
# Line 1194 | Line 1590 | public class CompletableFutureTest exten
1590       * completion of source
1591       */
1592      public void testThenRunAsync2() {
1593 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1593 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1594          Noop r = new Noop();
1595          CompletableFuture<Void> g = f.thenRunAsync(r);
1596          f.completeExceptionally(new CFException());
1597          try {
1598              g.join();
1599              shouldThrow();
1600 <        } catch (Exception ok) {
1205 <        }
1600 >        } catch (CompletionException success) {}
1601          checkCompletedWithWrappedCFException(g);
1602      }
1603  
# Line 1210 | Line 1605 | public class CompletableFutureTest exten
1605       * thenRunAsync result completes exceptionally if action does
1606       */
1607      public void testThenRunAsync3() {
1608 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1608 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1609          FailingNoop r = new FailingNoop();
1610          CompletableFuture<Void> g = f.thenRunAsync(r);
1611          f.complete(null);
# Line 1221 | Line 1616 | public class CompletableFutureTest exten
1616       * thenRunAsync result completes exceptionally if source cancelled
1617       */
1618      public void testThenRunAsync4() {
1619 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1619 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1620          Noop r = new Noop();
1621          CompletableFuture<Void> g = f.thenRunAsync(r);
1622          assertTrue(f.cancel(true));
# Line 1232 | Line 1627 | public class CompletableFutureTest exten
1627       * thenApplyAsync result completes normally after normal completion of source
1628       */
1629      public void testThenApplyAsync() {
1630 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1630 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1631          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1632          f.complete(one);
1633          checkCompletedNormally(g, two);
# Line 1243 | Line 1638 | public class CompletableFutureTest exten
1638       * completion of source
1639       */
1640      public void testThenApplyAsync2() {
1641 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1641 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1642          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1643          f.completeExceptionally(new CFException());
1644          checkCompletedWithWrappedCFException(g);
# Line 1253 | Line 1648 | public class CompletableFutureTest exten
1648       * thenApplyAsync result completes exceptionally if action does
1649       */
1650      public void testThenApplyAsync3() {
1651 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1651 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1652          FailingFunction r = new FailingFunction();
1653          CompletableFuture<Integer> g = f.thenApplyAsync(r);
1654          f.complete(null);
# Line 1264 | Line 1659 | public class CompletableFutureTest exten
1659       * thenApplyAsync result completes exceptionally if source cancelled
1660       */
1661      public void testThenApplyAsync4() {
1662 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1662 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1663          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1664          assertTrue(f.cancel(true));
1665          checkCompletedWithWrappedCancellationException(g);
# Line 1275 | Line 1670 | public class CompletableFutureTest exten
1670       * completion of source
1671       */
1672      public void testThenAcceptAsync() {
1673 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1673 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1674          IncAction r = new IncAction();
1675          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1676          f.complete(one);
# Line 1288 | Line 1683 | public class CompletableFutureTest exten
1683       * completion of source
1684       */
1685      public void testThenAcceptAsync2() {
1686 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1686 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1687          IncAction r = new IncAction();
1688          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1689          f.completeExceptionally(new CFException());
# Line 1299 | Line 1694 | public class CompletableFutureTest exten
1694       * thenAcceptAsync result completes exceptionally if action does
1695       */
1696      public void testThenAcceptAsync3() {
1697 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1697 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1698          FailingConsumer r = new FailingConsumer();
1699          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1700          f.complete(null);
# Line 1310 | Line 1705 | public class CompletableFutureTest exten
1705       * thenAcceptAsync result completes exceptionally if source cancelled
1706       */
1707      public void testThenAcceptAsync4() {
1708 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1708 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1709          IncAction r = new IncAction();
1710          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1711          assertTrue(f.cancel(true));
# Line 1324 | Line 1719 | public class CompletableFutureTest exten
1719      public void testThenCombineAsync() {
1720          CompletableFuture<Integer> f, g, h;
1721  
1722 <        f = new CompletableFuture<Integer>();
1723 <        g = new CompletableFuture<Integer>();
1722 >        f = new CompletableFuture<>();
1723 >        g = new CompletableFuture<>();
1724          h = f.thenCombineAsync(g, subtract);
1725          f.complete(3);
1726          checkIncomplete(h);
1727          g.complete(1);
1728          checkCompletedNormally(h, 2);
1729  
1730 <        f = new CompletableFuture<Integer>();
1731 <        g = new CompletableFuture<Integer>();
1730 >        f = new CompletableFuture<>();
1731 >        g = new CompletableFuture<>();
1732          h = f.thenCombineAsync(g, subtract);
1733          g.complete(1);
1734          checkIncomplete(h);
1735          f.complete(3);
1736          checkCompletedNormally(h, 2);
1737  
1738 <        f = new CompletableFuture<Integer>();
1739 <        g = new CompletableFuture<Integer>();
1738 >        f = new CompletableFuture<>();
1739 >        g = new CompletableFuture<>();
1740          g.complete(1);
1741          f.complete(3);
1742          h = f.thenCombineAsync(g, subtract);
# Line 1355 | Line 1750 | public class CompletableFutureTest exten
1750      public void testThenCombineAsync2() {
1751          CompletableFuture<Integer> f, g, h;
1752  
1753 <        f = new CompletableFuture<Integer>();
1754 <        g = new CompletableFuture<Integer>();
1753 >        f = new CompletableFuture<>();
1754 >        g = new CompletableFuture<>();
1755          h = f.thenCombineAsync(g, subtract);
1756          f.completeExceptionally(new CFException());
1757          checkIncomplete(h);
1758          g.complete(1);
1759          checkCompletedWithWrappedCFException(h);
1760  
1761 <        f = new CompletableFuture<Integer>();
1762 <        g = new CompletableFuture<Integer>();
1761 >        f = new CompletableFuture<>();
1762 >        g = new CompletableFuture<>();
1763          h = f.thenCombineAsync(g, subtract);
1764          g.completeExceptionally(new CFException());
1765          checkIncomplete(h);
1766          f.complete(3);
1767          checkCompletedWithWrappedCFException(h);
1768  
1769 <        f = new CompletableFuture<Integer>();
1770 <        g = new CompletableFuture<Integer>();
1769 >        f = new CompletableFuture<>();
1770 >        g = new CompletableFuture<>();
1771          g.completeExceptionally(new CFException());
1772          f.complete(3);
1773          h = f.thenCombineAsync(g, subtract);
# Line 1383 | Line 1778 | public class CompletableFutureTest exten
1778       * thenCombineAsync result completes exceptionally if action does
1779       */
1780      public void testThenCombineAsync3() {
1781 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1782 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1781 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1782 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1783          FailingBiFunction r = new FailingBiFunction();
1784          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r);
1785          f.complete(one);
# Line 1401 | Line 1796 | public class CompletableFutureTest exten
1796      public void testThenCombineAsync4() {
1797          CompletableFuture<Integer> f, g, h;
1798  
1799 <        f = new CompletableFuture<Integer>();
1800 <        g = new CompletableFuture<Integer>();
1799 >        f = new CompletableFuture<>();
1800 >        g = new CompletableFuture<>();
1801          h = f.thenCombineAsync(g, subtract);
1802          assertTrue(f.cancel(true));
1803          checkIncomplete(h);
1804          g.complete(1);
1805          checkCompletedWithWrappedCancellationException(h);
1806  
1807 <        f = new CompletableFuture<Integer>();
1808 <        g = new CompletableFuture<Integer>();
1807 >        f = new CompletableFuture<>();
1808 >        g = new CompletableFuture<>();
1809          h = f.thenCombineAsync(g, subtract);
1810          assertTrue(g.cancel(true));
1811          checkIncomplete(h);
1812          f.complete(3);
1813          checkCompletedWithWrappedCancellationException(h);
1814  
1815 <        f = new CompletableFuture<Integer>();
1816 <        g = new CompletableFuture<Integer>();
1815 >        f = new CompletableFuture<>();
1816 >        g = new CompletableFuture<>();
1817          g.complete(3);
1818          assertTrue(f.cancel(true));
1819          h = f.thenCombineAsync(g, subtract);
1820          checkCompletedWithWrappedCancellationException(h);
1821  
1822 <        f = new CompletableFuture<Integer>();
1823 <        g = new CompletableFuture<Integer>();
1822 >        f = new CompletableFuture<>();
1823 >        g = new CompletableFuture<>();
1824          f.complete(3);
1825          assertTrue(g.cancel(true));
1826          h = f.thenCombineAsync(g, subtract);
# Line 1437 | Line 1832 | public class CompletableFutureTest exten
1832       * completion of sources
1833       */
1834      public void testThenAcceptBothAsync() {
1835 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1836 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1837 <        AddAction r = new AddAction();
1838 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1839 <        f.complete(one);
1840 <        checkIncomplete(g);
1841 <        f2.complete(two);
1842 <        checkCompletedNormally(g, null);
1843 <        assertEquals(r.value, 3);
1835 >        CompletableFuture<Integer> f, g;
1836 >        CompletableFuture<Void> h;
1837 >        SubtractAction r;
1838 >
1839 >        f = new CompletableFuture<>();
1840 >        g = new CompletableFuture<>();
1841 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1842 >        f.complete(3);
1843 >        checkIncomplete(h);
1844 >        g.complete(1);
1845 >        checkCompletedNormally(h, null);
1846 >        assertEquals(r.value, 2);
1847 >
1848 >        f = new CompletableFuture<>();
1849 >        g = new CompletableFuture<>();
1850 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1851 >        g.complete(1);
1852 >        checkIncomplete(h);
1853 >        f.complete(3);
1854 >        checkCompletedNormally(h, null);
1855 >        assertEquals(r.value, 2);
1856 >
1857 >        f = new CompletableFuture<>();
1858 >        g = new CompletableFuture<>();
1859 >        g.complete(1);
1860 >        f.complete(3);
1861 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1862 >        checkCompletedNormally(h, null);
1863 >        assertEquals(r.value, 2);
1864      }
1865  
1866      /**
# Line 1453 | Line 1868 | public class CompletableFutureTest exten
1868       * completion of source
1869       */
1870      public void testThenAcceptBothAsync2() {
1871 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1872 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1873 <        AddAction r = new AddAction();
1874 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1871 >        CompletableFuture<Integer> f, g;
1872 >        CompletableFuture<Void> h;
1873 >        SubtractAction r;
1874 >
1875 >        f = new CompletableFuture<>();
1876 >        g = new CompletableFuture<>();
1877 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1878          f.completeExceptionally(new CFException());
1879 <        f2.complete(two);
1880 <        checkCompletedWithWrappedCFException(g);
1879 >        checkIncomplete(h);
1880 >        g.complete(1);
1881 >        checkCompletedWithWrappedCFException(h);
1882  
1883 <        r = new AddAction();
1884 <        f = new CompletableFuture<Integer>();
1885 <        f2 = new CompletableFuture<Integer>();
1886 <        g = f.thenAcceptBothAsync(f2, r);
1887 <        f.complete(one);
1888 <        f2.completeExceptionally(new CFException());
1889 <        checkCompletedWithWrappedCFException(g);
1883 >        f = new CompletableFuture<>();
1884 >        g = new CompletableFuture<>();
1885 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1886 >        g.completeExceptionally(new CFException());
1887 >        checkIncomplete(h);
1888 >        f.complete(3);
1889 >        checkCompletedWithWrappedCFException(h);
1890 >
1891 >        f = new CompletableFuture<>();
1892 >        g = new CompletableFuture<>();
1893 >        f.complete(3);
1894 >        g.completeExceptionally(new CFException());
1895 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1896 >        checkCompletedWithWrappedCFException(h);
1897 >
1898 >        f = new CompletableFuture<>();
1899 >        g = new CompletableFuture<>();
1900 >        f.completeExceptionally(new CFException());
1901 >        g.complete(3);
1902 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1903 >        checkCompletedWithWrappedCFException(h);
1904      }
1905  
1906      /**
1907       * thenAcceptBothAsync result completes exceptionally if action does
1908       */
1909      public void testThenAcceptBothAsync3() {
1910 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1911 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1912 <        FailingBiConsumer r = new FailingBiConsumer();
1480 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1481 <        f.complete(one);
1482 <        checkIncomplete(g);
1483 <        f2.complete(two);
1484 <        checkCompletedWithWrappedCFException(g);
1485 <    }
1910 >        CompletableFuture<Integer> f, g;
1911 >        CompletableFuture<Void> h;
1912 >        FailingBiConsumer r;
1913  
1914 <    /**
1915 <     * thenAcceptBothAsync result completes exceptionally if either source cancelled
1916 <     */
1917 <    public void testThenAcceptBothAsync4() {
1918 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1919 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1920 <        AddAction r = new AddAction();
1494 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1495 <        assertTrue(f.cancel(true));
1496 <        f2.complete(two);
1497 <        checkCompletedWithWrappedCancellationException(g);
1914 >        f = new CompletableFuture<>();
1915 >        g = new CompletableFuture<>();
1916 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1917 >        f.complete(3);
1918 >        checkIncomplete(h);
1919 >        g.complete(1);
1920 >        checkCompletedWithWrappedCFException(h);
1921  
1922 <        r = new AddAction();
1923 <        f = new CompletableFuture<Integer>();
1924 <        f2 = new CompletableFuture<Integer>();
1925 <        g = f.thenAcceptBothAsync(f2, r);
1926 <        f.complete(one);
1927 <        assertTrue(f2.cancel(true));
1505 <        checkCompletedWithWrappedCancellationException(g);
1922 >        f = new CompletableFuture<>();
1923 >        g = new CompletableFuture<>();
1924 >        f.complete(3);
1925 >        g.complete(1);
1926 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1927 >        checkCompletedWithWrappedCFException(h);
1928      }
1929  
1930      /**
1931 <     * runAfterBothAsync result completes normally after normal
1510 <     * completion of sources
1931 >     * thenAcceptBothAsync result completes exceptionally if either source cancelled
1932       */
1933 <    public void testRunAfterBothAsync() {
1934 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1935 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1936 <        Noop r = new Noop();
1516 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1517 <        f.complete(one);
1518 <        checkIncomplete(g);
1519 <        f2.complete(two);
1520 <        checkCompletedNormally(g, null);
1521 <        assertTrue(r.ran);
1522 <    }
1933 >    public void testThenAcceptBothAsync4() {
1934 >        CompletableFuture<Integer> f, g;
1935 >        CompletableFuture<Void> h;
1936 >        SubtractAction r;
1937  
1938 <    /**
1939 <     * runAfterBothAsync result completes exceptionally after exceptional
1940 <     * completion of source
1941 <     */
1942 <    public void testRunAfterBothAsync2() {
1943 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1944 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1531 <        Noop r = new Noop();
1532 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1533 <        f.completeExceptionally(new CFException());
1534 <        f2.complete(two);
1535 <        checkCompletedWithWrappedCFException(g);
1938 >        f = new CompletableFuture<>();
1939 >        g = new CompletableFuture<>();
1940 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1941 >        assertTrue(f.cancel(true));
1942 >        checkIncomplete(h);
1943 >        g.complete(1);
1944 >        checkCompletedWithWrappedCancellationException(h);
1945  
1946 <        r = new Noop();
1947 <        f = new CompletableFuture<Integer>();
1948 <        f2 = new CompletableFuture<Integer>();
1949 <        g = f.runAfterBothAsync(f2, r);
1950 <        f.complete(one);
1951 <        f2.completeExceptionally(new CFException());
1952 <        checkCompletedWithWrappedCFException(g);
1544 <    }
1946 >        f = new CompletableFuture<>();
1947 >        g = new CompletableFuture<>();
1948 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1949 >        assertTrue(g.cancel(true));
1950 >        checkIncomplete(h);
1951 >        f.complete(3);
1952 >        checkCompletedWithWrappedCancellationException(h);
1953  
1954 <    /**
1955 <     * runAfterBothAsync result completes exceptionally if action does
1956 <     */
1957 <    public void testRunAfterBothAsync3() {
1958 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1959 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1552 <        FailingNoop r = new FailingNoop();
1553 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1554 <        f.complete(one);
1555 <        checkIncomplete(g);
1556 <        f2.complete(two);
1557 <        checkCompletedWithWrappedCFException(g);
1558 <    }
1954 >        f = new CompletableFuture<>();
1955 >        g = new CompletableFuture<>();
1956 >        f.complete(3);
1957 >        assertTrue(g.cancel(true));
1958 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1959 >        checkCompletedWithWrappedCancellationException(h);
1960  
1961 <    /**
1962 <     * runAfterBothAsync result completes exceptionally if either source cancelled
1562 <     */
1563 <    public void testRunAfterBothAsync4() {
1564 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1565 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1566 <        Noop r = new Noop();
1567 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1961 >        f = new CompletableFuture<>();
1962 >        g = new CompletableFuture<>();
1963          assertTrue(f.cancel(true));
1964 <        f2.complete(two);
1965 <        checkCompletedWithWrappedCancellationException(g);
1966 <
1572 <        r = new Noop();
1573 <        f = new CompletableFuture<Integer>();
1574 <        f2 = new CompletableFuture<Integer>();
1575 <        g = f.runAfterBothAsync(f2, r);
1576 <        f.complete(one);
1577 <        assertTrue(f2.cancel(true));
1578 <        checkCompletedWithWrappedCancellationException(g);
1964 >        g.complete(3);
1965 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1966 >        checkCompletedWithWrappedCancellationException(h);
1967      }
1968  
1969      /**
# Line 1583 | Line 1971 | public class CompletableFutureTest exten
1971       * completion of sources
1972       */
1973      public void testApplyToEitherAsync() {
1974 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1975 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1974 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1975 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1976          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1977          f.complete(one);
1978          checkCompletedNormally(g, two);
1979  
1980 <        f = new CompletableFuture<Integer>();
1980 >        f = new CompletableFuture<>();
1981          f.complete(one);
1982 <        f2 = new CompletableFuture<Integer>();
1982 >        f2 = new CompletableFuture<>();
1983          g = f.applyToEitherAsync(f2, inc);
1984          checkCompletedNormally(g, two);
1985      }
# Line 1601 | Line 1989 | public class CompletableFutureTest exten
1989       * completion of source
1990       */
1991      public void testApplyToEitherAsync2() {
1992 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1993 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1992 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1993 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1994          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1995          f.completeExceptionally(new CFException());
1996          checkCompletedWithWrappedCFException(g);
1997  
1998 <        f = new CompletableFuture<Integer>();
1999 <        f2 = new CompletableFuture<Integer>();
1998 >        f = new CompletableFuture<>();
1999 >        f2 = new CompletableFuture<>();
2000          f2.completeExceptionally(new CFException());
2001          g = f.applyToEitherAsync(f2, inc);
2002          f.complete(one);
# Line 1619 | Line 2007 | public class CompletableFutureTest exten
2007       * applyToEitherAsync result completes exceptionally if action does
2008       */
2009      public void testApplyToEitherAsync3() {
2010 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2011 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2010 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2011 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2012          FailingFunction r = new FailingFunction();
2013          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
2014          f.complete(one);
# Line 1631 | Line 2019 | public class CompletableFutureTest exten
2019       * applyToEitherAsync result completes exceptionally if either source cancelled
2020       */
2021      public void testApplyToEitherAsync4() {
2022 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2023 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2022 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2023 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2024          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2025          assertTrue(f.cancel(true));
2026          checkCompletedWithWrappedCancellationException(g);
2027  
2028 <        f = new CompletableFuture<Integer>();
2029 <        f2 = new CompletableFuture<Integer>();
2028 >        f = new CompletableFuture<>();
2029 >        f2 = new CompletableFuture<>();
2030          assertTrue(f2.cancel(true));
2031          g = f.applyToEitherAsync(f2, inc);
2032          checkCompletedWithWrappedCancellationException(g);
# Line 1649 | Line 2037 | public class CompletableFutureTest exten
2037       * completion of sources
2038       */
2039      public void testAcceptEitherAsync() {
2040 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2041 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2040 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2041 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2042          IncAction r = new IncAction();
2043          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2044          f.complete(one);
# Line 1658 | Line 2046 | public class CompletableFutureTest exten
2046          assertEquals(r.value, 2);
2047  
2048          r = new IncAction();
2049 <        f = new CompletableFuture<Integer>();
2049 >        f = new CompletableFuture<>();
2050          f.complete(one);
2051 <        f2 = new CompletableFuture<Integer>();
2051 >        f2 = new CompletableFuture<>();
2052          g = f.acceptEitherAsync(f2, r);
2053          checkCompletedNormally(g, null);
2054          assertEquals(r.value, 2);
# Line 1671 | Line 2059 | public class CompletableFutureTest exten
2059       * completion of source
2060       */
2061      public void testAcceptEitherAsync2() {
2062 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2063 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2062 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2063 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2064          IncAction r = new IncAction();
2065          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2066          f.completeExceptionally(new CFException());
2067          checkCompletedWithWrappedCFException(g);
2068  
2069          r = new IncAction();
2070 <        f = new CompletableFuture<Integer>();
2071 <        f2 = new CompletableFuture<Integer>();
2070 >        f = new CompletableFuture<>();
2071 >        f2 = new CompletableFuture<>();
2072          f2.completeExceptionally(new CFException());
2073          g = f.acceptEitherAsync(f2, r);
2074          f.complete(one);
# Line 1691 | Line 2079 | public class CompletableFutureTest exten
2079       * acceptEitherAsync result completes exceptionally if action does
2080       */
2081      public void testAcceptEitherAsync3() {
2082 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2083 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2082 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2083 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2084          FailingConsumer r = new FailingConsumer();
2085          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2086          f.complete(one);
# Line 1704 | Line 2092 | public class CompletableFutureTest exten
2092       * source cancelled
2093       */
2094      public void testAcceptEitherAsync4() {
2095 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2096 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2095 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2096 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2097          IncAction r = new IncAction();
2098          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2099          assertTrue(f.cancel(true));
2100          checkCompletedWithWrappedCancellationException(g);
2101  
2102          r = new IncAction();
2103 <        f = new CompletableFuture<Integer>();
2104 <        f2 = new CompletableFuture<Integer>();
2103 >        f = new CompletableFuture<>();
2104 >        f2 = new CompletableFuture<>();
2105          assertTrue(f2.cancel(true));
2106          g = f.acceptEitherAsync(f2, r);
2107          checkCompletedWithWrappedCancellationException(g);
# Line 1724 | Line 2112 | public class CompletableFutureTest exten
2112       * completion of sources
2113       */
2114      public void testRunAfterEitherAsync() {
2115 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2116 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2115 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2116 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2117          Noop r = new Noop();
2118          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2119          f.complete(one);
# Line 1733 | Line 2121 | public class CompletableFutureTest exten
2121          assertTrue(r.ran);
2122  
2123          r = new Noop();
2124 <        f = new CompletableFuture<Integer>();
2124 >        f = new CompletableFuture<>();
2125          f.complete(one);
2126 <        f2 = new CompletableFuture<Integer>();
2126 >        f2 = new CompletableFuture<>();
2127          g = f.runAfterEitherAsync(f2, r);
2128          checkCompletedNormally(g, null);
2129          assertTrue(r.ran);
# Line 1746 | Line 2134 | public class CompletableFutureTest exten
2134       * completion of source
2135       */
2136      public void testRunAfterEitherAsync2() {
2137 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2138 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2137 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2138 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2139          Noop r = new Noop();
2140          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2141          f.completeExceptionally(new CFException());
2142          checkCompletedWithWrappedCFException(g);
2143  
2144          r = new Noop();
2145 <        f = new CompletableFuture<Integer>();
2146 <        f2 = new CompletableFuture<Integer>();
2145 >        f = new CompletableFuture<>();
2146 >        f2 = new CompletableFuture<>();
2147          f2.completeExceptionally(new CFException());
2148          g = f.runAfterEitherAsync(f2, r);
2149          f.complete(one);
# Line 1766 | Line 2154 | public class CompletableFutureTest exten
2154       * runAfterEitherAsync result completes exceptionally if action does
2155       */
2156      public void testRunAfterEitherAsync3() {
2157 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2158 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2157 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2158 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2159          FailingNoop r = new FailingNoop();
2160          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2161          f.complete(one);
# Line 1779 | Line 2167 | public class CompletableFutureTest exten
2167       * source cancelled
2168       */
2169      public void testRunAfterEitherAsync4() {
2170 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2171 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2170 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2171 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2172          Noop r = new Noop();
2173          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2174          assertTrue(f.cancel(true));
2175          checkCompletedWithWrappedCancellationException(g);
2176  
2177          r = new Noop();
2178 <        f = new CompletableFuture<Integer>();
2179 <        f2 = new CompletableFuture<Integer>();
2178 >        f = new CompletableFuture<>();
2179 >        f2 = new CompletableFuture<>();
2180          assertTrue(f2.cancel(true));
2181          g = f.runAfterEitherAsync(f2, r);
2182          checkCompletedWithWrappedCancellationException(g);
# Line 1802 | Line 2190 | public class CompletableFutureTest exten
2190          CompletableFuture<Integer> f, g;
2191          CompletableFutureInc r;
2192  
2193 <        f = new CompletableFuture<Integer>();
2193 >        f = new CompletableFuture<>();
2194          g = f.thenComposeAsync(r = new CompletableFutureInc());
2195          f.complete(one);
2196          checkCompletedNormally(g, two);
2197  
2198 <        f = new CompletableFuture<Integer>();
2198 >        f = new CompletableFuture<>();
2199          f.complete(one);
2200          g = f.thenComposeAsync(r = new CompletableFutureInc());
2201          checkCompletedNormally(g, two);
# Line 1821 | Line 2209 | public class CompletableFutureTest exten
2209          CompletableFuture<Integer> f, g;
2210          CompletableFutureInc r;
2211  
2212 <        f = new CompletableFuture<Integer>();
2212 >        f = new CompletableFuture<>();
2213          g = f.thenComposeAsync(r = new CompletableFutureInc());
2214          f.completeExceptionally(new CFException());
2215          checkCompletedWithWrappedCFException(g);
2216          assertFalse(r.ran);
2217  
2218 <        f = new CompletableFuture<Integer>();
2218 >        f = new CompletableFuture<>();
2219          f.completeExceptionally(new CFException());
2220          g = f.thenComposeAsync(r = new CompletableFutureInc());
2221          checkCompletedWithWrappedCFException(g);
# Line 1840 | Line 2228 | public class CompletableFutureTest exten
2228      public void testThenComposeAsync3() {
2229          CompletableFuture<Integer> f, g;
2230          FailingCompletableFutureFunction r;
2231 <        
2232 <        f = new CompletableFuture<Integer>();
2231 >
2232 >        f = new CompletableFuture<>();
2233          g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2234          f.complete(one);
2235          checkCompletedWithWrappedCFException(g);
2236 <        
2237 <        f = new CompletableFuture<Integer>();
2236 >
2237 >        f = new CompletableFuture<>();
2238          f.complete(one);
2239          g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2240          checkCompletedWithWrappedCFException(g);
# Line 1859 | Line 2247 | public class CompletableFutureTest exten
2247          CompletableFuture<Integer> f, g;
2248          CompletableFutureInc r;
2249  
2250 <        f = new CompletableFuture<Integer>();
2250 >        f = new CompletableFuture<>();
2251          g = f.thenComposeAsync(r = new CompletableFutureInc());
2252          assertTrue(f.cancel(true));
2253          checkCompletedWithWrappedCancellationException(g);
2254  
2255 <        f = new CompletableFuture<Integer>();
2255 >        f = new CompletableFuture<>();
2256          assertTrue(f.cancel(true));
2257          g = f.thenComposeAsync(r = new CompletableFutureInc());
2258          checkCompletedWithWrappedCancellationException(g);
2259      }
2260  
1873
2261      // async with explicit executors
2262  
2263      /**
2264       * thenRunAsync result completes normally after normal completion of source
2265       */
2266      public void testThenRunAsyncE() {
2267 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2267 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2268          Noop r = new Noop();
2269          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2270          f.complete(null);
2271          checkCompletedNormally(g, null);
2272  
2273          // reordered version
2274 <        f = new CompletableFuture<Integer>();
2274 >        f = new CompletableFuture<>();
2275          f.complete(null);
2276          r = new Noop();
2277          g = f.thenRunAsync(r, new ThreadExecutor());
# Line 1896 | Line 2283 | public class CompletableFutureTest exten
2283       * completion of source
2284       */
2285      public void testThenRunAsync2E() {
2286 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2286 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2287          Noop r = new Noop();
2288          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2289          f.completeExceptionally(new CFException());
2290          try {
2291              g.join();
2292              shouldThrow();
2293 <        } catch (Exception ok) {
1907 <        }
2293 >        } catch (CompletionException success) {}
2294          checkCompletedWithWrappedCFException(g);
2295      }
2296  
# Line 1912 | Line 2298 | public class CompletableFutureTest exten
2298       * thenRunAsync result completes exceptionally if action does
2299       */
2300      public void testThenRunAsync3E() {
2301 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2301 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2302          FailingNoop r = new FailingNoop();
2303          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2304          f.complete(null);
# Line 1923 | Line 2309 | public class CompletableFutureTest exten
2309       * thenRunAsync result completes exceptionally if source cancelled
2310       */
2311      public void testThenRunAsync4E() {
2312 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2312 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2313          Noop r = new Noop();
2314          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2315          assertTrue(f.cancel(true));
# Line 1934 | Line 2320 | public class CompletableFutureTest exten
2320       * thenApplyAsync result completes normally after normal completion of source
2321       */
2322      public void testThenApplyAsyncE() {
2323 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2323 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2324          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2325          f.complete(one);
2326          checkCompletedNormally(g, two);
# Line 1945 | Line 2331 | public class CompletableFutureTest exten
2331       * completion of source
2332       */
2333      public void testThenApplyAsync2E() {
2334 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2334 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2335          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2336          f.completeExceptionally(new CFException());
2337          checkCompletedWithWrappedCFException(g);
# Line 1955 | Line 2341 | public class CompletableFutureTest exten
2341       * thenApplyAsync result completes exceptionally if action does
2342       */
2343      public void testThenApplyAsync3E() {
2344 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2344 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2345          FailingFunction r = new FailingFunction();
2346          CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
2347          f.complete(null);
# Line 1966 | Line 2352 | public class CompletableFutureTest exten
2352       * thenApplyAsync result completes exceptionally if source cancelled
2353       */
2354      public void testThenApplyAsync4E() {
2355 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2355 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2356          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2357          assertTrue(f.cancel(true));
2358          checkCompletedWithWrappedCancellationException(g);
# Line 1977 | Line 2363 | public class CompletableFutureTest exten
2363       * completion of source
2364       */
2365      public void testThenAcceptAsyncE() {
2366 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2366 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2367          IncAction r = new IncAction();
2368          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2369          f.complete(one);
# Line 1990 | Line 2376 | public class CompletableFutureTest exten
2376       * completion of source
2377       */
2378      public void testThenAcceptAsync2E() {
2379 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2379 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2380          IncAction r = new IncAction();
2381          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2382          f.completeExceptionally(new CFException());
# Line 2001 | Line 2387 | public class CompletableFutureTest exten
2387       * thenAcceptAsync result completes exceptionally if action does
2388       */
2389      public void testThenAcceptAsync3E() {
2390 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2390 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2391          FailingConsumer r = new FailingConsumer();
2392          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2393          f.complete(null);
# Line 2012 | Line 2398 | public class CompletableFutureTest exten
2398       * thenAcceptAsync result completes exceptionally if source cancelled
2399       */
2400      public void testThenAcceptAsync4E() {
2401 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2401 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2402          IncAction r = new IncAction();
2403          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2404          assertTrue(f.cancel(true));
# Line 2028 | Line 2414 | public class CompletableFutureTest exten
2414          ThreadExecutor e = new ThreadExecutor();
2415          int count = 0;
2416  
2417 <        f = new CompletableFuture<Integer>();
2418 <        g = new CompletableFuture<Integer>();
2417 >        f = new CompletableFuture<>();
2418 >        g = new CompletableFuture<>();
2419          h = f.thenCombineAsync(g, subtract, e);
2420          f.complete(3);
2421          checkIncomplete(h);
# Line 2037 | Line 2423 | public class CompletableFutureTest exten
2423          checkCompletedNormally(h, 2);
2424          assertEquals(++count, e.count.get());
2425  
2426 <        f = new CompletableFuture<Integer>();
2427 <        g = new CompletableFuture<Integer>();
2426 >        f = new CompletableFuture<>();
2427 >        g = new CompletableFuture<>();
2428          h = f.thenCombineAsync(g, subtract, e);
2429          g.complete(1);
2430          checkIncomplete(h);
# Line 2046 | Line 2432 | public class CompletableFutureTest exten
2432          checkCompletedNormally(h, 2);
2433          assertEquals(++count, e.count.get());
2434  
2435 <        f = new CompletableFuture<Integer>();
2436 <        g = new CompletableFuture<Integer>();
2435 >        f = new CompletableFuture<>();
2436 >        g = new CompletableFuture<>();
2437          g.complete(1);
2438          f.complete(3);
2439          h = f.thenCombineAsync(g, subtract, e);
# Line 2064 | Line 2450 | public class CompletableFutureTest exten
2450          ThreadExecutor e = new ThreadExecutor();
2451          int count = 0;
2452  
2453 <        f = new CompletableFuture<Integer>();
2454 <        g = new CompletableFuture<Integer>();
2453 >        f = new CompletableFuture<>();
2454 >        g = new CompletableFuture<>();
2455          h = f.thenCombineAsync(g, subtract, e);
2456          f.completeExceptionally(new CFException());
2457          checkIncomplete(h);
2458          g.complete(1);
2459          checkCompletedWithWrappedCFException(h);
2460  
2461 <        f = new CompletableFuture<Integer>();
2462 <        g = new CompletableFuture<Integer>();
2461 >        f = new CompletableFuture<>();
2462 >        g = new CompletableFuture<>();
2463          h = f.thenCombineAsync(g, subtract, e);
2464          g.completeExceptionally(new CFException());
2465          checkIncomplete(h);
2466          f.complete(3);
2467          checkCompletedWithWrappedCFException(h);
2468  
2469 <        f = new CompletableFuture<Integer>();
2470 <        g = new CompletableFuture<Integer>();
2469 >        f = new CompletableFuture<>();
2470 >        g = new CompletableFuture<>();
2471          g.completeExceptionally(new CFException());
2472          h = f.thenCombineAsync(g, subtract, e);
2473          checkIncomplete(h);
# Line 2095 | Line 2481 | public class CompletableFutureTest exten
2481       * thenCombineAsync result completes exceptionally if action does
2482       */
2483      public void testThenCombineAsync3E() {
2484 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2485 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2484 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2485 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2486          FailingBiFunction r = new FailingBiFunction();
2487          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor());
2488          f.complete(one);
# Line 2114 | Line 2500 | public class CompletableFutureTest exten
2500          CompletableFuture<Integer> f, g, h;
2501          ThreadExecutor e = new ThreadExecutor();
2502  
2503 <        f = new CompletableFuture<Integer>();
2504 <        g = new CompletableFuture<Integer>();
2503 >        f = new CompletableFuture<>();
2504 >        g = new CompletableFuture<>();
2505          h = f.thenCombineAsync(g, subtract, e);
2506          assertTrue(f.cancel(true));
2507          checkIncomplete(h);
2508          g.complete(1);
2509          checkCompletedWithWrappedCancellationException(h);
2510  
2511 <        f = new CompletableFuture<Integer>();
2512 <        g = new CompletableFuture<Integer>();
2511 >        f = new CompletableFuture<>();
2512 >        g = new CompletableFuture<>();
2513          h = f.thenCombineAsync(g, subtract, e);
2514          assertTrue(g.cancel(true));
2515          checkIncomplete(h);
2516          f.complete(3);
2517          checkCompletedWithWrappedCancellationException(h);
2518  
2519 <        f = new CompletableFuture<Integer>();
2520 <        g = new CompletableFuture<Integer>();
2519 >        f = new CompletableFuture<>();
2520 >        g = new CompletableFuture<>();
2521          assertTrue(g.cancel(true));
2522          h = f.thenCombineAsync(g, subtract, e);
2523          checkIncomplete(h);
2524          f.complete(3);
2525          checkCompletedWithWrappedCancellationException(h);
2526  
2527 <        f = new CompletableFuture<Integer>();
2528 <        g = new CompletableFuture<Integer>();
2527 >        f = new CompletableFuture<>();
2528 >        g = new CompletableFuture<>();
2529          assertTrue(f.cancel(true));
2530          assertTrue(g.cancel(true));
2531          h = f.thenCombineAsync(g, subtract, e);
# Line 2153 | Line 2539 | public class CompletableFutureTest exten
2539       * completion of sources
2540       */
2541      public void testThenAcceptBothAsyncE() {
2542 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2543 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2544 <        AddAction r = new AddAction();
2545 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2546 <        f.complete(one);
2547 <        checkIncomplete(g);
2548 <        f2.complete(two);
2549 <        checkCompletedNormally(g, null);
2550 <        assertEquals(r.value, 3);
2542 >        CompletableFuture<Integer> f, g;
2543 >        CompletableFuture<Void> h;
2544 >        SubtractAction r;
2545 >        ThreadExecutor e = new ThreadExecutor();
2546 >
2547 >        f = new CompletableFuture<>();
2548 >        g = new CompletableFuture<>();
2549 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2550 >        f.complete(3);
2551 >        checkIncomplete(h);
2552 >        g.complete(1);
2553 >        checkCompletedNormally(h, null);
2554 >        assertEquals(r.value, 2);
2555 >
2556 >        f = new CompletableFuture<>();
2557 >        g = new CompletableFuture<>();
2558 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2559 >        g.complete(1);
2560 >        checkIncomplete(h);
2561 >        f.complete(3);
2562 >        checkCompletedNormally(h, null);
2563 >        assertEquals(r.value, 2);
2564 >
2565 >        f = new CompletableFuture<>();
2566 >        g = new CompletableFuture<>();
2567 >        g.complete(1);
2568 >        f.complete(3);
2569 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2570 >        checkCompletedNormally(h, null);
2571 >        assertEquals(r.value, 2);
2572 >
2573 >        assertEquals(3, e.count.get());
2574      }
2575  
2576      /**
# Line 2169 | Line 2578 | public class CompletableFutureTest exten
2578       * completion of source
2579       */
2580      public void testThenAcceptBothAsync2E() {
2581 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2582 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2583 <        AddAction r = new AddAction();
2584 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2581 >        CompletableFuture<Integer> f, g;
2582 >        CompletableFuture<Void> h;
2583 >        SubtractAction r;
2584 >        ThreadExecutor e = new ThreadExecutor();
2585 >
2586 >        f = new CompletableFuture<>();
2587 >        g = new CompletableFuture<>();
2588 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2589          f.completeExceptionally(new CFException());
2590 <        f2.complete(two);
2591 <        checkCompletedWithWrappedCFException(g);
2590 >        checkIncomplete(h);
2591 >        g.complete(1);
2592 >        checkCompletedWithWrappedCFException(h);
2593  
2594 <        r = new AddAction();
2595 <        f = new CompletableFuture<Integer>();
2596 <        f2 = new CompletableFuture<Integer>();
2597 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2598 <        f.complete(one);
2599 <        f2.completeExceptionally(new CFException());
2600 <        checkCompletedWithWrappedCFException(g);
2594 >        f = new CompletableFuture<>();
2595 >        g = new CompletableFuture<>();
2596 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2597 >        g.completeExceptionally(new CFException());
2598 >        checkIncomplete(h);
2599 >        f.complete(3);
2600 >        checkCompletedWithWrappedCFException(h);
2601 >
2602 >        f = new CompletableFuture<>();
2603 >        g = new CompletableFuture<>();
2604 >        f.complete(3);
2605 >        g.completeExceptionally(new CFException());
2606 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2607 >        checkCompletedWithWrappedCFException(h);
2608 >
2609 >        f = new CompletableFuture<>();
2610 >        g = new CompletableFuture<>();
2611 >        f.completeExceptionally(new CFException());
2612 >        g.complete(3);
2613 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2614 >        checkCompletedWithWrappedCFException(h);
2615 >
2616 >        assertEquals(0, e.count.get());
2617      }
2618  
2619      /**
2620       * thenAcceptBothAsync result completes exceptionally if action does
2621       */
2622      public void testThenAcceptBothAsync3E() {
2623 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2624 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2625 <        FailingBiConsumer r = new FailingBiConsumer();
2626 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2197 <        f.complete(one);
2198 <        checkIncomplete(g);
2199 <        f2.complete(two);
2200 <        checkCompletedWithWrappedCFException(g);
2201 <    }
2623 >        CompletableFuture<Integer> f, g;
2624 >        CompletableFuture<Void> h;
2625 >        FailingBiConsumer r;
2626 >        ThreadExecutor e = new ThreadExecutor();
2627  
2628 <    /**
2629 <     * thenAcceptBothAsync result completes exceptionally if either source cancelled
2630 <     */
2631 <    public void testThenAcceptBothAsync4E() {
2632 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2633 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2634 <        AddAction r = new AddAction();
2210 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2211 <        assertTrue(f.cancel(true));
2212 <        f2.complete(two);
2213 <        checkCompletedWithWrappedCancellationException(g);
2628 >        f = new CompletableFuture<>();
2629 >        g = new CompletableFuture<>();
2630 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2631 >        f.complete(3);
2632 >        checkIncomplete(h);
2633 >        g.complete(1);
2634 >        checkCompletedWithWrappedCFException(h);
2635  
2636 <        r = new AddAction();
2637 <        f = new CompletableFuture<Integer>();
2638 <        f2 = new CompletableFuture<Integer>();
2639 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2640 <        f.complete(one);
2641 <        assertTrue(f2.cancel(true));
2221 <        checkCompletedWithWrappedCancellationException(g);
2222 <    }
2636 >        f = new CompletableFuture<>();
2637 >        g = new CompletableFuture<>();
2638 >        f.complete(3);
2639 >        g.complete(1);
2640 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2641 >        checkCompletedWithWrappedCFException(h);
2642  
2643 <    /**
2225 <     * runAfterBothAsync result completes normally after normal
2226 <     * completion of sources
2227 <     */
2228 <    public void testRunAfterBothAsyncE() {
2229 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2230 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2231 <        Noop r = new Noop();
2232 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2233 <        f.complete(one);
2234 <        checkIncomplete(g);
2235 <        f2.complete(two);
2236 <        checkCompletedNormally(g, null);
2237 <        assertTrue(r.ran);
2643 >        assertEquals(2, e.count.get());
2644      }
2645  
2646      /**
2647 <     * runAfterBothAsync result completes exceptionally after exceptional
2242 <     * completion of source
2647 >     * thenAcceptBothAsync result completes exceptionally if either source cancelled
2648       */
2649 <    public void testRunAfterBothAsync2E() {
2650 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2651 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2652 <        Noop r = new Noop();
2653 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2249 <        f.completeExceptionally(new CFException());
2250 <        f2.complete(two);
2251 <        checkCompletedWithWrappedCFException(g);
2649 >    public void testThenAcceptBothAsync4E() {
2650 >        CompletableFuture<Integer> f, g;
2651 >        CompletableFuture<Void> h;
2652 >        SubtractAction r;
2653 >        ThreadExecutor e = new ThreadExecutor();
2654  
2655 <        r = new Noop();
2656 <        f = new CompletableFuture<Integer>();
2657 <        f2 = new CompletableFuture<Integer>();
2658 <        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2659 <        f.complete(one);
2660 <        f2.completeExceptionally(new CFException());
2661 <        checkCompletedWithWrappedCFException(g);
2260 <    }
2655 >        f = new CompletableFuture<>();
2656 >        g = new CompletableFuture<>();
2657 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2658 >        assertTrue(f.cancel(true));
2659 >        checkIncomplete(h);
2660 >        g.complete(1);
2661 >        checkCompletedWithWrappedCancellationException(h);
2662  
2663 <    /**
2664 <     * runAfterBothAsync result completes exceptionally if action does
2665 <     */
2666 <    public void testRunAfterBothAsync3E() {
2667 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2668 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2669 <        FailingNoop r = new FailingNoop();
2269 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2270 <        f.complete(one);
2271 <        checkIncomplete(g);
2272 <        f2.complete(two);
2273 <        checkCompletedWithWrappedCFException(g);
2274 <    }
2663 >        f = new CompletableFuture<>();
2664 >        g = new CompletableFuture<>();
2665 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2666 >        assertTrue(g.cancel(true));
2667 >        checkIncomplete(h);
2668 >        f.complete(3);
2669 >        checkCompletedWithWrappedCancellationException(h);
2670  
2671 <    /**
2672 <     * runAfterBothAsync result completes exceptionally if either source cancelled
2673 <     */
2674 <    public void testRunAfterBothAsync4E() {
2675 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2676 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2677 <        Noop r = new Noop();
2678 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2671 >        f = new CompletableFuture<>();
2672 >        g = new CompletableFuture<>();
2673 >        f.complete(3);
2674 >        assertTrue(g.cancel(true));
2675 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2676 >        checkCompletedWithWrappedCancellationException(h);
2677 >
2678 >        f = new CompletableFuture<>();
2679 >        g = new CompletableFuture<>();
2680          assertTrue(f.cancel(true));
2681 <        f2.complete(two);
2682 <        checkCompletedWithWrappedCancellationException(g);
2681 >        g.complete(3);
2682 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2683 >        checkCompletedWithWrappedCancellationException(h);
2684  
2685 <        r = new Noop();
2289 <        f = new CompletableFuture<Integer>();
2290 <        f2 = new CompletableFuture<Integer>();
2291 <        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2292 <        f.complete(one);
2293 <        assertTrue(f2.cancel(true));
2294 <        checkCompletedWithWrappedCancellationException(g);
2685 >        assertEquals(0, e.count.get());
2686      }
2687  
2688      /**
# Line 2299 | Line 2690 | public class CompletableFutureTest exten
2690       * completion of sources
2691       */
2692      public void testApplyToEitherAsyncE() {
2693 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2694 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2693 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2694 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2695          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2696          f.complete(one);
2697          checkCompletedNormally(g, two);
2698  
2699 <        f = new CompletableFuture<Integer>();
2699 >        f = new CompletableFuture<>();
2700          f.complete(one);
2701 <        f2 = new CompletableFuture<Integer>();
2701 >        f2 = new CompletableFuture<>();
2702          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2703          checkCompletedNormally(g, two);
2704      }
# Line 2317 | Line 2708 | public class CompletableFutureTest exten
2708       * completion of source
2709       */
2710      public void testApplyToEitherAsync2E() {
2711 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2712 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2711 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2712 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2713          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2714          f.completeExceptionally(new CFException());
2715          checkCompletedWithWrappedCFException(g);
2716  
2717 <        f = new CompletableFuture<Integer>();
2718 <        f2 = new CompletableFuture<Integer>();
2717 >        f = new CompletableFuture<>();
2718 >        f2 = new CompletableFuture<>();
2719          f2.completeExceptionally(new CFException());
2720          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2721          f.complete(one);
# Line 2335 | Line 2726 | public class CompletableFutureTest exten
2726       * applyToEitherAsync result completes exceptionally if action does
2727       */
2728      public void testApplyToEitherAsync3E() {
2729 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2730 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2729 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2730 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2731          FailingFunction r = new FailingFunction();
2732          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2733          f.complete(one);
# Line 2347 | Line 2738 | public class CompletableFutureTest exten
2738       * applyToEitherAsync result completes exceptionally if either source cancelled
2739       */
2740      public void testApplyToEitherAsync4E() {
2741 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2742 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2741 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2742 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2743          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2744          assertTrue(f.cancel(true));
2745          checkCompletedWithWrappedCancellationException(g);
2746  
2747 <        f = new CompletableFuture<Integer>();
2748 <        f2 = new CompletableFuture<Integer>();
2747 >        f = new CompletableFuture<>();
2748 >        f2 = new CompletableFuture<>();
2749          assertTrue(f2.cancel(true));
2750          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2751          checkCompletedWithWrappedCancellationException(g);
# Line 2365 | Line 2756 | public class CompletableFutureTest exten
2756       * completion of sources
2757       */
2758      public void testAcceptEitherAsyncE() {
2759 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2760 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2759 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2760 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2761          IncAction r = new IncAction();
2762          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2763          f.complete(one);
# Line 2374 | Line 2765 | public class CompletableFutureTest exten
2765          assertEquals(r.value, 2);
2766  
2767          r = new IncAction();
2768 <        f = new CompletableFuture<Integer>();
2768 >        f = new CompletableFuture<>();
2769          f.complete(one);
2770 <        f2 = new CompletableFuture<Integer>();
2770 >        f2 = new CompletableFuture<>();
2771          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2772          checkCompletedNormally(g, null);
2773          assertEquals(r.value, 2);
# Line 2387 | Line 2778 | public class CompletableFutureTest exten
2778       * completion of source
2779       */
2780      public void testAcceptEitherAsync2E() {
2781 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2782 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2781 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2782 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2783          IncAction r = new IncAction();
2784          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2785          f.completeExceptionally(new CFException());
2786          checkCompletedWithWrappedCFException(g);
2787  
2788          r = new IncAction();
2789 <        f = new CompletableFuture<Integer>();
2790 <        f2 = new CompletableFuture<Integer>();
2789 >        f = new CompletableFuture<>();
2790 >        f2 = new CompletableFuture<>();
2791          f2.completeExceptionally(new CFException());
2792          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2793          f.complete(one);
# Line 2407 | Line 2798 | public class CompletableFutureTest exten
2798       * acceptEitherAsync result completes exceptionally if action does
2799       */
2800      public void testAcceptEitherAsync3E() {
2801 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2802 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2801 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2802 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2803          FailingConsumer r = new FailingConsumer();
2804          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2805          f.complete(one);
# Line 2420 | Line 2811 | public class CompletableFutureTest exten
2811       * source cancelled
2812       */
2813      public void testAcceptEitherAsync4E() {
2814 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2815 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2814 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2815 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2816          IncAction r = new IncAction();
2817          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2818          assertTrue(f.cancel(true));
2819          checkCompletedWithWrappedCancellationException(g);
2820  
2821          r = new IncAction();
2822 <        f = new CompletableFuture<Integer>();
2823 <        f2 = new CompletableFuture<Integer>();
2822 >        f = new CompletableFuture<>();
2823 >        f2 = new CompletableFuture<>();
2824          assertTrue(f2.cancel(true));
2825          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2826          checkCompletedWithWrappedCancellationException(g);
# Line 2440 | Line 2831 | public class CompletableFutureTest exten
2831       * completion of sources
2832       */
2833      public void testRunAfterEitherAsyncE() {
2834 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2835 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2834 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2835 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2836          Noop r = new Noop();
2837          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2838          f.complete(one);
# Line 2449 | Line 2840 | public class CompletableFutureTest exten
2840          assertTrue(r.ran);
2841  
2842          r = new Noop();
2843 <        f = new CompletableFuture<Integer>();
2843 >        f = new CompletableFuture<>();
2844          f.complete(one);
2845 <        f2 = new CompletableFuture<Integer>();
2845 >        f2 = new CompletableFuture<>();
2846          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2847          checkCompletedNormally(g, null);
2848          assertTrue(r.ran);
# Line 2462 | Line 2853 | public class CompletableFutureTest exten
2853       * completion of source
2854       */
2855      public void testRunAfterEitherAsync2E() {
2856 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2857 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2856 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2857 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2858          Noop r = new Noop();
2859          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2860          f.completeExceptionally(new CFException());
2861          checkCompletedWithWrappedCFException(g);
2862  
2863          r = new Noop();
2864 <        f = new CompletableFuture<Integer>();
2865 <        f2 = new CompletableFuture<Integer>();
2864 >        f = new CompletableFuture<>();
2865 >        f2 = new CompletableFuture<>();
2866          f2.completeExceptionally(new CFException());
2867          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2868          f.complete(one);
# Line 2482 | Line 2873 | public class CompletableFutureTest exten
2873       * runAfterEitherAsync result completes exceptionally if action does
2874       */
2875      public void testRunAfterEitherAsync3E() {
2876 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2877 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2876 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2877 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2878          FailingNoop r = new FailingNoop();
2879          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2880          f.complete(one);
# Line 2495 | Line 2886 | public class CompletableFutureTest exten
2886       * source cancelled
2887       */
2888      public void testRunAfterEitherAsync4E() {
2889 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2890 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2889 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2890 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2891          Noop r = new Noop();
2892          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2893          assertTrue(f.cancel(true));
2894          checkCompletedWithWrappedCancellationException(g);
2895  
2896          r = new Noop();
2897 <        f = new CompletableFuture<Integer>();
2898 <        f2 = new CompletableFuture<Integer>();
2897 >        f = new CompletableFuture<>();
2898 >        f2 = new CompletableFuture<>();
2899          assertTrue(f2.cancel(true));
2900          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2901          checkCompletedWithWrappedCancellationException(g);
# Line 2515 | Line 2906 | public class CompletableFutureTest exten
2906       * completion of source
2907       */
2908      public void testThenComposeAsyncE() {
2909 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2909 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2910          CompletableFutureInc r = new CompletableFutureInc();
2911          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2912          f.complete(one);
# Line 2527 | Line 2918 | public class CompletableFutureTest exten
2918       * exceptional completion of source
2919       */
2920      public void testThenComposeAsync2E() {
2921 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2921 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2922          CompletableFutureInc r = new CompletableFutureInc();
2923          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2924          f.completeExceptionally(new CFException());
# Line 2538 | Line 2929 | public class CompletableFutureTest exten
2929       * thenComposeAsync result completes exceptionally if action does
2930       */
2931      public void testThenComposeAsync3E() {
2932 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2932 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2933          FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2934          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2935          f.complete(one);
# Line 2549 | Line 2940 | public class CompletableFutureTest exten
2940       * thenComposeAsync result completes exceptionally if source cancelled
2941       */
2942      public void testThenComposeAsync4E() {
2943 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2943 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2944          CompletableFutureInc r = new CompletableFutureInc();
2945          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2946          assertTrue(f.cancel(true));
# Line 2563 | Line 2954 | public class CompletableFutureTest exten
2954       * with the value null
2955       */
2956      public void testAllOf_empty() throws Exception {
2957 <        CompletableFuture<?> f = CompletableFuture.allOf();
2957 >        CompletableFuture<Void> f = CompletableFuture.allOf();
2958          checkCompletedNormally(f, null);
2959      }
2960  
2961      /**
2962 <     * allOf returns a future completed when all components complete
2962 >     * allOf returns a future completed normally with the value null
2963 >     * when all components complete normally
2964       */
2965 <    public void testAllOf() throws Exception {
2965 >    public void testAllOf_normal() throws Exception {
2966          for (int k = 1; k < 20; ++k) {
2967 <            CompletableFuture[] fs = new CompletableFuture[k];
2967 >            CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2968              for (int i = 0; i < k; ++i)
2969 <                fs[i] = new CompletableFuture<Integer>();
2969 >                fs[i] = new CompletableFuture<>();
2970              CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2971              for (int i = 0; i < k; ++i) {
2972                  checkIncomplete(f);
2973 +                checkIncomplete(CompletableFuture.allOf(fs));
2974                  fs[i].complete(one);
2975              }
2976              checkCompletedNormally(f, null);
2977 +            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2978          }
2979      }
2980  
# Line 2588 | Line 2982 | public class CompletableFutureTest exten
2982       * anyOf(no component futures) returns an incomplete future
2983       */
2984      public void testAnyOf_empty() throws Exception {
2985 <        CompletableFuture<?> f = CompletableFuture.anyOf();
2985 >        CompletableFuture<Object> f = CompletableFuture.anyOf();
2986          checkIncomplete(f);
2987      }
2988  
2989      /**
2990 <     * anyOf returns a future completed when any components complete
2990 >     * anyOf returns a future completed normally with a value when
2991 >     * a component future does
2992       */
2993 <    public void testAnyOf() throws Exception {
2994 <        for (int k = 1; k < 20; ++k) {
2993 >    public void testAnyOf_normal() throws Exception {
2994 >        for (int k = 0; k < 10; ++k) {
2995              CompletableFuture[] fs = new CompletableFuture[k];
2996              for (int i = 0; i < k; ++i)
2997 <                fs[i] = new CompletableFuture<Integer>();
2997 >                fs[i] = new CompletableFuture<>();
2998              CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2999              checkIncomplete(f);
3000              for (int i = 0; i < k; ++i) {
3001                  fs[i].complete(one);
3002                  checkCompletedNormally(f, one);
3003 +                checkCompletedNormally(CompletableFuture.anyOf(fs), one);
3004 +            }
3005 +        }
3006 +    }
3007 +
3008 +    /**
3009 +     * anyOf result completes exceptionally when any component does.
3010 +     */
3011 +    public void testAnyOf_exceptional() throws Exception {
3012 +        for (int k = 0; k < 10; ++k) {
3013 +            CompletableFuture[] fs = new CompletableFuture[k];
3014 +            for (int i = 0; i < k; ++i)
3015 +                fs[i] = new CompletableFuture<>();
3016 +            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
3017 +            checkIncomplete(f);
3018 +            for (int i = 0; i < k; ++i) {
3019 +                fs[i].completeExceptionally(new CFException());
3020 +                checkCompletedWithWrappedCFException(f);
3021 +                checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
3022              }
3023          }
3024      }
# Line 2613 | Line 3027 | public class CompletableFutureTest exten
3027       * Completion methods throw NullPointerException with null arguments
3028       */
3029      public void testNPE() {
3030 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
3031 <        CompletableFuture<Integer> g = new CompletableFuture<Integer>();
3030 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3031 >        CompletableFuture<Integer> g = new CompletableFuture<>();
3032          CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null;
3033          CompletableFuture<?> h;
3034          ThreadExecutor exec = new ThreadExecutor();
3035  
3036          Runnable[] throwingActions = {
3037 <            () -> { CompletableFuture.supplyAsync(null); },
3038 <            () -> { CompletableFuture.supplyAsync(null, exec); },
3039 <            () -> { CompletableFuture.supplyAsync(supplyOne, null); },
3040 <
3041 <            () -> { CompletableFuture.runAsync(null); },
3042 <            () -> { CompletableFuture.runAsync(null, exec); },
3043 <            () -> { CompletableFuture.runAsync(() -> {}, null); },
3044 <
3045 <            () -> { f.completeExceptionally(null); },
3046 <
3047 <            () -> { f.thenApply(null); },
3048 <            () -> { f.thenApplyAsync(null); },
3049 <            () -> { f.thenApplyAsync((x) -> x, null); },
3050 <            () -> { f.thenApplyAsync(null, exec); },
3051 <
3052 <            () -> { f.thenAccept(null); },
3053 <            () -> { f.thenAcceptAsync(null); },
3054 <            () -> { f.thenAcceptAsync((x) -> { ; }, null); },
3055 <            () -> { f.thenAcceptAsync(null, exec); },
3056 <
3057 <            () -> { f.thenRun(null); },
3058 <            () -> { f.thenRunAsync(null); },
3059 <            () -> { f.thenRunAsync(() -> { ; }, null); },
3060 <            () -> { f.thenRunAsync(null, exec); },
3061 <
3062 <            () -> { f.thenCombine(g, null); },
3063 <            () -> { f.thenCombineAsync(g, null); },
3064 <            () -> { f.thenCombineAsync(g, null, exec); },
3065 <            () -> { f.thenCombine(nullFuture, (x, y) -> x); },
3066 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x); },
3067 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); },
3068 <            () -> { f.thenCombineAsync(g, (x, y) -> x, null); },
3069 <
3070 <            () -> { f.thenAcceptBoth(g, null); },
3071 <            () -> { f.thenAcceptBothAsync(g, null); },
3072 <            () -> { f.thenAcceptBothAsync(g, null, exec); },
3073 <            () -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); },
3074 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); },
3075 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); },
3076 <            () -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); },
3077 <
3078 <            () -> { f.runAfterBoth(g, null); },
3079 <            () -> { f.runAfterBothAsync(g, null); },
3080 <            () -> { f.runAfterBothAsync(g, null, exec); },
3081 <            () -> { f.runAfterBoth(nullFuture, () -> {}); },
3082 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}); },
3083 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); },
3084 <            () -> { f.runAfterBothAsync(g, () -> {}, null); },
3085 <
3086 <            () -> { f.applyToEither(g, null); },
3087 <            () -> { f.applyToEitherAsync(g, null); },
3088 <            () -> { f.applyToEitherAsync(g, null, exec); },
3089 <            () -> { f.applyToEither(nullFuture, (x) -> x); },
3090 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x); },
3091 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); },
3092 <            () -> { f.applyToEitherAsync(g, (x) -> x, null); },
3093 <
3094 <            () -> { f.acceptEither(g, null); },
3095 <            () -> { f.acceptEitherAsync(g, null); },
3096 <            () -> { f.acceptEitherAsync(g, null, exec); },
3097 <            () -> { f.acceptEither(nullFuture, (x) -> {}); },
3098 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}); },
3099 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); },
3100 <            () -> { f.acceptEitherAsync(g, (x) -> {}, null); },
3101 <
3102 <            () -> { f.runAfterEither(g, null); },
3103 <            () -> { f.runAfterEitherAsync(g, null); },
3104 <            () -> { f.runAfterEitherAsync(g, null, exec); },
3105 <            () -> { f.runAfterEither(nullFuture, () -> {}); },
3106 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}); },
3107 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); },
3108 <            () -> { f.runAfterEitherAsync(g, () -> {}, null); },
3109 <
3110 <            () -> { f.thenCompose(null); },
3111 <            () -> { f.thenComposeAsync(null); },
3112 <            () -> { f.thenComposeAsync(new CompletableFutureInc(), null); },
3113 <            () -> { f.thenComposeAsync(null, exec); },
3114 <
3115 <            () -> { f.exceptionally(null); },
3116 <
3117 <            () -> { f.handle(null); },
3118 <
3119 <            () -> { CompletableFuture.allOf((CompletableFuture<?>)null); },
3120 <            () -> { CompletableFuture.allOf((CompletableFuture<?>[])null); },
3121 <            () -> { CompletableFuture.allOf(f, null); },
3122 <            () -> { CompletableFuture.allOf(null, f); },
3123 <
3124 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>)null); },
3125 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); },
3126 <            () -> { CompletableFuture.anyOf(f, null); },
3127 <            () -> { CompletableFuture.anyOf(null, f); },
3037 >            () -> CompletableFuture.supplyAsync(null),
3038 >            () -> CompletableFuture.supplyAsync(null, exec),
3039 >            () -> CompletableFuture.supplyAsync(supplyOne, null),
3040 >
3041 >            () -> CompletableFuture.runAsync(null),
3042 >            () -> CompletableFuture.runAsync(null, exec),
3043 >            () -> CompletableFuture.runAsync(() -> {}, null),
3044 >
3045 >            () -> f.completeExceptionally(null),
3046 >
3047 >            () -> f.thenApply(null),
3048 >            () -> f.thenApplyAsync(null),
3049 >            () -> f.thenApplyAsync((x) -> x, null),
3050 >            () -> f.thenApplyAsync(null, exec),
3051 >
3052 >            () -> f.thenAccept(null),
3053 >            () -> f.thenAcceptAsync(null),
3054 >            () -> f.thenAcceptAsync((x) -> {} , null),
3055 >            () -> f.thenAcceptAsync(null, exec),
3056 >
3057 >            () -> f.thenRun(null),
3058 >            () -> f.thenRunAsync(null),
3059 >            () -> f.thenRunAsync(() -> {} , null),
3060 >            () -> f.thenRunAsync(null, exec),
3061 >
3062 >            () -> f.thenCombine(g, null),
3063 >            () -> f.thenCombineAsync(g, null),
3064 >            () -> f.thenCombineAsync(g, null, exec),
3065 >            () -> f.thenCombine(nullFuture, (x, y) -> x),
3066 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x),
3067 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec),
3068 >            () -> f.thenCombineAsync(g, (x, y) -> x, null),
3069 >
3070 >            () -> f.thenAcceptBoth(g, null),
3071 >            () -> f.thenAcceptBothAsync(g, null),
3072 >            () -> f.thenAcceptBothAsync(g, null, exec),
3073 >            () -> f.thenAcceptBoth(nullFuture, (x, y) -> {}),
3074 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}),
3075 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec),
3076 >            () -> f.thenAcceptBothAsync(g, (x, y) -> {}, null),
3077 >
3078 >            () -> f.runAfterBoth(g, null),
3079 >            () -> f.runAfterBothAsync(g, null),
3080 >            () -> f.runAfterBothAsync(g, null, exec),
3081 >            () -> f.runAfterBoth(nullFuture, () -> {}),
3082 >            () -> f.runAfterBothAsync(nullFuture, () -> {}),
3083 >            () -> f.runAfterBothAsync(nullFuture, () -> {}, exec),
3084 >            () -> f.runAfterBothAsync(g, () -> {}, null),
3085 >
3086 >            () -> f.applyToEither(g, null),
3087 >            () -> f.applyToEitherAsync(g, null),
3088 >            () -> f.applyToEitherAsync(g, null, exec),
3089 >            () -> f.applyToEither(nullFuture, (x) -> x),
3090 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x),
3091 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x, exec),
3092 >            () -> f.applyToEitherAsync(g, (x) -> x, null),
3093 >
3094 >            () -> f.acceptEither(g, null),
3095 >            () -> f.acceptEitherAsync(g, null),
3096 >            () -> f.acceptEitherAsync(g, null, exec),
3097 >            () -> f.acceptEither(nullFuture, (x) -> {}),
3098 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}),
3099 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec),
3100 >            () -> f.acceptEitherAsync(g, (x) -> {}, null),
3101 >
3102 >            () -> f.runAfterEither(g, null),
3103 >            () -> f.runAfterEitherAsync(g, null),
3104 >            () -> f.runAfterEitherAsync(g, null, exec),
3105 >            () -> f.runAfterEither(nullFuture, () -> {}),
3106 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}),
3107 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}, exec),
3108 >            () -> f.runAfterEitherAsync(g, () -> {}, null),
3109 >
3110 >            () -> f.thenCompose(null),
3111 >            () -> f.thenComposeAsync(null),
3112 >            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
3113 >            () -> f.thenComposeAsync(null, exec),
3114 >
3115 >            () -> f.exceptionally(null),
3116 >
3117 >            () -> f.handle(null),
3118 >
3119 >            () -> CompletableFuture.allOf((CompletableFuture<?>)null),
3120 >            () -> CompletableFuture.allOf((CompletableFuture<?>[])null),
3121 >            () -> CompletableFuture.allOf(f, null),
3122 >            () -> CompletableFuture.allOf(null, f),
3123 >
3124 >            () -> CompletableFuture.anyOf((CompletableFuture<?>)null),
3125 >            () -> CompletableFuture.anyOf((CompletableFuture<?>[])null),
3126 >            () -> CompletableFuture.anyOf(f, null),
3127 >            () -> CompletableFuture.anyOf(null, f),
3128 >
3129 >            () -> f.obtrudeException(null),
3130          };
3131  
3132          assertThrows(NullPointerException.class, throwingActions);
3133          assertEquals(0, exec.count.get());
3134      }
3135  
3136 +    /**
3137 +     * toCompletableFuture returns this CompletableFuture.
3138 +     */
3139 +    public void testToCompletableFuture() {
3140 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3141 +        assertSame(f, f.toCompletableFuture());
3142 +    }
3143 +
3144 +    /**
3145 +     * whenComplete action executes on normal completion, propagating
3146 +     * source result.
3147 +     */
3148 +    public void testWhenComplete1() {
3149 +        final AtomicInteger a = new AtomicInteger();
3150 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3151 +        CompletableFuture<Integer> g =
3152 +            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3153 +        f.complete(three);
3154 +        checkCompletedNormally(f, three);
3155 +        checkCompletedNormally(g, three);
3156 +        assertEquals(a.get(), 1);
3157 +    }
3158 +
3159 +    /**
3160 +     * whenComplete action executes on exceptional completion, propagating
3161 +     * source result.
3162 +     */
3163 +    public void testWhenComplete2() {
3164 +        final AtomicInteger a = new AtomicInteger();
3165 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3166 +        CompletableFuture<Integer> g =
3167 +            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3168 +        f.completeExceptionally(new CFException());
3169 +        assertTrue(f.isCompletedExceptionally());
3170 +        assertTrue(g.isCompletedExceptionally());
3171 +        assertEquals(a.get(), 1);
3172 +    }
3173 +
3174 +    /**
3175 +     * If a whenComplete action throws an exception when triggered by
3176 +     * a normal completion, it completes exceptionally
3177 +     */
3178 +    public void testWhenComplete3() {
3179 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3180 +        CompletableFuture<Integer> g =
3181 +            f.whenComplete((Integer x, Throwable t) ->
3182 +                           { throw new CFException(); } );
3183 +        f.complete(three);
3184 +        checkCompletedNormally(f, three);
3185 +        assertTrue(g.isCompletedExceptionally());
3186 +        checkCompletedWithWrappedCFException(g);
3187 +    }
3188 +
3189 +    /**
3190 +     * whenCompleteAsync action executes on normal completion, propagating
3191 +     * source result.
3192 +     */
3193 +    public void testWhenCompleteAsync1() {
3194 +        final AtomicInteger a = new AtomicInteger();
3195 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3196 +        CompletableFuture<Integer> g =
3197 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3198 +        f.complete(three);
3199 +        checkCompletedNormally(f, three);
3200 +        checkCompletedNormally(g, three);
3201 +        assertEquals(a.get(), 1);
3202 +    }
3203 +
3204 +    /**
3205 +     * whenCompleteAsync action executes on exceptional completion, propagating
3206 +     * source result.
3207 +     */
3208 +    public void testWhenCompleteAsync2() {
3209 +        final AtomicInteger a = new AtomicInteger();
3210 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3211 +        CompletableFuture<Integer> g =
3212 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3213 +        f.completeExceptionally(new CFException());
3214 +        checkCompletedWithWrappedCFException(f);
3215 +        checkCompletedWithWrappedCFException(g);
3216 +    }
3217 +
3218 +    /**
3219 +     * If a whenCompleteAsync action throws an exception when
3220 +     * triggered by a normal completion, it completes exceptionally
3221 +     */
3222 +    public void testWhenCompleteAsync3() {
3223 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3224 +        CompletableFuture<Integer> g =
3225 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3226 +                           { throw new CFException(); } );
3227 +        f.complete(three);
3228 +        checkCompletedNormally(f, three);
3229 +        checkCompletedWithWrappedCFException(g);
3230 +    }
3231 +
3232 +    /**
3233 +     * whenCompleteAsync action executes on normal completion, propagating
3234 +     * source result.
3235 +     */
3236 +    public void testWhenCompleteAsync1e() {
3237 +        final AtomicInteger a = new AtomicInteger();
3238 +        ThreadExecutor exec = new ThreadExecutor();
3239 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3240 +        CompletableFuture<Integer> g =
3241 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3242 +                                exec);
3243 +        f.complete(three);
3244 +        checkCompletedNormally(f, three);
3245 +        checkCompletedNormally(g, three);
3246 +        assertEquals(a.get(), 1);
3247 +    }
3248 +
3249 +    /**
3250 +     * whenCompleteAsync action executes on exceptional completion, propagating
3251 +     * source result.
3252 +     */
3253 +    public void testWhenCompleteAsync2e() {
3254 +        final AtomicInteger a = new AtomicInteger();
3255 +        ThreadExecutor exec = new ThreadExecutor();
3256 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3257 +        CompletableFuture<Integer> g =
3258 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3259 +                                exec);
3260 +        f.completeExceptionally(new CFException());
3261 +        checkCompletedWithWrappedCFException(f);
3262 +        checkCompletedWithWrappedCFException(g);
3263 +    }
3264 +
3265 +    /**
3266 +     * If a whenCompleteAsync action throws an exception when triggered
3267 +     * by a normal completion, it completes exceptionally
3268 +     */
3269 +    public void testWhenCompleteAsync3e() {
3270 +        ThreadExecutor exec = new ThreadExecutor();
3271 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3272 +        CompletableFuture<Integer> g =
3273 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3274 +                                { throw new CFException(); },
3275 +                                exec);
3276 +        f.complete(three);
3277 +        checkCompletedNormally(f, three);
3278 +        checkCompletedWithWrappedCFException(g);
3279 +    }
3280 +
3281 +    /**
3282 +     * handleAsync action completes normally with function value on
3283 +     * either normal or exceptional completion of source
3284 +     */
3285 +    public void testHandleAsync() {
3286 +        CompletableFuture<Integer> f, g;
3287 +        IntegerHandler r;
3288 +
3289 +        f = new CompletableFuture<>();
3290 +        g = f.handleAsync(r = new IntegerHandler());
3291 +        assertFalse(r.ran);
3292 +        f.completeExceptionally(new CFException());
3293 +        checkCompletedWithWrappedCFException(f);
3294 +        checkCompletedNormally(g, three);
3295 +        assertTrue(r.ran);
3296 +
3297 +        f = new CompletableFuture<>();
3298 +        g = f.handleAsync(r = new IntegerHandler());
3299 +        assertFalse(r.ran);
3300 +        f.completeExceptionally(new CFException());
3301 +        checkCompletedWithWrappedCFException(f);
3302 +        checkCompletedNormally(g, three);
3303 +        assertTrue(r.ran);
3304 +
3305 +        f = new CompletableFuture<>();
3306 +        g = f.handleAsync(r = new IntegerHandler());
3307 +        assertFalse(r.ran);
3308 +        f.complete(one);
3309 +        checkCompletedNormally(f, one);
3310 +        checkCompletedNormally(g, two);
3311 +        assertTrue(r.ran);
3312 +
3313 +        f = new CompletableFuture<>();
3314 +        g = f.handleAsync(r = new IntegerHandler());
3315 +        assertFalse(r.ran);
3316 +        f.complete(one);
3317 +        checkCompletedNormally(f, one);
3318 +        checkCompletedNormally(g, two);
3319 +        assertTrue(r.ran);
3320 +    }
3321 +
3322 +    /**
3323 +     * handleAsync action with Executor completes normally with
3324 +     * function value on either normal or exceptional completion of
3325 +     * source
3326 +     */
3327 +    public void testHandleAsync2() {
3328 +        CompletableFuture<Integer> f, g;
3329 +        ThreadExecutor exec = new ThreadExecutor();
3330 +        IntegerHandler r;
3331 +
3332 +        f = new CompletableFuture<>();
3333 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3334 +        assertFalse(r.ran);
3335 +        f.completeExceptionally(new CFException());
3336 +        checkCompletedWithWrappedCFException(f);
3337 +        checkCompletedNormally(g, three);
3338 +        assertTrue(r.ran);
3339 +
3340 +        f = new CompletableFuture<>();
3341 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3342 +        assertFalse(r.ran);
3343 +        f.completeExceptionally(new CFException());
3344 +        checkCompletedWithWrappedCFException(f);
3345 +        checkCompletedNormally(g, three);
3346 +        assertTrue(r.ran);
3347 +
3348 +        f = new CompletableFuture<>();
3349 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3350 +        assertFalse(r.ran);
3351 +        f.complete(one);
3352 +        checkCompletedNormally(f, one);
3353 +        checkCompletedNormally(g, two);
3354 +        assertTrue(r.ran);
3355 +
3356 +        f = new CompletableFuture<>();
3357 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3358 +        assertFalse(r.ran);
3359 +        f.complete(one);
3360 +        checkCompletedNormally(f, one);
3361 +        checkCompletedNormally(g, two);
3362 +        assertTrue(r.ran);
3363 +    }
3364 +
3365   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines