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.7 by jsr166, Fri Mar 22 16:29:42 2013 UTC vs.
Revision 1.28 by jsr166, Sun Jul 14 16:34:49 2013 UTC

# Line 53 | Line 53 | public class CompletableFutureTest exten
53          catch (Throwable fail) { threadUnexpectedException(fail); }
54      }
55  
56 <    void checkCompletedNormally(CompletableFuture<?> f, Object value) {
56 >    <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
57 >        try {
58 >            assertEquals(value, f.get(LONG_DELAY_MS, MILLISECONDS));
59 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
60          try {
61              assertEquals(value, f.join());
62          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 63 | Line 66 | public class CompletableFutureTest exten
66          try {
67              assertEquals(value, f.get());
68          } catch (Throwable fail) { threadUnexpectedException(fail); }
66        try {
67            assertEquals(value, f.get(0L, SECONDS));
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  
75      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
76          try {
77 +            f.get(LONG_DELAY_MS, MILLISECONDS);
78 +            shouldThrow();
79 +        } catch (ExecutionException success) {
80 +            assertTrue(success.getCause() instanceof CFException);
81 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
82 +        try {
83              f.join();
84              shouldThrow();
85 <        } catch (Throwable ex) {
86 <            assertTrue(ex instanceof CompletionException &&
80 <                       ((CompletionException)ex).getCause() instanceof CFException);
85 >        } catch (CompletionException success) {
86 >            assertTrue(success.getCause() instanceof CFException);
87          }
88          try {
89              f.getNow(null);
90              shouldThrow();
91 <        } catch (Throwable ex) {
92 <            assertTrue(ex instanceof CompletionException &&
87 <                       ((CompletionException)ex).getCause() instanceof CFException);
91 >        } catch (CompletionException success) {
92 >            assertTrue(success.getCause() instanceof CFException);
93          }
94          try {
95              f.get();
96              shouldThrow();
97 <        } catch (Throwable ex) {
98 <            assertTrue(ex instanceof ExecutionException &&
99 <                       ((ExecutionException)ex).getCause() instanceof CFException);
95 <        }
96 <        try {
97 <            f.get(0L, SECONDS);
98 <            shouldThrow();
99 <        } catch (Throwable ex) {
100 <            assertTrue(ex instanceof ExecutionException &&
101 <                       ((ExecutionException)ex).getCause() instanceof CFException);
102 <        }
97 >        } catch (ExecutionException success) {
98 >            assertTrue(success.getCause() instanceof CFException);
99 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
100          assertTrue(f.isDone());
101          assertFalse(f.isCancelled());
102 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
103      }
104  
105      void checkCancelled(CompletableFuture<?> f) {
106          try {
107 +            f.get(LONG_DELAY_MS, MILLISECONDS);
108 +            shouldThrow();
109 +        } catch (CancellationException success) {
110 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
111 +        try {
112              f.join();
113              shouldThrow();
114 <        } catch (Throwable ex) {
112 <            assertTrue(ex instanceof CancellationException);
113 <        }
114 >        } catch (CancellationException success) {}
115          try {
116              f.getNow(null);
117              shouldThrow();
118 <        } catch (Throwable ex) {
118 <            assertTrue(ex instanceof CancellationException);
119 <        }
118 >        } catch (CancellationException success) {}
119          try {
120              f.get();
121              shouldThrow();
122 <        } catch (Throwable ex) {
123 <            assertTrue(ex instanceof CancellationException);
125 <        }
126 <        try {
127 <            f.get(0L, SECONDS);
128 <            shouldThrow();
129 <        } catch (Throwable ex) {
130 <            assertTrue(ex instanceof CancellationException);
131 <        }
122 >        } catch (CancellationException success) {
123 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
124          assertTrue(f.isDone());
125 +        assertTrue(f.isCompletedExceptionally());
126          assertTrue(f.isCancelled());
127 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
128      }
129  
130      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
131          try {
132 +            f.get(LONG_DELAY_MS, MILLISECONDS);
133 +            shouldThrow();
134 +        } catch (ExecutionException success) {
135 +            assertTrue(success.getCause() instanceof CancellationException);
136 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
137 +        try {
138              f.join();
139              shouldThrow();
140 <        } catch (Throwable ex) {
141 <            assertTrue(ex instanceof CompletionException &&
142 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
140 >        } catch (CompletionException success) {
141 >            assertTrue(success.getCause() instanceof CancellationException);
142          }
143          try {
144              f.getNow(null);
145              shouldThrow();
146 <        } catch (Throwable ex) {
147 <            assertTrue(ex instanceof CompletionException &&
149 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
146 >        } catch (CompletionException success) {
147 >            assertTrue(success.getCause() instanceof CancellationException);
148          }
149          try {
150              f.get();
151              shouldThrow();
152 <        } catch (Throwable ex) {
153 <            assertTrue(ex instanceof ExecutionException &&
154 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
157 <        }
158 <        try {
159 <            f.get(0L, SECONDS);
160 <            shouldThrow();
161 <        } catch (Throwable ex) {
162 <            assertTrue(ex instanceof ExecutionException &&
163 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
164 <        }
152 >        } catch (ExecutionException success) {
153 >            assertTrue(success.getCause() instanceof CancellationException);
154 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
155          assertTrue(f.isDone());
156          assertFalse(f.isCancelled());
157 +        assertTrue(f.isCompletedExceptionally());
158 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
159      }
160  
161      /**
# Line 171 | Line 163 | public class CompletableFutureTest exten
163       * by methods isDone, isCancelled, and getNow
164       */
165      public void testConstructor() {
166 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
166 >        CompletableFuture<Integer> f = new CompletableFuture<>();
167          checkIncomplete(f);
168      }
169  
# Line 180 | Line 172 | public class CompletableFutureTest exten
172       * isCancelled, join, get, and getNow
173       */
174      public void testComplete() {
175 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
175 >        CompletableFuture<Integer> f = new CompletableFuture<>();
176          checkIncomplete(f);
177          f.complete(one);
178          checkCompletedNormally(f, one);
# Line 191 | Line 183 | public class CompletableFutureTest exten
183       * methods isDone, isCancelled, join, get, and getNow
184       */
185      public void testCompleteExceptionally() {
186 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
186 >        CompletableFuture<Integer> f = new CompletableFuture<>();
187          checkIncomplete(f);
188          f.completeExceptionally(new CFException());
189          checkCompletedWithWrappedCFException(f);
# Line 202 | Line 194 | public class CompletableFutureTest exten
194       * methods isDone, isCancelled, join, get, and getNow
195       */
196      public void testCancel() {
197 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
197 >        CompletableFuture<Integer> f = new CompletableFuture<>();
198          checkIncomplete(f);
199          assertTrue(f.cancel(true));
200          checkCancelled(f);
# Line 212 | Line 204 | public class CompletableFutureTest exten
204       * obtrudeValue forces completion with given value
205       */
206      public void testObtrudeValue() {
207 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
207 >        CompletableFuture<Integer> f = new CompletableFuture<>();
208          checkIncomplete(f);
209          f.complete(one);
210          checkCompletedNormally(f, one);
# Line 220 | Line 212 | public class CompletableFutureTest exten
212          checkCompletedNormally(f, three);
213          f.obtrudeValue(two);
214          checkCompletedNormally(f, two);
215 <        f = new CompletableFuture<Integer>();
215 >        f = new CompletableFuture<>();
216          f.obtrudeValue(three);
217          checkCompletedNormally(f, three);
218 <        f = new CompletableFuture<Integer>();
218 >        f = new CompletableFuture<>();
219          f.completeExceptionally(new CFException());
220          f.obtrudeValue(four);
221          checkCompletedNormally(f, four);
# Line 233 | Line 225 | public class CompletableFutureTest exten
225       * obtrudeException forces completion with given exception
226       */
227      public void testObtrudeException() {
228 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
228 >        CompletableFuture<Integer> f = new CompletableFuture<>();
229          checkIncomplete(f);
230          f.complete(one);
231          checkCompletedNormally(f, one);
232          f.obtrudeException(new CFException());
233          checkCompletedWithWrappedCFException(f);
234 <        f = new CompletableFuture<Integer>();
234 >        f = new CompletableFuture<>();
235          f.obtrudeException(new CFException());
236          checkCompletedWithWrappedCFException(f);
237 <        f = new CompletableFuture<Integer>();
237 >        f = new CompletableFuture<>();
238          f.completeExceptionally(new CFException());
239          f.obtrudeValue(four);
240          checkCompletedNormally(f, four);
# Line 254 | Line 246 | public class CompletableFutureTest exten
246       * getNumberOfDependents returns number of dependent tasks
247       */
248      public void testGetNumberOfDependents() {
249 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
249 >        CompletableFuture<Integer> f = new CompletableFuture<>();
250          assertEquals(f.getNumberOfDependents(), 0);
251          CompletableFuture g = f.thenRun(new Noop());
252          assertEquals(f.getNumberOfDependents(), 1);
# Line 267 | Line 259 | public class CompletableFutureTest exten
259          assertEquals(g.getNumberOfDependents(), 0);
260      }
261  
270
262      /**
263       * toString indicates current completion state
264       */
# Line 285 | Line 276 | public class CompletableFutureTest exten
276          assertTrue(f.toString().contains("[Completed exceptionally]"));
277      }
278  
279 +    /**
280 +     * completedFuture returns a completed CompletableFuture with given value
281 +     */
282 +    public void testCompletedFuture() {
283 +        CompletableFuture<String> f = CompletableFuture.completedFuture("test");
284 +        checkCompletedNormally(f, "test");
285 +    }
286 +
287 +    // Choose non-commutative actions for better coverage
288 +
289      static final Supplier<Integer> supplyOne =
290          () -> Integer.valueOf(1);
291      static final Function<Integer, Integer> inc =
292          (Integer x) -> Integer.valueOf(x.intValue() + 1);
293 <    static final BiFunction<Integer, Integer, Integer> add =
294 <        (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue());
293 >    static final BiFunction<Integer, Integer, Integer> subtract =
294 >        (Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue());
295      static final class IncAction implements Consumer<Integer> {
296          int value;
297          public void accept(Integer x) { value = x.intValue() + 1; }
298      }
299 <    static final class AddAction implements BiConsumer<Integer, Integer> {
299 >    static final class SubtractAction implements BiConsumer<Integer, Integer> {
300          int value;
301          public void accept(Integer x, Integer y) {
302 <            value = x.intValue() + y.intValue();
302 >            value = x.intValue() - y.intValue();
303          }
304      }
305      static final class Noop implements Runnable {
# Line 331 | Line 332 | public class CompletableFutureTest exten
332          public void run() { ran = true; throw new CFException(); }
333      }
334  
335 <    static final class CompletableFutureInc implements Function<Integer, CompletableFuture<Integer>> {
335 >    static final class CompletableFutureInc
336 >        implements Function<Integer, CompletableFuture<Integer>> {
337 >        boolean ran;
338          public CompletableFuture<Integer> apply(Integer x) {
339 <            CompletableFuture<Integer> f = new CompletableFuture<Integer>();
339 >            ran = true;
340 >            CompletableFuture<Integer> f = new CompletableFuture<>();
341              f.complete(Integer.valueOf(x.intValue() + 1));
342              return f;
343          }
344      }
345  
346 <    static final class FailingCompletableFutureFunction implements Function<Integer, CompletableFuture<Integer>> {
346 >    static final class FailingCompletableFutureFunction
347 >        implements Function<Integer, CompletableFuture<Integer>> {
348          boolean ran;
349          public CompletableFuture<Integer> apply(Integer x) {
350              ran = true; throw new CFException();
# Line 348 | Line 353 | public class CompletableFutureTest exten
353  
354      // Used for explicit executor tests
355      static final class ThreadExecutor implements Executor {
356 +        AtomicInteger count = new AtomicInteger(0);
357 +
358          public void execute(Runnable r) {
359 +            count.getAndIncrement();
360              new Thread(r).start();
361          }
362      }
# Line 358 | Line 366 | public class CompletableFutureTest exten
366      }
367  
368      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
369 +        boolean ran;
370          public Integer apply(Integer x, Throwable t) {
371 +            ran = true;
372              return (t == null) ? two : three;
373          }
374      }
375  
366
376      /**
377       * exceptionally action completes with function value on source
378       * exception;  otherwise with source value
379       */
380      public void testExceptionally() {
381 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
381 >        CompletableFuture<Integer> f = new CompletableFuture<>();
382          ExceptionToInteger r = new ExceptionToInteger();
383          CompletableFuture<Integer> g = f.exceptionally(r);
384          f.completeExceptionally(new CFException());
385          checkCompletedNormally(g, three);
386  
387 <        f = new CompletableFuture<Integer>();
387 >        f = new CompletableFuture<>();
388          r = new ExceptionToInteger();
389          g = f.exceptionally(r);
390          f.complete(one);
# Line 387 | Line 396 | public class CompletableFutureTest exten
396       * normal or exceptional completion of source
397       */
398      public void testHandle() {
399 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
400 <        IntegerHandler r = new IntegerHandler();
401 <        CompletableFuture<Integer> g = f.handle(r);
399 >        CompletableFuture<Integer> f, g;
400 >        IntegerHandler r;
401 >
402 >        f = new CompletableFuture<>();
403 >        f.completeExceptionally(new CFException());
404 >        g = f.handle(r = new IntegerHandler());
405 >        assertTrue(r.ran);
406 >        checkCompletedNormally(g, three);
407 >
408 >        f = new CompletableFuture<>();
409 >        g = f.handle(r = new IntegerHandler());
410 >        assertFalse(r.ran);
411          f.completeExceptionally(new CFException());
412          checkCompletedNormally(g, three);
413 +        assertTrue(r.ran);
414  
415 <        f = new CompletableFuture<Integer>();
397 <        r = new IntegerHandler();
398 <        g = f.handle(r);
415 >        f = new CompletableFuture<>();
416          f.complete(one);
417 +        g = f.handle(r = new IntegerHandler());
418 +        assertTrue(r.ran);
419 +        checkCompletedNormally(g, two);
420 +
421 +        f = new CompletableFuture<>();
422 +        g = f.handle(r = new IntegerHandler());
423 +        assertFalse(r.ran);
424 +        f.complete(one);
425 +        assertTrue(r.ran);
426          checkCompletedNormally(g, two);
427      }
428  
# Line 408 | Line 434 | public class CompletableFutureTest exten
434          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
435          assertNull(f.join());
436          assertTrue(r.ran);
437 +        checkCompletedNormally(f, null);
438      }
439  
440      /**
# Line 415 | Line 442 | public class CompletableFutureTest exten
442       */
443      public void testRunAsync2() {
444          Noop r = new Noop();
445 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor());
445 >        ThreadExecutor exec = new ThreadExecutor();
446 >        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
447          assertNull(f.join());
448          assertTrue(r.ran);
449 +        checkCompletedNormally(f, null);
450 +        assertEquals(1, exec.count.get());
451      }
452  
453      /**
# Line 434 | Line 464 | public class CompletableFutureTest exten
464       * supplyAsync completes with result of supplier
465       */
466      public void testSupplyAsync() {
467 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne);
467 >        CompletableFuture<Integer> f;
468 >        f = CompletableFuture.supplyAsync(supplyOne);
469          assertEquals(f.join(), one);
470 +        checkCompletedNormally(f, one);
471      }
472  
473      /**
474       * supplyAsync with executor completes with result of supplier
475       */
476      public void testSupplyAsync2() {
477 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
477 >        CompletableFuture<Integer> f;
478 >        f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
479          assertEquals(f.join(), one);
480 +        checkCompletedNormally(f, one);
481      }
482  
483      /**
# Line 462 | Line 496 | public class CompletableFutureTest exten
496       * thenRun result completes normally after normal completion of source
497       */
498      public void testThenRun() {
499 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
500 <        Noop r = new Noop();
501 <        CompletableFuture<Void> g = f.thenRun(r);
499 >        CompletableFuture<Integer> f;
500 >        CompletableFuture<Void> g;
501 >        Noop r;
502 >
503 >        f = new CompletableFuture<>();
504 >        g = f.thenRun(r = new Noop());
505          f.complete(null);
506          checkCompletedNormally(g, null);
507 <        // reordered version
508 <        f = new CompletableFuture<Integer>();
507 >        assertTrue(r.ran);
508 >
509 >        f = new CompletableFuture<>();
510          f.complete(null);
511 <        r = new Noop();
474 <        g = f.thenRun(r);
511 >        g = f.thenRun(r = new Noop());
512          checkCompletedNormally(g, null);
513 +        assertTrue(r.ran);
514      }
515  
516      /**
# Line 480 | Line 518 | public class CompletableFutureTest exten
518       * completion of source
519       */
520      public void testThenRun2() {
521 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
522 <        Noop r = new Noop();
523 <        CompletableFuture<Void> g = f.thenRun(r);
521 >        CompletableFuture<Integer> f;
522 >        CompletableFuture<Void> g;
523 >        Noop r;
524 >
525 >        f = new CompletableFuture<>();
526 >        g = f.thenRun(r = new Noop());
527 >        f.completeExceptionally(new CFException());
528 >        checkCompletedWithWrappedCFException(g);
529 >        assertFalse(r.ran);
530 >
531 >        f = new CompletableFuture<>();
532          f.completeExceptionally(new CFException());
533 +        g = f.thenRun(r = new Noop());
534          checkCompletedWithWrappedCFException(g);
535 +        assertFalse(r.ran);
536      }
537  
538      /**
539       * thenRun result completes exceptionally if action does
540       */
541      public void testThenRun3() {
542 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
543 <        FailingNoop r = new FailingNoop();
544 <        CompletableFuture<Void> g = f.thenRun(r);
542 >        CompletableFuture<Integer> f;
543 >        CompletableFuture<Void> g;
544 >        FailingNoop r;
545 >
546 >        f = new CompletableFuture<>();
547 >        g = f.thenRun(r = new FailingNoop());
548 >        f.complete(null);
549 >        checkCompletedWithWrappedCFException(g);
550 >
551 >        f = new CompletableFuture<>();
552          f.complete(null);
553 +        g = f.thenRun(r = new FailingNoop());
554          checkCompletedWithWrappedCFException(g);
555      }
556  
# Line 502 | Line 558 | public class CompletableFutureTest exten
558       * thenRun result completes exceptionally if source cancelled
559       */
560      public void testThenRun4() {
561 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
562 <        Noop r = new Noop();
563 <        CompletableFuture<Void> g = f.thenRun(r);
561 >        CompletableFuture<Integer> f;
562 >        CompletableFuture<Void> g;
563 >        Noop r;
564 >
565 >        f = new CompletableFuture<>();
566 >        g = f.thenRun(r = new Noop());
567 >        assertTrue(f.cancel(true));
568 >        checkCompletedWithWrappedCancellationException(g);
569 >
570 >        f = new CompletableFuture<>();
571          assertTrue(f.cancel(true));
572 +        g = f.thenRun(r = new Noop());
573          checkCompletedWithWrappedCancellationException(g);
574      }
575  
# Line 513 | Line 577 | public class CompletableFutureTest exten
577       * thenApply result completes normally after normal completion of source
578       */
579      public void testThenApply() {
580 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
580 >        CompletableFuture<Integer> f = new CompletableFuture<>();
581          CompletableFuture<Integer> g = f.thenApply(inc);
582          f.complete(one);
583          checkCompletedNormally(g, two);
# Line 524 | Line 588 | public class CompletableFutureTest exten
588       * completion of source
589       */
590      public void testThenApply2() {
591 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
591 >        CompletableFuture<Integer> f = new CompletableFuture<>();
592          CompletableFuture<Integer> g = f.thenApply(inc);
593          f.completeExceptionally(new CFException());
594          checkCompletedWithWrappedCFException(g);
# Line 534 | Line 598 | public class CompletableFutureTest exten
598       * thenApply result completes exceptionally if action does
599       */
600      public void testThenApply3() {
601 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
601 >        CompletableFuture<Integer> f = new CompletableFuture<>();
602          CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
603          f.complete(one);
604          checkCompletedWithWrappedCFException(g);
# Line 544 | Line 608 | public class CompletableFutureTest exten
608       * thenApply result completes exceptionally if source cancelled
609       */
610      public void testThenApply4() {
611 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
611 >        CompletableFuture<Integer> f = new CompletableFuture<>();
612          CompletableFuture<Integer> g = f.thenApply(inc);
613          assertTrue(f.cancel(true));
614          checkCompletedWithWrappedCancellationException(g);
# Line 554 | Line 618 | public class CompletableFutureTest exten
618       * thenAccept result completes normally after normal completion of source
619       */
620      public void testThenAccept() {
621 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
621 >        CompletableFuture<Integer> f = new CompletableFuture<>();
622          IncAction r = new IncAction();
623          CompletableFuture<Void> g = f.thenAccept(r);
624          f.complete(one);
# Line 567 | Line 631 | public class CompletableFutureTest exten
631       * completion of source
632       */
633      public void testThenAccept2() {
634 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
634 >        CompletableFuture<Integer> f = new CompletableFuture<>();
635          IncAction r = new IncAction();
636          CompletableFuture<Void> g = f.thenAccept(r);
637          f.completeExceptionally(new CFException());
# Line 578 | Line 642 | public class CompletableFutureTest exten
642       * thenAccept result completes exceptionally if action does
643       */
644      public void testThenAccept3() {
645 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
645 >        CompletableFuture<Integer> f = new CompletableFuture<>();
646          FailingConsumer r = new FailingConsumer();
647          CompletableFuture<Void> g = f.thenAccept(r);
648          f.complete(one);
# Line 590 | Line 654 | public class CompletableFutureTest exten
654       * thenAccept result completes exceptionally if source cancelled
655       */
656      public void testThenAccept4() {
657 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
657 >        CompletableFuture<Integer> f = new CompletableFuture<>();
658          IncAction r = new IncAction();
659          CompletableFuture<Void> g = f.thenAccept(r);
660          assertTrue(f.cancel(true));
661          checkCompletedWithWrappedCancellationException(g);
662      }
663  
600
664      /**
665 <     * thenCombine result completes normally after normal completion of sources
665 >     * thenCombine result completes normally after normal completion
666 >     * of sources
667       */
668      public void testThenCombine() {
669 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
606 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
607 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
608 <        f.complete(one);
609 <        checkIncomplete(g);
610 <        f2.complete(two);
611 <        checkCompletedNormally(g, three);
669 >        CompletableFuture<Integer> f, g, h;
670  
671 <        f = new CompletableFuture<Integer>();
672 <        f.complete(one);
673 <        f2 = new CompletableFuture<Integer>();
674 <        g = f.thenCombine(f2, add);
675 <        checkIncomplete(g);
676 <        f2.complete(two);
677 <        checkCompletedNormally(g, three);
671 >        f = new CompletableFuture<>();
672 >        g = new CompletableFuture<>();
673 >        h = f.thenCombine(g, subtract);
674 >        f.complete(3);
675 >        checkIncomplete(h);
676 >        g.complete(1);
677 >        checkCompletedNormally(h, 2);
678 >
679 >        f = new CompletableFuture<>();
680 >        g = new CompletableFuture<>();
681 >        h = f.thenCombine(g, subtract);
682 >        g.complete(1);
683 >        checkIncomplete(h);
684 >        f.complete(3);
685 >        checkCompletedNormally(h, 2);
686 >
687 >        f = new CompletableFuture<>();
688 >        g = new CompletableFuture<>();
689 >        g.complete(1);
690 >        f.complete(3);
691 >        h = f.thenCombine(g, subtract);
692 >        checkCompletedNormally(h, 2);
693      }
694  
695      /**
# Line 624 | Line 697 | public class CompletableFutureTest exten
697       * completion of either source
698       */
699      public void testThenCombine2() {
700 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
628 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
629 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
630 <        f.completeExceptionally(new CFException());
631 <        f2.complete(two);
632 <        checkCompletedWithWrappedCFException(g);
700 >        CompletableFuture<Integer> f, g, h;
701  
702 <        f = new CompletableFuture<Integer>();
703 <        f.complete(one);
704 <        f2 = new CompletableFuture<Integer>();
705 <        g = f.thenCombine(f2, add);
706 <        f2.completeExceptionally(new CFException());
707 <        checkCompletedWithWrappedCFException(g);
702 >        f = new CompletableFuture<>();
703 >        g = new CompletableFuture<>();
704 >        h = f.thenCombine(g, subtract);
705 >        f.completeExceptionally(new CFException());
706 >        checkIncomplete(h);
707 >        g.complete(1);
708 >        checkCompletedWithWrappedCFException(h);
709 >
710 >        f = new CompletableFuture<>();
711 >        g = new CompletableFuture<>();
712 >        h = f.thenCombine(g, subtract);
713 >        g.completeExceptionally(new CFException());
714 >        checkIncomplete(h);
715 >        f.complete(3);
716 >        checkCompletedWithWrappedCFException(h);
717 >
718 >        f = new CompletableFuture<>();
719 >        g = new CompletableFuture<>();
720 >        f.complete(3);
721 >        g.completeExceptionally(new CFException());
722 >        h = f.thenCombine(g, subtract);
723 >        checkCompletedWithWrappedCFException(h);
724 >
725 >        f = new CompletableFuture<>();
726 >        g = new CompletableFuture<>();
727 >        f.completeExceptionally(new CFException());
728 >        g.complete(3);
729 >        h = f.thenCombine(g, subtract);
730 >        checkCompletedWithWrappedCFException(h);
731      }
732  
733      /**
734       * thenCombine result completes exceptionally if action does
735       */
736      public void testThenCombine3() {
737 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
738 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
737 >        CompletableFuture<Integer> f = new CompletableFuture<>();
738 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
739          FailingBiFunction r = new FailingBiFunction();
740          CompletableFuture<Integer> g = f.thenCombine(f2, r);
741          f.complete(one);
742          checkIncomplete(g);
743 +        assertFalse(r.ran);
744          f2.complete(two);
745          checkCompletedWithWrappedCFException(g);
746 +        assertTrue(r.ran);
747      }
748  
749      /**
750       * thenCombine result completes exceptionally if either source cancelled
751       */
752      public void testThenCombine4() {
753 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
754 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
755 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
756 <        assertTrue(f.cancel(true));
757 <        f2.complete(two);
758 <        checkCompletedWithWrappedCancellationException(g);
759 <        f = new CompletableFuture<Integer>();
760 <        f2 = new CompletableFuture<Integer>();
761 <        g = f.thenCombine(f2, add);
762 <        f.complete(one);
763 <        assertTrue(f2.cancel(true));
764 <        checkCompletedWithWrappedCancellationException(g);
753 >        CompletableFuture<Integer> f, g, h;
754 >
755 >        f = new CompletableFuture<>();
756 >        g = new CompletableFuture<>();
757 >        h = f.thenCombine(g, subtract);
758 >        assertTrue(f.cancel(true));
759 >        checkIncomplete(h);
760 >        g.complete(1);
761 >        checkCompletedWithWrappedCancellationException(h);
762 >
763 >        f = new CompletableFuture<>();
764 >        g = new CompletableFuture<>();
765 >        h = f.thenCombine(g, subtract);
766 >        assertTrue(g.cancel(true));
767 >        checkIncomplete(h);
768 >        f.complete(3);
769 >        checkCompletedWithWrappedCancellationException(h);
770 >
771 >        f = new CompletableFuture<>();
772 >        g = new CompletableFuture<>();
773 >        assertTrue(f.cancel(true));
774 >        assertTrue(g.cancel(true));
775 >        h = f.thenCombine(g, subtract);
776 >        checkCompletedWithWrappedCancellationException(h);
777      }
778  
779      /**
# Line 676 | Line 781 | public class CompletableFutureTest exten
781       * completion of sources
782       */
783      public void testThenAcceptBoth() {
784 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
785 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
786 <        AddAction r = new AddAction();
787 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
788 <        f.complete(one);
789 <        checkIncomplete(g);
790 <        f2.complete(two);
791 <        checkCompletedNormally(g, null);
792 <        assertEquals(r.value, 3);
784 >        CompletableFuture<Integer> f, g;
785 >        CompletableFuture<Void> h;
786 >        SubtractAction r;
787 >
788 >        f = new CompletableFuture<>();
789 >        g = new CompletableFuture<>();
790 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
791 >        f.complete(3);
792 >        checkIncomplete(h);
793 >        g.complete(1);
794 >        checkCompletedNormally(h, null);
795 >        assertEquals(r.value, 2);
796  
797 <        r = new AddAction();
798 <        f = new CompletableFuture<Integer>();
799 <        f.complete(one);
800 <        f2 = new CompletableFuture<Integer>();
801 <        g = f.thenAcceptBoth(f2, r);
802 <        checkIncomplete(g);
803 <        f2.complete(two);
804 <        checkCompletedNormally(g, null);
805 <        assertEquals(r.value, 3);
797 >        f = new CompletableFuture<>();
798 >        g = new CompletableFuture<>();
799 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
800 >        g.complete(1);
801 >        checkIncomplete(h);
802 >        f.complete(3);
803 >        checkCompletedNormally(h, null);
804 >        assertEquals(r.value, 2);
805 >
806 >        f = new CompletableFuture<>();
807 >        g = new CompletableFuture<>();
808 >        g.complete(1);
809 >        f.complete(3);
810 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
811 >        checkCompletedNormally(h, null);
812 >        assertEquals(r.value, 2);
813      }
814  
815      /**
# Line 702 | Line 817 | public class CompletableFutureTest exten
817       * completion of either source
818       */
819      public void testThenAcceptBoth2() {
820 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
821 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
822 <        AddAction r = new AddAction();
823 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
824 <        f.completeExceptionally(new CFException());
825 <        f2.complete(two);
826 <        checkCompletedWithWrappedCFException(g);
827 <
828 <        r = new AddAction();
829 <        f = new CompletableFuture<Integer>();
830 <        f.complete(one);
831 <        f2 = new CompletableFuture<Integer>();
832 <        g = f.thenAcceptBoth(f2, r);
833 <        f2.completeExceptionally(new CFException());
834 <        checkCompletedWithWrappedCFException(g);
820 >        CompletableFuture<Integer> f, g;
821 >        CompletableFuture<Void> h;
822 >        SubtractAction r;
823 >
824 >        f = new CompletableFuture<>();
825 >        g = new CompletableFuture<>();
826 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
827 >        f.completeExceptionally(new CFException());
828 >        checkIncomplete(h);
829 >        g.complete(1);
830 >        checkCompletedWithWrappedCFException(h);
831 >
832 >        f = new CompletableFuture<>();
833 >        g = new CompletableFuture<>();
834 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
835 >        g.completeExceptionally(new CFException());
836 >        checkIncomplete(h);
837 >        f.complete(3);
838 >        checkCompletedWithWrappedCFException(h);
839 >
840 >        f = new CompletableFuture<>();
841 >        g = new CompletableFuture<>();
842 >        f.complete(3);
843 >        g.completeExceptionally(new CFException());
844 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
845 >        checkCompletedWithWrappedCFException(h);
846 >
847 >        f = new CompletableFuture<>();
848 >        g = new CompletableFuture<>();
849 >        f.completeExceptionally(new CFException());
850 >        g.complete(3);
851 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
852 >        checkCompletedWithWrappedCFException(h);
853      }
854  
855      /**
856       * thenAcceptBoth result completes exceptionally if action does
857       */
858      public void testThenAcceptBoth3() {
859 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
860 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
861 <        FailingBiConsumer r = new FailingBiConsumer();
862 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
863 <        f.complete(one);
864 <        checkIncomplete(g);
865 <        f2.complete(two);
866 <        checkCompletedWithWrappedCFException(g);
859 >        CompletableFuture<Integer> f, g;
860 >        CompletableFuture<Void> h;
861 >        FailingBiConsumer r;
862 >
863 >        f = new CompletableFuture<>();
864 >        g = new CompletableFuture<>();
865 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
866 >        f.complete(3);
867 >        checkIncomplete(h);
868 >        g.complete(1);
869 >        checkCompletedWithWrappedCFException(h);
870 >
871 >        f = new CompletableFuture<>();
872 >        g = new CompletableFuture<>();
873 >        f.complete(3);
874 >        g.complete(1);
875 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
876 >        checkCompletedWithWrappedCFException(h);
877      }
878  
879      /**
880       * thenAcceptBoth result completes exceptionally if either source cancelled
881       */
882      public void testThenAcceptBoth4() {
883 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
884 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
885 <        AddAction r = new AddAction();
886 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
887 <        assertTrue(f.cancel(true));
888 <        f2.complete(two);
889 <        checkCompletedWithWrappedCancellationException(g);
890 <        f = new CompletableFuture<Integer>();
891 <        f2 = new CompletableFuture<Integer>();
892 <        r = new AddAction();
893 <        g = f.thenAcceptBoth(f2, r);
894 <        f.complete(one);
895 <        assertTrue(f2.cancel(true));
896 <        checkCompletedWithWrappedCancellationException(g);
883 >        CompletableFuture<Integer> f, g;
884 >        CompletableFuture<Void> h;
885 >        SubtractAction r;
886 >
887 >        f = new CompletableFuture<>();
888 >        g = new CompletableFuture<>();
889 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
890 >        assertTrue(f.cancel(true));
891 >        checkIncomplete(h);
892 >        g.complete(1);
893 >        checkCompletedWithWrappedCancellationException(h);
894 >
895 >        f = new CompletableFuture<>();
896 >        g = new CompletableFuture<>();
897 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
898 >        assertTrue(g.cancel(true));
899 >        checkIncomplete(h);
900 >        f.complete(3);
901 >        checkCompletedWithWrappedCancellationException(h);
902 >
903 >        f = new CompletableFuture<>();
904 >        g = new CompletableFuture<>();
905 >        f.complete(3);
906 >        assertTrue(g.cancel(true));
907 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
908 >        checkCompletedWithWrappedCancellationException(h);
909 >
910 >        f = new CompletableFuture<>();
911 >        g = new CompletableFuture<>();
912 >        assertTrue(f.cancel(true));
913 >        g.complete(3);
914 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
915 >        checkCompletedWithWrappedCancellationException(h);
916      }
917  
918      /**
# Line 758 | Line 920 | public class CompletableFutureTest exten
920       * completion of sources
921       */
922      public void testRunAfterBoth() {
923 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
924 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
925 <        Noop r = new Noop();
926 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
927 <        f.complete(one);
928 <        checkIncomplete(g);
929 <        f2.complete(two);
930 <        checkCompletedNormally(g, null);
923 >        CompletableFuture<Integer> f, g;
924 >        CompletableFuture<Void> h;
925 >        Noop r;
926 >
927 >        f = new CompletableFuture<>();
928 >        g = new CompletableFuture<>();
929 >        h = f.runAfterBoth(g, r = new Noop());
930 >        f.complete(3);
931 >        checkIncomplete(h);
932 >        g.complete(1);
933 >        checkCompletedNormally(h, null);
934          assertTrue(r.ran);
935  
936 <        r = new Noop();
937 <        f = new CompletableFuture<Integer>();
938 <        f.complete(one);
939 <        f2 = new CompletableFuture<Integer>();
940 <        g = f.runAfterBoth(f2, r);
941 <        checkIncomplete(g);
942 <        f2.complete(two);
943 <        checkCompletedNormally(g, null);
936 >        f = new CompletableFuture<>();
937 >        g = new CompletableFuture<>();
938 >        h = f.runAfterBoth(g, r = new Noop());
939 >        g.complete(1);
940 >        checkIncomplete(h);
941 >        f.complete(3);
942 >        checkCompletedNormally(h, null);
943 >        assertTrue(r.ran);
944 >
945 >        f = new CompletableFuture<>();
946 >        g = new CompletableFuture<>();
947 >        g.complete(1);
948 >        f.complete(3);
949 >        h = f.runAfterBoth(g, r = new Noop());
950 >        checkCompletedNormally(h, null);
951          assertTrue(r.ran);
952      }
953  
# Line 784 | Line 956 | public class CompletableFutureTest exten
956       * completion of either source
957       */
958      public void testRunAfterBoth2() {
959 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
960 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
961 <        Noop r = new Noop();
962 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
963 <        f.completeExceptionally(new CFException());
964 <        f2.complete(two);
965 <        checkCompletedWithWrappedCFException(g);
966 <
967 <        r = new Noop();
968 <        f = new CompletableFuture<Integer>();
969 <        f.complete(one);
970 <        f2 = new CompletableFuture<Integer>();
971 <        g = f.runAfterBoth(f2, r);
972 <        f2.completeExceptionally(new CFException());
973 <        checkCompletedWithWrappedCFException(g);
959 >        CompletableFuture<Integer> f, g;
960 >        CompletableFuture<Void> h;
961 >        Noop r;
962 >
963 >        f = new CompletableFuture<>();
964 >        g = new CompletableFuture<>();
965 >        h = f.runAfterBoth(g, r = new Noop());
966 >        f.completeExceptionally(new CFException());
967 >        checkIncomplete(h);
968 >        g.complete(1);
969 >        checkCompletedWithWrappedCFException(h);
970 >        assertFalse(r.ran);
971 >
972 >        f = new CompletableFuture<>();
973 >        g = new CompletableFuture<>();
974 >        h = f.runAfterBoth(g, r = new Noop());
975 >        g.completeExceptionally(new CFException());
976 >        checkIncomplete(h);
977 >        f.complete(3);
978 >        checkCompletedWithWrappedCFException(h);
979 >        assertFalse(r.ran);
980 >
981 >        f = new CompletableFuture<>();
982 >        g = new CompletableFuture<>();
983 >        g.completeExceptionally(new CFException());
984 >        f.complete(3);
985 >        h = f.runAfterBoth(g, r = new Noop());
986 >        checkCompletedWithWrappedCFException(h);
987 >        assertFalse(r.ran);
988 >
989 >        f = new CompletableFuture<>();
990 >        g = new CompletableFuture<>();
991 >        f.completeExceptionally(new CFException());
992 >        g.complete(1);
993 >        h = f.runAfterBoth(g, r = new Noop());
994 >        checkCompletedWithWrappedCFException(h);
995 >        assertFalse(r.ran);
996      }
997  
998      /**
999       * runAfterBoth result completes exceptionally if action does
1000       */
1001      public void testRunAfterBoth3() {
1002 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1003 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1002 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1003 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1004          FailingNoop r = new FailingNoop();
1005          CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1006          f.complete(one);
# Line 819 | Line 1013 | public class CompletableFutureTest exten
1013       * runAfterBoth result completes exceptionally if either source cancelled
1014       */
1015      public void testRunAfterBoth4() {
1016 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1017 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1016 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1017 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1018          Noop r = new Noop();
1019          CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1020          assertTrue(f.cancel(true));
1021          f2.complete(two);
1022          checkCompletedWithWrappedCancellationException(g);
1023 <        f = new CompletableFuture<Integer>();
1024 <        f2 = new CompletableFuture<Integer>();
1023 >        f = new CompletableFuture<>();
1024 >        f2 = new CompletableFuture<>();
1025          r = new Noop();
1026          g = f.runAfterBoth(f2, r);
1027          f.complete(one);
# Line 840 | Line 1034 | public class CompletableFutureTest exten
1034       * of either source
1035       */
1036      public void testApplyToEither() {
1037 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1038 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1037 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1038 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1039          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1040          f.complete(one);
1041          checkCompletedNormally(g, two);
1042          f2.complete(one);
1043          checkCompletedNormally(g, two);
1044  
1045 <        f = new CompletableFuture<Integer>();
1045 >        f = new CompletableFuture<>();
1046          f.complete(one);
1047 <        f2 = new CompletableFuture<Integer>();
1047 >        f2 = new CompletableFuture<>();
1048          g = f.applyToEither(f2, inc);
1049          checkCompletedNormally(g, two);
1050      }
# Line 860 | Line 1054 | public class CompletableFutureTest exten
1054       * completion of either source
1055       */
1056      public void testApplyToEither2() {
1057 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1058 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1057 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1058 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1059          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1060          f.completeExceptionally(new CFException());
1061          f2.complete(one);
1062          checkCompletedWithWrappedCFException(g);
1063  
1064 <        f = new CompletableFuture<Integer>();
1065 <        f2 = new CompletableFuture<Integer>();
1064 >        f = new CompletableFuture<>();
1065 >        f2 = new CompletableFuture<>();
1066          f2.completeExceptionally(new CFException());
1067          g = f.applyToEither(f2, inc);
1068          checkCompletedWithWrappedCFException(g);
# Line 878 | Line 1072 | public class CompletableFutureTest exten
1072       * applyToEither result completes exceptionally if action does
1073       */
1074      public void testApplyToEither3() {
1075 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1076 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1075 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1076 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1077          FailingFunction r = new FailingFunction();
1078          CompletableFuture<Integer> g = f.applyToEither(f2, r);
1079          f2.complete(two);
# Line 890 | Line 1084 | public class CompletableFutureTest exten
1084       * applyToEither result completes exceptionally if either source cancelled
1085       */
1086      public void testApplyToEither4() {
1087 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1088 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1087 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1088 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1089          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1090          assertTrue(f.cancel(true));
1091          checkCompletedWithWrappedCancellationException(g);
1092 <        f = new CompletableFuture<Integer>();
1093 <        f2 = new CompletableFuture<Integer>();
1092 >        f = new CompletableFuture<>();
1093 >        f2 = new CompletableFuture<>();
1094          assertTrue(f2.cancel(true));
1095          checkCompletedWithWrappedCancellationException(g);
1096      }
# Line 906 | Line 1100 | public class CompletableFutureTest exten
1100       * of either source
1101       */
1102      public void testAcceptEither() {
1103 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1104 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1103 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1104 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1105          IncAction r = new IncAction();
1106          CompletableFuture<Void> g = f.acceptEither(f2, r);
1107          f.complete(one);
# Line 917 | Line 1111 | public class CompletableFutureTest exten
1111          assertEquals(r.value, 2);
1112  
1113          r = new IncAction();
1114 <        f = new CompletableFuture<Integer>();
1114 >        f = new CompletableFuture<>();
1115          f.complete(one);
1116 <        f2 = new CompletableFuture<Integer>();
1116 >        f2 = new CompletableFuture<>();
1117          g = f.acceptEither(f2, r);
1118          checkCompletedNormally(g, null);
1119          assertEquals(r.value, 2);
# Line 930 | Line 1124 | public class CompletableFutureTest exten
1124       * completion of either source
1125       */
1126      public void testAcceptEither2() {
1127 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1128 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1127 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1128 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1129          IncAction r = new IncAction();
1130          CompletableFuture<Void> g = f.acceptEither(f2, r);
1131          f.completeExceptionally(new CFException());
# Line 939 | Line 1133 | public class CompletableFutureTest exten
1133          checkCompletedWithWrappedCFException(g);
1134  
1135          r = new IncAction();
1136 <        f = new CompletableFuture<Integer>();
1137 <        f2 = new CompletableFuture<Integer>();
1136 >        f = new CompletableFuture<>();
1137 >        f2 = new CompletableFuture<>();
1138          f2.completeExceptionally(new CFException());
1139          g = f.acceptEither(f2, r);
1140          checkCompletedWithWrappedCFException(g);
# Line 950 | Line 1144 | public class CompletableFutureTest exten
1144       * acceptEither result completes exceptionally if action does
1145       */
1146      public void testAcceptEither3() {
1147 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1148 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1147 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1148 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1149          FailingConsumer r = new FailingConsumer();
1150          CompletableFuture<Void> g = f.acceptEither(f2, r);
1151          f2.complete(two);
# Line 962 | Line 1156 | public class CompletableFutureTest exten
1156       * acceptEither result completes exceptionally if either source cancelled
1157       */
1158      public void testAcceptEither4() {
1159 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1160 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1159 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1160 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1161          IncAction r = new IncAction();
1162          CompletableFuture<Void> g = f.acceptEither(f2, r);
1163          assertTrue(f.cancel(true));
1164          checkCompletedWithWrappedCancellationException(g);
1165 <        f = new CompletableFuture<Integer>();
1166 <        f2 = new CompletableFuture<Integer>();
1165 >        f = new CompletableFuture<>();
1166 >        f2 = new CompletableFuture<>();
1167          assertTrue(f2.cancel(true));
1168          checkCompletedWithWrappedCancellationException(g);
1169      }
1170  
977
1171      /**
1172       * runAfterEither result completes normally after normal completion
1173       * of either source
1174       */
1175      public void testRunAfterEither() {
1176 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1177 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1176 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1177 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1178          Noop r = new Noop();
1179          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1180          f.complete(one);
# Line 991 | Line 1184 | public class CompletableFutureTest exten
1184          assertTrue(r.ran);
1185  
1186          r = new Noop();
1187 <        f = new CompletableFuture<Integer>();
1187 >        f = new CompletableFuture<>();
1188          f.complete(one);
1189 <        f2 = new CompletableFuture<Integer>();
1189 >        f2 = new CompletableFuture<>();
1190          g = f.runAfterEither(f2, r);
1191          checkCompletedNormally(g, null);
1192          assertTrue(r.ran);
# Line 1004 | Line 1197 | public class CompletableFutureTest exten
1197       * completion of either source
1198       */
1199      public void testRunAfterEither2() {
1200 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1201 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1200 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1201 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1202          Noop r = new Noop();
1203          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1204          f.completeExceptionally(new CFException());
# Line 1013 | Line 1206 | public class CompletableFutureTest exten
1206          checkCompletedWithWrappedCFException(g);
1207  
1208          r = new Noop();
1209 <        f = new CompletableFuture<Integer>();
1210 <        f2 = new CompletableFuture<Integer>();
1209 >        f = new CompletableFuture<>();
1210 >        f2 = new CompletableFuture<>();
1211          f2.completeExceptionally(new CFException());
1212          g = f.runAfterEither(f2, r);
1213          checkCompletedWithWrappedCFException(g);
# Line 1024 | Line 1217 | public class CompletableFutureTest exten
1217       * runAfterEither result completes exceptionally if action does
1218       */
1219      public void testRunAfterEither3() {
1220 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1221 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1220 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1221 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1222          FailingNoop r = new FailingNoop();
1223          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1224          f2.complete(two);
# Line 1036 | Line 1229 | public class CompletableFutureTest exten
1229       * runAfterEither result completes exceptionally if either source cancelled
1230       */
1231      public void testRunAfterEither4() {
1232 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1233 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1232 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1233 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1234          Noop r = new Noop();
1235          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1236          assertTrue(f.cancel(true));
1237          checkCompletedWithWrappedCancellationException(g);
1238 <        f = new CompletableFuture<Integer>();
1239 <        f2 = new CompletableFuture<Integer>();
1238 >        f = new CompletableFuture<>();
1239 >        f2 = new CompletableFuture<>();
1240          assertTrue(f2.cancel(true));
1241          checkCompletedWithWrappedCancellationException(g);
1242      }
# Line 1052 | Line 1245 | public class CompletableFutureTest exten
1245       * thenCompose result completes normally after normal completion of source
1246       */
1247      public void testThenCompose() {
1248 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1249 <        CompletableFutureInc r = new CompletableFutureInc();
1250 <        CompletableFuture<Integer> g = f.thenCompose(r);
1248 >        CompletableFuture<Integer> f, g;
1249 >        CompletableFutureInc r;
1250 >
1251 >        f = new CompletableFuture<>();
1252 >        g = f.thenCompose(r = new CompletableFutureInc());
1253 >        f.complete(one);
1254 >        checkCompletedNormally(g, two);
1255 >        assertTrue(r.ran);
1256 >
1257 >        f = new CompletableFuture<>();
1258          f.complete(one);
1259 +        g = f.thenCompose(r = new CompletableFutureInc());
1260          checkCompletedNormally(g, two);
1261 +        assertTrue(r.ran);
1262      }
1263  
1264      /**
# Line 1064 | Line 1266 | public class CompletableFutureTest exten
1266       * completion of source
1267       */
1268      public void testThenCompose2() {
1269 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1270 <        CompletableFutureInc r = new CompletableFutureInc();
1271 <        CompletableFuture<Integer> g = f.thenCompose(r);
1269 >        CompletableFuture<Integer> f, g;
1270 >        CompletableFutureInc r;
1271 >
1272 >        f = new CompletableFuture<>();
1273 >        g = f.thenCompose(r = new CompletableFutureInc());
1274 >        f.completeExceptionally(new CFException());
1275 >        checkCompletedWithWrappedCFException(g);
1276 >
1277 >        f = new CompletableFuture<>();
1278          f.completeExceptionally(new CFException());
1279 +        g = f.thenCompose(r = new CompletableFutureInc());
1280          checkCompletedWithWrappedCFException(g);
1281      }
1282  
# Line 1075 | Line 1284 | public class CompletableFutureTest exten
1284       * thenCompose result completes exceptionally if action does
1285       */
1286      public void testThenCompose3() {
1287 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1288 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
1289 <        CompletableFuture<Integer> g = f.thenCompose(r);
1287 >        CompletableFuture<Integer> f, g;
1288 >        FailingCompletableFutureFunction r;
1289 >
1290 >        f = new CompletableFuture<>();
1291 >        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1292 >        f.complete(one);
1293 >        checkCompletedWithWrappedCFException(g);
1294 >
1295 >        f = new CompletableFuture<>();
1296          f.complete(one);
1297 +        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1298          checkCompletedWithWrappedCFException(g);
1299      }
1300  
# Line 1086 | Line 1302 | public class CompletableFutureTest exten
1302       * thenCompose result completes exceptionally if source cancelled
1303       */
1304      public void testThenCompose4() {
1305 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1306 <        CompletableFutureInc r = new CompletableFutureInc();
1307 <        CompletableFuture<Integer> g = f.thenCompose(r);
1305 >        CompletableFuture<Integer> f, g;
1306 >        CompletableFutureInc r;
1307 >
1308 >        f = new CompletableFuture<>();
1309 >        g = f.thenCompose(r = new CompletableFutureInc());
1310          assertTrue(f.cancel(true));
1311          checkCompletedWithWrappedCancellationException(g);
1094    }
1312  
1313 +        f = new CompletableFuture<>();
1314 +        assertTrue(f.cancel(true));
1315 +        g = f.thenCompose(r = new CompletableFutureInc());
1316 +        checkCompletedWithWrappedCancellationException(g);
1317 +    }
1318  
1319      // asyncs
1320  
# Line 1100 | Line 1322 | public class CompletableFutureTest exten
1322       * thenRunAsync result completes normally after normal completion of source
1323       */
1324      public void testThenRunAsync() {
1325 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1325 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1326          Noop r = new Noop();
1327          CompletableFuture<Void> g = f.thenRunAsync(r);
1328          f.complete(null);
1329          checkCompletedNormally(g, null);
1330  
1331          // reordered version
1332 <        f = new CompletableFuture<Integer>();
1332 >        f = new CompletableFuture<>();
1333          f.complete(null);
1334          r = new Noop();
1335          g = f.thenRunAsync(r);
# Line 1119 | Line 1341 | public class CompletableFutureTest exten
1341       * completion of source
1342       */
1343      public void testThenRunAsync2() {
1344 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1344 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1345          Noop r = new Noop();
1346          CompletableFuture<Void> g = f.thenRunAsync(r);
1347          f.completeExceptionally(new CFException());
# Line 1135 | Line 1357 | public class CompletableFutureTest exten
1357       * thenRunAsync result completes exceptionally if action does
1358       */
1359      public void testThenRunAsync3() {
1360 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1360 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1361          FailingNoop r = new FailingNoop();
1362          CompletableFuture<Void> g = f.thenRunAsync(r);
1363          f.complete(null);
# Line 1146 | Line 1368 | public class CompletableFutureTest exten
1368       * thenRunAsync result completes exceptionally if source cancelled
1369       */
1370      public void testThenRunAsync4() {
1371 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1371 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1372          Noop r = new Noop();
1373          CompletableFuture<Void> g = f.thenRunAsync(r);
1374          assertTrue(f.cancel(true));
# Line 1157 | Line 1379 | public class CompletableFutureTest exten
1379       * thenApplyAsync result completes normally after normal completion of source
1380       */
1381      public void testThenApplyAsync() {
1382 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1382 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1383          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1384          f.complete(one);
1385          checkCompletedNormally(g, two);
# Line 1168 | Line 1390 | public class CompletableFutureTest exten
1390       * completion of source
1391       */
1392      public void testThenApplyAsync2() {
1393 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1393 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1394          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1395          f.completeExceptionally(new CFException());
1396          checkCompletedWithWrappedCFException(g);
# Line 1178 | Line 1400 | public class CompletableFutureTest exten
1400       * thenApplyAsync result completes exceptionally if action does
1401       */
1402      public void testThenApplyAsync3() {
1403 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1403 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1404          FailingFunction r = new FailingFunction();
1405          CompletableFuture<Integer> g = f.thenApplyAsync(r);
1406          f.complete(null);
# Line 1189 | Line 1411 | public class CompletableFutureTest exten
1411       * thenApplyAsync result completes exceptionally if source cancelled
1412       */
1413      public void testThenApplyAsync4() {
1414 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1414 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1415          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1416          assertTrue(f.cancel(true));
1417          checkCompletedWithWrappedCancellationException(g);
# Line 1200 | Line 1422 | public class CompletableFutureTest exten
1422       * completion of source
1423       */
1424      public void testThenAcceptAsync() {
1425 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1425 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1426          IncAction r = new IncAction();
1427          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1428          f.complete(one);
# Line 1213 | Line 1435 | public class CompletableFutureTest exten
1435       * completion of source
1436       */
1437      public void testThenAcceptAsync2() {
1438 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1438 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1439          IncAction r = new IncAction();
1440          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1441          f.completeExceptionally(new CFException());
# Line 1224 | Line 1446 | public class CompletableFutureTest exten
1446       * thenAcceptAsync result completes exceptionally if action does
1447       */
1448      public void testThenAcceptAsync3() {
1449 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1449 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1450          FailingConsumer r = new FailingConsumer();
1451          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1452          f.complete(null);
# Line 1235 | Line 1457 | public class CompletableFutureTest exten
1457       * thenAcceptAsync result completes exceptionally if source cancelled
1458       */
1459      public void testThenAcceptAsync4() {
1460 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1460 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1461          IncAction r = new IncAction();
1462          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1463          assertTrue(f.cancel(true));
1464          checkCompletedWithWrappedCancellationException(g);
1465      }
1466 +
1467      /**
1468       * thenCombineAsync result completes normally after normal
1469       * completion of sources
1470       */
1471      public void testThenCombineAsync() {
1472 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1473 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1474 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1475 <        f.complete(one);
1476 <        checkIncomplete(g);
1477 <        f2.complete(two);
1478 <        checkCompletedNormally(g, three);
1472 >        CompletableFuture<Integer> f, g, h;
1473 >
1474 >        f = new CompletableFuture<>();
1475 >        g = new CompletableFuture<>();
1476 >        h = f.thenCombineAsync(g, subtract);
1477 >        f.complete(3);
1478 >        checkIncomplete(h);
1479 >        g.complete(1);
1480 >        checkCompletedNormally(h, 2);
1481 >
1482 >        f = new CompletableFuture<>();
1483 >        g = new CompletableFuture<>();
1484 >        h = f.thenCombineAsync(g, subtract);
1485 >        g.complete(1);
1486 >        checkIncomplete(h);
1487 >        f.complete(3);
1488 >        checkCompletedNormally(h, 2);
1489 >
1490 >        f = new CompletableFuture<>();
1491 >        g = new CompletableFuture<>();
1492 >        g.complete(1);
1493 >        f.complete(3);
1494 >        h = f.thenCombineAsync(g, subtract);
1495 >        checkCompletedNormally(h, 2);
1496      }
1497  
1498      /**
1499       * thenCombineAsync result completes exceptionally after exceptional
1500 <     * completion of source
1500 >     * completion of either source
1501       */
1502      public void testThenCombineAsync2() {
1503 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1264 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1265 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1266 <        f.completeExceptionally(new CFException());
1267 <        f2.complete(two);
1268 <        checkCompletedWithWrappedCFException(g);
1503 >        CompletableFuture<Integer> f, g, h;
1504  
1505 <        f = new CompletableFuture<Integer>();
1506 <        f2 = new CompletableFuture<Integer>();
1507 <        g = f.thenCombineAsync(f2, add);
1508 <        f.complete(one);
1509 <        f2.completeExceptionally(new CFException());
1510 <        checkCompletedWithWrappedCFException(g);
1505 >        f = new CompletableFuture<>();
1506 >        g = new CompletableFuture<>();
1507 >        h = f.thenCombineAsync(g, subtract);
1508 >        f.completeExceptionally(new CFException());
1509 >        checkIncomplete(h);
1510 >        g.complete(1);
1511 >        checkCompletedWithWrappedCFException(h);
1512 >
1513 >        f = new CompletableFuture<>();
1514 >        g = new CompletableFuture<>();
1515 >        h = f.thenCombineAsync(g, subtract);
1516 >        g.completeExceptionally(new CFException());
1517 >        checkIncomplete(h);
1518 >        f.complete(3);
1519 >        checkCompletedWithWrappedCFException(h);
1520 >
1521 >        f = new CompletableFuture<>();
1522 >        g = new CompletableFuture<>();
1523 >        g.completeExceptionally(new CFException());
1524 >        f.complete(3);
1525 >        h = f.thenCombineAsync(g, subtract);
1526 >        checkCompletedWithWrappedCFException(h);
1527      }
1528  
1529      /**
1530       * thenCombineAsync result completes exceptionally if action does
1531       */
1532      public void testThenCombineAsync3() {
1533 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1534 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1533 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1534 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1535          FailingBiFunction r = new FailingBiFunction();
1536          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r);
1537          f.complete(one);
1538          checkIncomplete(g);
1539 +        assertFalse(r.ran);
1540          f2.complete(two);
1541          checkCompletedWithWrappedCFException(g);
1542 +        assertTrue(r.ran);
1543      }
1544  
1545      /**
1546       * thenCombineAsync result completes exceptionally if either source cancelled
1547       */
1548      public void testThenCombineAsync4() {
1549 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1297 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1298 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1299 <        assertTrue(f.cancel(true));
1300 <        f2.complete(two);
1301 <        checkCompletedWithWrappedCancellationException(g);
1549 >        CompletableFuture<Integer> f, g, h;
1550  
1551 <        f = new CompletableFuture<Integer>();
1552 <        f2 = new CompletableFuture<Integer>();
1553 <        g = f.thenCombineAsync(f2, add);
1554 <        f.complete(one);
1555 <        assertTrue(f2.cancel(true));
1556 <        checkCompletedWithWrappedCancellationException(g);
1551 >        f = new CompletableFuture<>();
1552 >        g = new CompletableFuture<>();
1553 >        h = f.thenCombineAsync(g, subtract);
1554 >        assertTrue(f.cancel(true));
1555 >        checkIncomplete(h);
1556 >        g.complete(1);
1557 >        checkCompletedWithWrappedCancellationException(h);
1558 >
1559 >        f = new CompletableFuture<>();
1560 >        g = new CompletableFuture<>();
1561 >        h = f.thenCombineAsync(g, subtract);
1562 >        assertTrue(g.cancel(true));
1563 >        checkIncomplete(h);
1564 >        f.complete(3);
1565 >        checkCompletedWithWrappedCancellationException(h);
1566 >
1567 >        f = new CompletableFuture<>();
1568 >        g = new CompletableFuture<>();
1569 >        g.complete(3);
1570 >        assertTrue(f.cancel(true));
1571 >        h = f.thenCombineAsync(g, subtract);
1572 >        checkCompletedWithWrappedCancellationException(h);
1573 >
1574 >        f = new CompletableFuture<>();
1575 >        g = new CompletableFuture<>();
1576 >        f.complete(3);
1577 >        assertTrue(g.cancel(true));
1578 >        h = f.thenCombineAsync(g, subtract);
1579 >        checkCompletedWithWrappedCancellationException(h);
1580      }
1581  
1582      /**
# Line 1313 | Line 1584 | public class CompletableFutureTest exten
1584       * completion of sources
1585       */
1586      public void testThenAcceptBothAsync() {
1587 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1588 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1589 <        AddAction r = new AddAction();
1590 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1591 <        f.complete(one);
1592 <        checkIncomplete(g);
1593 <        f2.complete(two);
1594 <        checkCompletedNormally(g, null);
1595 <        assertEquals(r.value, 3);
1587 >        CompletableFuture<Integer> f, g;
1588 >        CompletableFuture<Void> h;
1589 >        SubtractAction r;
1590 >
1591 >        f = new CompletableFuture<>();
1592 >        g = new CompletableFuture<>();
1593 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1594 >        f.complete(3);
1595 >        checkIncomplete(h);
1596 >        g.complete(1);
1597 >        checkCompletedNormally(h, null);
1598 >        assertEquals(r.value, 2);
1599 >
1600 >        f = new CompletableFuture<>();
1601 >        g = new CompletableFuture<>();
1602 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1603 >        g.complete(1);
1604 >        checkIncomplete(h);
1605 >        f.complete(3);
1606 >        checkCompletedNormally(h, null);
1607 >        assertEquals(r.value, 2);
1608 >
1609 >        f = new CompletableFuture<>();
1610 >        g = new CompletableFuture<>();
1611 >        g.complete(1);
1612 >        f.complete(3);
1613 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1614 >        checkCompletedNormally(h, null);
1615 >        assertEquals(r.value, 2);
1616      }
1617  
1618      /**
# Line 1329 | Line 1620 | public class CompletableFutureTest exten
1620       * completion of source
1621       */
1622      public void testThenAcceptBothAsync2() {
1623 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1624 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1625 <        AddAction r = new AddAction();
1626 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1627 <        f.completeExceptionally(new CFException());
1628 <        f2.complete(two);
1629 <        checkCompletedWithWrappedCFException(g);
1630 <
1631 <        r = new AddAction();
1632 <        f = new CompletableFuture<Integer>();
1633 <        f2 = new CompletableFuture<Integer>();
1634 <        g = f.thenAcceptBothAsync(f2, r);
1635 <        f.complete(one);
1636 <        f2.completeExceptionally(new CFException());
1637 <        checkCompletedWithWrappedCFException(g);
1623 >        CompletableFuture<Integer> f, g;
1624 >        CompletableFuture<Void> h;
1625 >        SubtractAction r;
1626 >
1627 >        f = new CompletableFuture<>();
1628 >        g = new CompletableFuture<>();
1629 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1630 >        f.completeExceptionally(new CFException());
1631 >        checkIncomplete(h);
1632 >        g.complete(1);
1633 >        checkCompletedWithWrappedCFException(h);
1634 >
1635 >        f = new CompletableFuture<>();
1636 >        g = new CompletableFuture<>();
1637 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1638 >        g.completeExceptionally(new CFException());
1639 >        checkIncomplete(h);
1640 >        f.complete(3);
1641 >        checkCompletedWithWrappedCFException(h);
1642 >
1643 >        f = new CompletableFuture<>();
1644 >        g = new CompletableFuture<>();
1645 >        f.complete(3);
1646 >        g.completeExceptionally(new CFException());
1647 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1648 >        checkCompletedWithWrappedCFException(h);
1649 >
1650 >        f = new CompletableFuture<>();
1651 >        g = new CompletableFuture<>();
1652 >        f.completeExceptionally(new CFException());
1653 >        g.complete(3);
1654 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1655 >        checkCompletedWithWrappedCFException(h);
1656      }
1657  
1658      /**
1659       * thenAcceptBothAsync result completes exceptionally if action does
1660       */
1661      public void testThenAcceptBothAsync3() {
1662 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1663 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1664 <        FailingBiConsumer r = new FailingBiConsumer();
1665 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1666 <        f.complete(one);
1667 <        checkIncomplete(g);
1668 <        f2.complete(two);
1669 <        checkCompletedWithWrappedCFException(g);
1662 >        CompletableFuture<Integer> f, g;
1663 >        CompletableFuture<Void> h;
1664 >        FailingBiConsumer r;
1665 >
1666 >        f = new CompletableFuture<>();
1667 >        g = new CompletableFuture<>();
1668 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1669 >        f.complete(3);
1670 >        checkIncomplete(h);
1671 >        g.complete(1);
1672 >        checkCompletedWithWrappedCFException(h);
1673 >
1674 >        f = new CompletableFuture<>();
1675 >        g = new CompletableFuture<>();
1676 >        f.complete(3);
1677 >        g.complete(1);
1678 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1679 >        checkCompletedWithWrappedCFException(h);
1680      }
1681  
1682      /**
1683       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1684       */
1685      public void testThenAcceptBothAsync4() {
1686 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1687 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1688 <        AddAction r = new AddAction();
1689 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1690 <        assertTrue(f.cancel(true));
1691 <        f2.complete(two);
1692 <        checkCompletedWithWrappedCancellationException(g);
1693 <
1694 <        r = new AddAction();
1695 <        f = new CompletableFuture<Integer>();
1696 <        f2 = new CompletableFuture<Integer>();
1697 <        g = f.thenAcceptBothAsync(f2, r);
1698 <        f.complete(one);
1699 <        assertTrue(f2.cancel(true));
1700 <        checkCompletedWithWrappedCancellationException(g);
1686 >        CompletableFuture<Integer> f, g;
1687 >        CompletableFuture<Void> h;
1688 >        SubtractAction r;
1689 >
1690 >        f = new CompletableFuture<>();
1691 >        g = new CompletableFuture<>();
1692 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1693 >        assertTrue(f.cancel(true));
1694 >        checkIncomplete(h);
1695 >        g.complete(1);
1696 >        checkCompletedWithWrappedCancellationException(h);
1697 >
1698 >        f = new CompletableFuture<>();
1699 >        g = new CompletableFuture<>();
1700 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1701 >        assertTrue(g.cancel(true));
1702 >        checkIncomplete(h);
1703 >        f.complete(3);
1704 >        checkCompletedWithWrappedCancellationException(h);
1705 >
1706 >        f = new CompletableFuture<>();
1707 >        g = new CompletableFuture<>();
1708 >        f.complete(3);
1709 >        assertTrue(g.cancel(true));
1710 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1711 >        checkCompletedWithWrappedCancellationException(h);
1712 >
1713 >        f = new CompletableFuture<>();
1714 >        g = new CompletableFuture<>();
1715 >        assertTrue(f.cancel(true));
1716 >        g.complete(3);
1717 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1718 >        checkCompletedWithWrappedCancellationException(h);
1719      }
1720  
1721      /**
# Line 1386 | Line 1723 | public class CompletableFutureTest exten
1723       * completion of sources
1724       */
1725      public void testRunAfterBothAsync() {
1726 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1727 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1726 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1727 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1728          Noop r = new Noop();
1729          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1730          f.complete(one);
# Line 1402 | Line 1739 | public class CompletableFutureTest exten
1739       * completion of source
1740       */
1741      public void testRunAfterBothAsync2() {
1742 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1743 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1742 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1743 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1744          Noop r = new Noop();
1745          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1746          f.completeExceptionally(new CFException());
# Line 1411 | Line 1748 | public class CompletableFutureTest exten
1748          checkCompletedWithWrappedCFException(g);
1749  
1750          r = new Noop();
1751 <        f = new CompletableFuture<Integer>();
1752 <        f2 = new CompletableFuture<Integer>();
1751 >        f = new CompletableFuture<>();
1752 >        f2 = new CompletableFuture<>();
1753          g = f.runAfterBothAsync(f2, r);
1754          f.complete(one);
1755          f2.completeExceptionally(new CFException());
# Line 1423 | Line 1760 | public class CompletableFutureTest exten
1760       * runAfterBothAsync result completes exceptionally if action does
1761       */
1762      public void testRunAfterBothAsync3() {
1763 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1764 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1763 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1764 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1765          FailingNoop r = new FailingNoop();
1766          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1767          f.complete(one);
# Line 1437 | Line 1774 | public class CompletableFutureTest exten
1774       * runAfterBothAsync result completes exceptionally if either source cancelled
1775       */
1776      public void testRunAfterBothAsync4() {
1777 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1778 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1777 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1778 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1779          Noop r = new Noop();
1780          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1781          assertTrue(f.cancel(true));
# Line 1446 | Line 1783 | public class CompletableFutureTest exten
1783          checkCompletedWithWrappedCancellationException(g);
1784  
1785          r = new Noop();
1786 <        f = new CompletableFuture<Integer>();
1787 <        f2 = new CompletableFuture<Integer>();
1786 >        f = new CompletableFuture<>();
1787 >        f2 = new CompletableFuture<>();
1788          g = f.runAfterBothAsync(f2, r);
1789          f.complete(one);
1790          assertTrue(f2.cancel(true));
# Line 1459 | Line 1796 | public class CompletableFutureTest exten
1796       * completion of sources
1797       */
1798      public void testApplyToEitherAsync() {
1799 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1800 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1799 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1800 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1801          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1802          f.complete(one);
1803          checkCompletedNormally(g, two);
1804  
1805 <        f = new CompletableFuture<Integer>();
1805 >        f = new CompletableFuture<>();
1806          f.complete(one);
1807 <        f2 = new CompletableFuture<Integer>();
1807 >        f2 = new CompletableFuture<>();
1808          g = f.applyToEitherAsync(f2, inc);
1809          checkCompletedNormally(g, two);
1810      }
# Line 1477 | Line 1814 | public class CompletableFutureTest exten
1814       * completion of source
1815       */
1816      public void testApplyToEitherAsync2() {
1817 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1818 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1817 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1818 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1819          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1820          f.completeExceptionally(new CFException());
1821          checkCompletedWithWrappedCFException(g);
1822  
1823 <        f = new CompletableFuture<Integer>();
1824 <        f2 = new CompletableFuture<Integer>();
1823 >        f = new CompletableFuture<>();
1824 >        f2 = new CompletableFuture<>();
1825          f2.completeExceptionally(new CFException());
1826          g = f.applyToEitherAsync(f2, inc);
1827          f.complete(one);
# Line 1495 | Line 1832 | public class CompletableFutureTest exten
1832       * applyToEitherAsync result completes exceptionally if action does
1833       */
1834      public void testApplyToEitherAsync3() {
1835 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1836 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1835 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1836 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1837          FailingFunction r = new FailingFunction();
1838          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
1839          f.complete(one);
# Line 1507 | Line 1844 | public class CompletableFutureTest exten
1844       * applyToEitherAsync result completes exceptionally if either source cancelled
1845       */
1846      public void testApplyToEitherAsync4() {
1847 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1848 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1847 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1848 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1849          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1850          assertTrue(f.cancel(true));
1851          checkCompletedWithWrappedCancellationException(g);
1852  
1853 <        f = new CompletableFuture<Integer>();
1854 <        f2 = new CompletableFuture<Integer>();
1853 >        f = new CompletableFuture<>();
1854 >        f2 = new CompletableFuture<>();
1855          assertTrue(f2.cancel(true));
1856          g = f.applyToEitherAsync(f2, inc);
1857          checkCompletedWithWrappedCancellationException(g);
# Line 1525 | Line 1862 | public class CompletableFutureTest exten
1862       * completion of sources
1863       */
1864      public void testAcceptEitherAsync() {
1865 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1866 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1865 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1866 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1867          IncAction r = new IncAction();
1868          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1869          f.complete(one);
# Line 1534 | Line 1871 | public class CompletableFutureTest exten
1871          assertEquals(r.value, 2);
1872  
1873          r = new IncAction();
1874 <        f = new CompletableFuture<Integer>();
1874 >        f = new CompletableFuture<>();
1875          f.complete(one);
1876 <        f2 = new CompletableFuture<Integer>();
1876 >        f2 = new CompletableFuture<>();
1877          g = f.acceptEitherAsync(f2, r);
1878          checkCompletedNormally(g, null);
1879          assertEquals(r.value, 2);
# Line 1547 | Line 1884 | public class CompletableFutureTest exten
1884       * completion of source
1885       */
1886      public void testAcceptEitherAsync2() {
1887 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1888 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1887 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1888 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1889          IncAction r = new IncAction();
1890          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1891          f.completeExceptionally(new CFException());
1892          checkCompletedWithWrappedCFException(g);
1893  
1894          r = new IncAction();
1895 <        f = new CompletableFuture<Integer>();
1896 <        f2 = new CompletableFuture<Integer>();
1895 >        f = new CompletableFuture<>();
1896 >        f2 = new CompletableFuture<>();
1897          f2.completeExceptionally(new CFException());
1898          g = f.acceptEitherAsync(f2, r);
1899          f.complete(one);
# Line 1567 | Line 1904 | public class CompletableFutureTest exten
1904       * acceptEitherAsync result completes exceptionally if action does
1905       */
1906      public void testAcceptEitherAsync3() {
1907 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1908 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1907 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1908 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1909          FailingConsumer r = new FailingConsumer();
1910          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1911          f.complete(one);
# Line 1580 | Line 1917 | public class CompletableFutureTest exten
1917       * source cancelled
1918       */
1919      public void testAcceptEitherAsync4() {
1920 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1921 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1920 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1921 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1922          IncAction r = new IncAction();
1923          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1924          assertTrue(f.cancel(true));
1925          checkCompletedWithWrappedCancellationException(g);
1926  
1927          r = new IncAction();
1928 <        f = new CompletableFuture<Integer>();
1929 <        f2 = new CompletableFuture<Integer>();
1928 >        f = new CompletableFuture<>();
1929 >        f2 = new CompletableFuture<>();
1930          assertTrue(f2.cancel(true));
1931          g = f.acceptEitherAsync(f2, r);
1932          checkCompletedWithWrappedCancellationException(g);
# Line 1600 | Line 1937 | public class CompletableFutureTest exten
1937       * completion of sources
1938       */
1939      public void testRunAfterEitherAsync() {
1940 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1941 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1940 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1941 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1942          Noop r = new Noop();
1943          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1944          f.complete(one);
# Line 1609 | Line 1946 | public class CompletableFutureTest exten
1946          assertTrue(r.ran);
1947  
1948          r = new Noop();
1949 <        f = new CompletableFuture<Integer>();
1949 >        f = new CompletableFuture<>();
1950          f.complete(one);
1951 <        f2 = new CompletableFuture<Integer>();
1951 >        f2 = new CompletableFuture<>();
1952          g = f.runAfterEitherAsync(f2, r);
1953          checkCompletedNormally(g, null);
1954          assertTrue(r.ran);
# Line 1622 | Line 1959 | public class CompletableFutureTest exten
1959       * completion of source
1960       */
1961      public void testRunAfterEitherAsync2() {
1962 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1963 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1962 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1963 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1964          Noop r = new Noop();
1965          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1966          f.completeExceptionally(new CFException());
1967          checkCompletedWithWrappedCFException(g);
1968  
1969          r = new Noop();
1970 <        f = new CompletableFuture<Integer>();
1971 <        f2 = new CompletableFuture<Integer>();
1970 >        f = new CompletableFuture<>();
1971 >        f2 = new CompletableFuture<>();
1972          f2.completeExceptionally(new CFException());
1973          g = f.runAfterEitherAsync(f2, r);
1974          f.complete(one);
# Line 1642 | Line 1979 | public class CompletableFutureTest exten
1979       * runAfterEitherAsync result completes exceptionally if action does
1980       */
1981      public void testRunAfterEitherAsync3() {
1982 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1983 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1982 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1983 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1984          FailingNoop r = new FailingNoop();
1985          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1986          f.complete(one);
# Line 1655 | Line 1992 | public class CompletableFutureTest exten
1992       * source cancelled
1993       */
1994      public void testRunAfterEitherAsync4() {
1995 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1996 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1995 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1996 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1997          Noop r = new Noop();
1998          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1999          assertTrue(f.cancel(true));
2000          checkCompletedWithWrappedCancellationException(g);
2001  
2002          r = new Noop();
2003 <        f = new CompletableFuture<Integer>();
2004 <        f2 = new CompletableFuture<Integer>();
2003 >        f = new CompletableFuture<>();
2004 >        f2 = new CompletableFuture<>();
2005          assertTrue(f2.cancel(true));
2006          g = f.runAfterEitherAsync(f2, r);
2007          checkCompletedWithWrappedCancellationException(g);
# Line 1675 | Line 2012 | public class CompletableFutureTest exten
2012       * completion of source
2013       */
2014      public void testThenComposeAsync() {
2015 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2016 <        CompletableFutureInc r = new CompletableFutureInc();
2017 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2015 >        CompletableFuture<Integer> f, g;
2016 >        CompletableFutureInc r;
2017 >
2018 >        f = new CompletableFuture<>();
2019 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2020          f.complete(one);
2021          checkCompletedNormally(g, two);
2022 +
2023 +        f = new CompletableFuture<>();
2024 +        f.complete(one);
2025 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2026 +        checkCompletedNormally(g, two);
2027      }
2028  
2029      /**
# Line 1687 | Line 2031 | public class CompletableFutureTest exten
2031       * exceptional completion of source
2032       */
2033      public void testThenComposeAsync2() {
2034 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2035 <        CompletableFutureInc r = new CompletableFutureInc();
2036 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2034 >        CompletableFuture<Integer> f, g;
2035 >        CompletableFutureInc r;
2036 >
2037 >        f = new CompletableFuture<>();
2038 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2039 >        f.completeExceptionally(new CFException());
2040 >        checkCompletedWithWrappedCFException(g);
2041 >        assertFalse(r.ran);
2042 >
2043 >        f = new CompletableFuture<>();
2044          f.completeExceptionally(new CFException());
2045 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2046          checkCompletedWithWrappedCFException(g);
2047 +        assertFalse(r.ran);
2048      }
2049  
2050      /**
2051       * thenComposeAsync result completes exceptionally if action does
2052       */
2053      public void testThenComposeAsync3() {
2054 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2055 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2056 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2054 >        CompletableFuture<Integer> f, g;
2055 >        FailingCompletableFutureFunction r;
2056 >
2057 >        f = new CompletableFuture<>();
2058 >        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2059          f.complete(one);
2060          checkCompletedWithWrappedCFException(g);
2061 +
2062 +        f = new CompletableFuture<>();
2063 +        f.complete(one);
2064 +        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2065 +        checkCompletedWithWrappedCFException(g);
2066      }
2067  
2068      /**
2069       * thenComposeAsync result completes exceptionally if source cancelled
2070       */
2071      public void testThenComposeAsync4() {
2072 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2073 <        CompletableFutureInc r = new CompletableFutureInc();
2074 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2072 >        CompletableFuture<Integer> f, g;
2073 >        CompletableFutureInc r;
2074 >
2075 >        f = new CompletableFuture<>();
2076 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2077          assertTrue(f.cancel(true));
2078          checkCompletedWithWrappedCancellationException(g);
1717    }
2079  
2080 +        f = new CompletableFuture<>();
2081 +        assertTrue(f.cancel(true));
2082 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2083 +        checkCompletedWithWrappedCancellationException(g);
2084 +    }
2085  
2086      // async with explicit executors
2087  
# Line 1723 | Line 2089 | public class CompletableFutureTest exten
2089       * thenRunAsync result completes normally after normal completion of source
2090       */
2091      public void testThenRunAsyncE() {
2092 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2092 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2093          Noop r = new Noop();
2094          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2095          f.complete(null);
2096          checkCompletedNormally(g, null);
2097  
2098          // reordered version
2099 <        f = new CompletableFuture<Integer>();
2099 >        f = new CompletableFuture<>();
2100          f.complete(null);
2101          r = new Noop();
2102          g = f.thenRunAsync(r, new ThreadExecutor());
# Line 1742 | Line 2108 | public class CompletableFutureTest exten
2108       * completion of source
2109       */
2110      public void testThenRunAsync2E() {
2111 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2111 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2112          Noop r = new Noop();
2113          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2114          f.completeExceptionally(new CFException());
# Line 1758 | Line 2124 | public class CompletableFutureTest exten
2124       * thenRunAsync result completes exceptionally if action does
2125       */
2126      public void testThenRunAsync3E() {
2127 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2127 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2128          FailingNoop r = new FailingNoop();
2129          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2130          f.complete(null);
# Line 1769 | Line 2135 | public class CompletableFutureTest exten
2135       * thenRunAsync result completes exceptionally if source cancelled
2136       */
2137      public void testThenRunAsync4E() {
2138 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2138 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2139          Noop r = new Noop();
2140          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2141          assertTrue(f.cancel(true));
# Line 1780 | Line 2146 | public class CompletableFutureTest exten
2146       * thenApplyAsync result completes normally after normal completion of source
2147       */
2148      public void testThenApplyAsyncE() {
2149 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2149 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2150          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2151          f.complete(one);
2152          checkCompletedNormally(g, two);
# Line 1791 | Line 2157 | public class CompletableFutureTest exten
2157       * completion of source
2158       */
2159      public void testThenApplyAsync2E() {
2160 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2160 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2161          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2162          f.completeExceptionally(new CFException());
2163          checkCompletedWithWrappedCFException(g);
# Line 1801 | Line 2167 | public class CompletableFutureTest exten
2167       * thenApplyAsync result completes exceptionally if action does
2168       */
2169      public void testThenApplyAsync3E() {
2170 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2170 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2171          FailingFunction r = new FailingFunction();
2172          CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
2173          f.complete(null);
# Line 1812 | Line 2178 | public class CompletableFutureTest exten
2178       * thenApplyAsync result completes exceptionally if source cancelled
2179       */
2180      public void testThenApplyAsync4E() {
2181 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2181 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2182          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2183          assertTrue(f.cancel(true));
2184          checkCompletedWithWrappedCancellationException(g);
# Line 1823 | Line 2189 | public class CompletableFutureTest exten
2189       * completion of source
2190       */
2191      public void testThenAcceptAsyncE() {
2192 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2192 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2193          IncAction r = new IncAction();
2194          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2195          f.complete(one);
# Line 1836 | Line 2202 | public class CompletableFutureTest exten
2202       * completion of source
2203       */
2204      public void testThenAcceptAsync2E() {
2205 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2205 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2206          IncAction r = new IncAction();
2207          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2208          f.completeExceptionally(new CFException());
# Line 1847 | Line 2213 | public class CompletableFutureTest exten
2213       * thenAcceptAsync result completes exceptionally if action does
2214       */
2215      public void testThenAcceptAsync3E() {
2216 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2216 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2217          FailingConsumer r = new FailingConsumer();
2218          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2219          f.complete(null);
# Line 1858 | Line 2224 | public class CompletableFutureTest exten
2224       * thenAcceptAsync result completes exceptionally if source cancelled
2225       */
2226      public void testThenAcceptAsync4E() {
2227 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2227 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2228          IncAction r = new IncAction();
2229          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2230          assertTrue(f.cancel(true));
2231          checkCompletedWithWrappedCancellationException(g);
2232      }
2233 +
2234      /**
2235       * thenCombineAsync result completes normally after normal
2236       * completion of sources
2237       */
2238      public void testThenCombineAsyncE() {
2239 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2240 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2241 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2242 <        f.complete(one);
2243 <        checkIncomplete(g);
2244 <        f2.complete(two);
2245 <        checkCompletedNormally(g, three);
2239 >        CompletableFuture<Integer> f, g, h;
2240 >        ThreadExecutor e = new ThreadExecutor();
2241 >        int count = 0;
2242 >
2243 >        f = new CompletableFuture<>();
2244 >        g = new CompletableFuture<>();
2245 >        h = f.thenCombineAsync(g, subtract, e);
2246 >        f.complete(3);
2247 >        checkIncomplete(h);
2248 >        g.complete(1);
2249 >        checkCompletedNormally(h, 2);
2250 >        assertEquals(++count, e.count.get());
2251 >
2252 >        f = new CompletableFuture<>();
2253 >        g = new CompletableFuture<>();
2254 >        h = f.thenCombineAsync(g, subtract, e);
2255 >        g.complete(1);
2256 >        checkIncomplete(h);
2257 >        f.complete(3);
2258 >        checkCompletedNormally(h, 2);
2259 >        assertEquals(++count, e.count.get());
2260 >
2261 >        f = new CompletableFuture<>();
2262 >        g = new CompletableFuture<>();
2263 >        g.complete(1);
2264 >        f.complete(3);
2265 >        h = f.thenCombineAsync(g, subtract, e);
2266 >        checkCompletedNormally(h, 2);
2267 >        assertEquals(++count, e.count.get());
2268      }
2269  
2270      /**
2271       * thenCombineAsync result completes exceptionally after exceptional
2272 <     * completion of source
2272 >     * completion of either source
2273       */
2274      public void testThenCombineAsync2E() {
2275 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2276 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2277 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2278 <        f.completeExceptionally(new CFException());
2279 <        f2.complete(two);
2280 <        checkCompletedWithWrappedCFException(g);
2275 >        CompletableFuture<Integer> f, g, h;
2276 >        ThreadExecutor e = new ThreadExecutor();
2277 >        int count = 0;
2278 >
2279 >        f = new CompletableFuture<>();
2280 >        g = new CompletableFuture<>();
2281 >        h = f.thenCombineAsync(g, subtract, e);
2282 >        f.completeExceptionally(new CFException());
2283 >        checkIncomplete(h);
2284 >        g.complete(1);
2285 >        checkCompletedWithWrappedCFException(h);
2286 >
2287 >        f = new CompletableFuture<>();
2288 >        g = new CompletableFuture<>();
2289 >        h = f.thenCombineAsync(g, subtract, e);
2290 >        g.completeExceptionally(new CFException());
2291 >        checkIncomplete(h);
2292 >        f.complete(3);
2293 >        checkCompletedWithWrappedCFException(h);
2294 >
2295 >        f = new CompletableFuture<>();
2296 >        g = new CompletableFuture<>();
2297 >        g.completeExceptionally(new CFException());
2298 >        h = f.thenCombineAsync(g, subtract, e);
2299 >        checkIncomplete(h);
2300 >        f.complete(3);
2301 >        checkCompletedWithWrappedCFException(h);
2302  
2303 <        f = new CompletableFuture<Integer>();
1894 <        f2 = new CompletableFuture<Integer>();
1895 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1896 <        f.complete(one);
1897 <        f2.completeExceptionally(new CFException());
1898 <        checkCompletedWithWrappedCFException(g);
2303 >        assertEquals(0, e.count.get());
2304      }
2305  
2306      /**
2307       * thenCombineAsync result completes exceptionally if action does
2308       */
2309      public void testThenCombineAsync3E() {
2310 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2311 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2310 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2311 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2312          FailingBiFunction r = new FailingBiFunction();
2313          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor());
2314          f.complete(one);
2315          checkIncomplete(g);
2316 +        assertFalse(r.ran);
2317          f2.complete(two);
2318          checkCompletedWithWrappedCFException(g);
2319 +        assertTrue(r.ran);
2320      }
2321  
2322      /**
2323       * thenCombineAsync result completes exceptionally if either source cancelled
2324       */
2325      public void testThenCombineAsync4E() {
2326 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2327 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1921 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1922 <        assertTrue(f.cancel(true));
1923 <        f2.complete(two);
1924 <        checkCompletedWithWrappedCancellationException(g);
2326 >        CompletableFuture<Integer> f, g, h;
2327 >        ThreadExecutor e = new ThreadExecutor();
2328  
2329 <        f = new CompletableFuture<Integer>();
2330 <        f2 = new CompletableFuture<Integer>();
2331 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2332 <        f.complete(one);
2333 <        assertTrue(f2.cancel(true));
2334 <        checkCompletedWithWrappedCancellationException(g);
2329 >        f = new CompletableFuture<>();
2330 >        g = new CompletableFuture<>();
2331 >        h = f.thenCombineAsync(g, subtract, e);
2332 >        assertTrue(f.cancel(true));
2333 >        checkIncomplete(h);
2334 >        g.complete(1);
2335 >        checkCompletedWithWrappedCancellationException(h);
2336 >
2337 >        f = new CompletableFuture<>();
2338 >        g = new CompletableFuture<>();
2339 >        h = f.thenCombineAsync(g, subtract, e);
2340 >        assertTrue(g.cancel(true));
2341 >        checkIncomplete(h);
2342 >        f.complete(3);
2343 >        checkCompletedWithWrappedCancellationException(h);
2344 >
2345 >        f = new CompletableFuture<>();
2346 >        g = new CompletableFuture<>();
2347 >        assertTrue(g.cancel(true));
2348 >        h = f.thenCombineAsync(g, subtract, e);
2349 >        checkIncomplete(h);
2350 >        f.complete(3);
2351 >        checkCompletedWithWrappedCancellationException(h);
2352 >
2353 >        f = new CompletableFuture<>();
2354 >        g = new CompletableFuture<>();
2355 >        assertTrue(f.cancel(true));
2356 >        assertTrue(g.cancel(true));
2357 >        h = f.thenCombineAsync(g, subtract, e);
2358 >        checkCompletedWithWrappedCancellationException(h);
2359 >
2360 >        assertEquals(0, e.count.get());
2361      }
2362  
2363      /**
# Line 1936 | Line 2365 | public class CompletableFutureTest exten
2365       * completion of sources
2366       */
2367      public void testThenAcceptBothAsyncE() {
2368 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2369 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2370 <        AddAction r = new AddAction();
2371 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2372 <        f.complete(one);
2373 <        checkIncomplete(g);
2374 <        f2.complete(two);
2375 <        checkCompletedNormally(g, null);
2376 <        assertEquals(r.value, 3);
2368 >        CompletableFuture<Integer> f, g;
2369 >        CompletableFuture<Void> h;
2370 >        SubtractAction r;
2371 >        ThreadExecutor e = new ThreadExecutor();
2372 >
2373 >        f = new CompletableFuture<>();
2374 >        g = new CompletableFuture<>();
2375 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2376 >        f.complete(3);
2377 >        checkIncomplete(h);
2378 >        g.complete(1);
2379 >        checkCompletedNormally(h, null);
2380 >        assertEquals(r.value, 2);
2381 >
2382 >        f = new CompletableFuture<>();
2383 >        g = new CompletableFuture<>();
2384 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2385 >        g.complete(1);
2386 >        checkIncomplete(h);
2387 >        f.complete(3);
2388 >        checkCompletedNormally(h, null);
2389 >        assertEquals(r.value, 2);
2390 >
2391 >        f = new CompletableFuture<>();
2392 >        g = new CompletableFuture<>();
2393 >        g.complete(1);
2394 >        f.complete(3);
2395 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2396 >        checkCompletedNormally(h, null);
2397 >        assertEquals(r.value, 2);
2398 >
2399 >        assertEquals(3, e.count.get());
2400      }
2401  
2402      /**
# Line 1952 | Line 2404 | public class CompletableFutureTest exten
2404       * completion of source
2405       */
2406      public void testThenAcceptBothAsync2E() {
2407 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2408 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2409 <        AddAction r = new AddAction();
2410 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2411 <        f.completeExceptionally(new CFException());
2412 <        f2.complete(two);
2413 <        checkCompletedWithWrappedCFException(g);
2407 >        CompletableFuture<Integer> f, g;
2408 >        CompletableFuture<Void> h;
2409 >        SubtractAction r;
2410 >        ThreadExecutor e = new ThreadExecutor();
2411 >
2412 >        f = new CompletableFuture<>();
2413 >        g = new CompletableFuture<>();
2414 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2415 >        f.completeExceptionally(new CFException());
2416 >        checkIncomplete(h);
2417 >        g.complete(1);
2418 >        checkCompletedWithWrappedCFException(h);
2419 >
2420 >        f = new CompletableFuture<>();
2421 >        g = new CompletableFuture<>();
2422 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2423 >        g.completeExceptionally(new CFException());
2424 >        checkIncomplete(h);
2425 >        f.complete(3);
2426 >        checkCompletedWithWrappedCFException(h);
2427 >
2428 >        f = new CompletableFuture<>();
2429 >        g = new CompletableFuture<>();
2430 >        f.complete(3);
2431 >        g.completeExceptionally(new CFException());
2432 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2433 >        checkCompletedWithWrappedCFException(h);
2434 >
2435 >        f = new CompletableFuture<>();
2436 >        g = new CompletableFuture<>();
2437 >        f.completeExceptionally(new CFException());
2438 >        g.complete(3);
2439 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2440 >        checkCompletedWithWrappedCFException(h);
2441  
2442 <        r = new AddAction();
1964 <        f = new CompletableFuture<Integer>();
1965 <        f2 = new CompletableFuture<Integer>();
1966 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1967 <        f.complete(one);
1968 <        f2.completeExceptionally(new CFException());
1969 <        checkCompletedWithWrappedCFException(g);
2442 >        assertEquals(0, e.count.get());
2443      }
2444  
2445      /**
2446       * thenAcceptBothAsync result completes exceptionally if action does
2447       */
2448      public void testThenAcceptBothAsync3E() {
2449 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2450 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2451 <        FailingBiConsumer r = new FailingBiConsumer();
2452 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2453 <        f.complete(one);
2454 <        checkIncomplete(g);
2455 <        f2.complete(two);
2456 <        checkCompletedWithWrappedCFException(g);
2449 >        CompletableFuture<Integer> f, g;
2450 >        CompletableFuture<Void> h;
2451 >        FailingBiConsumer r;
2452 >        ThreadExecutor e = new ThreadExecutor();
2453 >
2454 >        f = new CompletableFuture<>();
2455 >        g = new CompletableFuture<>();
2456 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2457 >        f.complete(3);
2458 >        checkIncomplete(h);
2459 >        g.complete(1);
2460 >        checkCompletedWithWrappedCFException(h);
2461 >
2462 >        f = new CompletableFuture<>();
2463 >        g = new CompletableFuture<>();
2464 >        f.complete(3);
2465 >        g.complete(1);
2466 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2467 >        checkCompletedWithWrappedCFException(h);
2468 >
2469 >        assertEquals(2, e.count.get());
2470      }
2471  
2472      /**
2473       * thenAcceptBothAsync result completes exceptionally if either source cancelled
2474       */
2475      public void testThenAcceptBothAsync4E() {
2476 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2477 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2478 <        AddAction r = new AddAction();
2479 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2480 <        assertTrue(f.cancel(true));
2481 <        f2.complete(two);
2482 <        checkCompletedWithWrappedCancellationException(g);
2476 >        CompletableFuture<Integer> f, g;
2477 >        CompletableFuture<Void> h;
2478 >        SubtractAction r;
2479 >        ThreadExecutor e = new ThreadExecutor();
2480 >
2481 >        f = new CompletableFuture<>();
2482 >        g = new CompletableFuture<>();
2483 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2484 >        assertTrue(f.cancel(true));
2485 >        checkIncomplete(h);
2486 >        g.complete(1);
2487 >        checkCompletedWithWrappedCancellationException(h);
2488 >
2489 >        f = new CompletableFuture<>();
2490 >        g = new CompletableFuture<>();
2491 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2492 >        assertTrue(g.cancel(true));
2493 >        checkIncomplete(h);
2494 >        f.complete(3);
2495 >        checkCompletedWithWrappedCancellationException(h);
2496 >
2497 >        f = new CompletableFuture<>();
2498 >        g = new CompletableFuture<>();
2499 >        f.complete(3);
2500 >        assertTrue(g.cancel(true));
2501 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2502 >        checkCompletedWithWrappedCancellationException(h);
2503 >
2504 >        f = new CompletableFuture<>();
2505 >        g = new CompletableFuture<>();
2506 >        assertTrue(f.cancel(true));
2507 >        g.complete(3);
2508 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2509 >        checkCompletedWithWrappedCancellationException(h);
2510  
2511 <        r = new AddAction();
1999 <        f = new CompletableFuture<Integer>();
2000 <        f2 = new CompletableFuture<Integer>();
2001 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2002 <        f.complete(one);
2003 <        assertTrue(f2.cancel(true));
2004 <        checkCompletedWithWrappedCancellationException(g);
2511 >        assertEquals(0, e.count.get());
2512      }
2513  
2514      /**
# Line 2009 | Line 2516 | public class CompletableFutureTest exten
2516       * completion of sources
2517       */
2518      public void testRunAfterBothAsyncE() {
2519 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2520 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2519 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2520 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2521          Noop r = new Noop();
2522          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2523          f.complete(one);
# Line 2025 | Line 2532 | public class CompletableFutureTest exten
2532       * completion of source
2533       */
2534      public void testRunAfterBothAsync2E() {
2535 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2536 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2535 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2536 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2537          Noop r = new Noop();
2538          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2539          f.completeExceptionally(new CFException());
# Line 2034 | Line 2541 | public class CompletableFutureTest exten
2541          checkCompletedWithWrappedCFException(g);
2542  
2543          r = new Noop();
2544 <        f = new CompletableFuture<Integer>();
2545 <        f2 = new CompletableFuture<Integer>();
2544 >        f = new CompletableFuture<>();
2545 >        f2 = new CompletableFuture<>();
2546          g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2547          f.complete(one);
2548          f2.completeExceptionally(new CFException());
# Line 2046 | Line 2553 | public class CompletableFutureTest exten
2553       * runAfterBothAsync result completes exceptionally if action does
2554       */
2555      public void testRunAfterBothAsync3E() {
2556 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2557 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2556 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2557 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2558          FailingNoop r = new FailingNoop();
2559          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2560          f.complete(one);
# Line 2060 | Line 2567 | public class CompletableFutureTest exten
2567       * runAfterBothAsync result completes exceptionally if either source cancelled
2568       */
2569      public void testRunAfterBothAsync4E() {
2570 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2571 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2570 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2571 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2572          Noop r = new Noop();
2573          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2574          assertTrue(f.cancel(true));
# Line 2069 | Line 2576 | public class CompletableFutureTest exten
2576          checkCompletedWithWrappedCancellationException(g);
2577  
2578          r = new Noop();
2579 <        f = new CompletableFuture<Integer>();
2580 <        f2 = new CompletableFuture<Integer>();
2579 >        f = new CompletableFuture<>();
2580 >        f2 = new CompletableFuture<>();
2581          g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2582          f.complete(one);
2583          assertTrue(f2.cancel(true));
# Line 2082 | Line 2589 | public class CompletableFutureTest exten
2589       * completion of sources
2590       */
2591      public void testApplyToEitherAsyncE() {
2592 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2593 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2592 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2593 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2594          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2595          f.complete(one);
2596          checkCompletedNormally(g, two);
2597  
2598 <        f = new CompletableFuture<Integer>();
2598 >        f = new CompletableFuture<>();
2599          f.complete(one);
2600 <        f2 = new CompletableFuture<Integer>();
2600 >        f2 = new CompletableFuture<>();
2601          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2602          checkCompletedNormally(g, two);
2603      }
# Line 2100 | Line 2607 | public class CompletableFutureTest exten
2607       * completion of source
2608       */
2609      public void testApplyToEitherAsync2E() {
2610 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2611 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2610 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2611 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2612          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2613          f.completeExceptionally(new CFException());
2614          checkCompletedWithWrappedCFException(g);
2615  
2616 <        f = new CompletableFuture<Integer>();
2617 <        f2 = new CompletableFuture<Integer>();
2616 >        f = new CompletableFuture<>();
2617 >        f2 = new CompletableFuture<>();
2618          f2.completeExceptionally(new CFException());
2619          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2620          f.complete(one);
# Line 2118 | Line 2625 | public class CompletableFutureTest exten
2625       * applyToEitherAsync result completes exceptionally if action does
2626       */
2627      public void testApplyToEitherAsync3E() {
2628 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2629 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2628 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2629 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2630          FailingFunction r = new FailingFunction();
2631          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2632          f.complete(one);
# Line 2130 | Line 2637 | public class CompletableFutureTest exten
2637       * applyToEitherAsync result completes exceptionally if either source cancelled
2638       */
2639      public void testApplyToEitherAsync4E() {
2640 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2641 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2640 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2641 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2642          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2643          assertTrue(f.cancel(true));
2644          checkCompletedWithWrappedCancellationException(g);
2645  
2646 <        f = new CompletableFuture<Integer>();
2647 <        f2 = new CompletableFuture<Integer>();
2646 >        f = new CompletableFuture<>();
2647 >        f2 = new CompletableFuture<>();
2648          assertTrue(f2.cancel(true));
2649          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2650          checkCompletedWithWrappedCancellationException(g);
# Line 2148 | Line 2655 | public class CompletableFutureTest exten
2655       * completion of sources
2656       */
2657      public void testAcceptEitherAsyncE() {
2658 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2659 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2658 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2659 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2660          IncAction r = new IncAction();
2661          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2662          f.complete(one);
# Line 2157 | Line 2664 | public class CompletableFutureTest exten
2664          assertEquals(r.value, 2);
2665  
2666          r = new IncAction();
2667 <        f = new CompletableFuture<Integer>();
2667 >        f = new CompletableFuture<>();
2668          f.complete(one);
2669 <        f2 = new CompletableFuture<Integer>();
2669 >        f2 = new CompletableFuture<>();
2670          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2671          checkCompletedNormally(g, null);
2672          assertEquals(r.value, 2);
# Line 2170 | Line 2677 | public class CompletableFutureTest exten
2677       * completion of source
2678       */
2679      public void testAcceptEitherAsync2E() {
2680 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2681 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2680 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2681 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2682          IncAction r = new IncAction();
2683          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2684          f.completeExceptionally(new CFException());
2685          checkCompletedWithWrappedCFException(g);
2686  
2687          r = new IncAction();
2688 <        f = new CompletableFuture<Integer>();
2689 <        f2 = new CompletableFuture<Integer>();
2688 >        f = new CompletableFuture<>();
2689 >        f2 = new CompletableFuture<>();
2690          f2.completeExceptionally(new CFException());
2691          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2692          f.complete(one);
# Line 2190 | Line 2697 | public class CompletableFutureTest exten
2697       * acceptEitherAsync result completes exceptionally if action does
2698       */
2699      public void testAcceptEitherAsync3E() {
2700 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2701 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2700 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2701 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2702          FailingConsumer r = new FailingConsumer();
2703          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2704          f.complete(one);
# Line 2203 | Line 2710 | public class CompletableFutureTest exten
2710       * source cancelled
2711       */
2712      public void testAcceptEitherAsync4E() {
2713 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2714 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2713 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2714 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2715          IncAction r = new IncAction();
2716          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2717          assertTrue(f.cancel(true));
2718          checkCompletedWithWrappedCancellationException(g);
2719  
2720          r = new IncAction();
2721 <        f = new CompletableFuture<Integer>();
2722 <        f2 = new CompletableFuture<Integer>();
2721 >        f = new CompletableFuture<>();
2722 >        f2 = new CompletableFuture<>();
2723          assertTrue(f2.cancel(true));
2724          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2725          checkCompletedWithWrappedCancellationException(g);
# Line 2223 | Line 2730 | public class CompletableFutureTest exten
2730       * completion of sources
2731       */
2732      public void testRunAfterEitherAsyncE() {
2733 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2734 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2733 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2734 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2735          Noop r = new Noop();
2736          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2737          f.complete(one);
# Line 2232 | Line 2739 | public class CompletableFutureTest exten
2739          assertTrue(r.ran);
2740  
2741          r = new Noop();
2742 <        f = new CompletableFuture<Integer>();
2742 >        f = new CompletableFuture<>();
2743          f.complete(one);
2744 <        f2 = new CompletableFuture<Integer>();
2744 >        f2 = new CompletableFuture<>();
2745          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2746          checkCompletedNormally(g, null);
2747          assertTrue(r.ran);
# Line 2245 | Line 2752 | public class CompletableFutureTest exten
2752       * completion of source
2753       */
2754      public void testRunAfterEitherAsync2E() {
2755 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2756 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2755 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2756 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2757          Noop r = new Noop();
2758          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2759          f.completeExceptionally(new CFException());
2760          checkCompletedWithWrappedCFException(g);
2761  
2762          r = new Noop();
2763 <        f = new CompletableFuture<Integer>();
2764 <        f2 = new CompletableFuture<Integer>();
2763 >        f = new CompletableFuture<>();
2764 >        f2 = new CompletableFuture<>();
2765          f2.completeExceptionally(new CFException());
2766          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2767          f.complete(one);
# Line 2265 | Line 2772 | public class CompletableFutureTest exten
2772       * runAfterEitherAsync result completes exceptionally if action does
2773       */
2774      public void testRunAfterEitherAsync3E() {
2775 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2776 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2775 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2776 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2777          FailingNoop r = new FailingNoop();
2778          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2779          f.complete(one);
# Line 2278 | Line 2785 | public class CompletableFutureTest exten
2785       * source cancelled
2786       */
2787      public void testRunAfterEitherAsync4E() {
2788 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2789 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2788 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2789 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2790          Noop r = new Noop();
2791          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2792          assertTrue(f.cancel(true));
2793          checkCompletedWithWrappedCancellationException(g);
2794  
2795          r = new Noop();
2796 <        f = new CompletableFuture<Integer>();
2797 <        f2 = new CompletableFuture<Integer>();
2796 >        f = new CompletableFuture<>();
2797 >        f2 = new CompletableFuture<>();
2798          assertTrue(f2.cancel(true));
2799          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2800          checkCompletedWithWrappedCancellationException(g);
# Line 2298 | Line 2805 | public class CompletableFutureTest exten
2805       * completion of source
2806       */
2807      public void testThenComposeAsyncE() {
2808 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2808 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2809          CompletableFutureInc r = new CompletableFutureInc();
2810          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2811          f.complete(one);
# Line 2310 | Line 2817 | public class CompletableFutureTest exten
2817       * exceptional completion of source
2818       */
2819      public void testThenComposeAsync2E() {
2820 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2820 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2821          CompletableFutureInc r = new CompletableFutureInc();
2822          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2823          f.completeExceptionally(new CFException());
# Line 2321 | Line 2828 | public class CompletableFutureTest exten
2828       * thenComposeAsync result completes exceptionally if action does
2829       */
2830      public void testThenComposeAsync3E() {
2831 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2831 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2832          FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2833          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2834          f.complete(one);
# Line 2332 | Line 2839 | public class CompletableFutureTest exten
2839       * thenComposeAsync result completes exceptionally if source cancelled
2840       */
2841      public void testThenComposeAsync4E() {
2842 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2842 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2843          CompletableFutureInc r = new CompletableFutureInc();
2844          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2845          assertTrue(f.cancel(true));
# Line 2346 | Line 2853 | public class CompletableFutureTest exten
2853       * with the value null
2854       */
2855      public void testAllOf_empty() throws Exception {
2856 <        CompletableFuture<?> f = CompletableFuture.allOf();
2856 >        CompletableFuture<Void> f = CompletableFuture.allOf();
2857          checkCompletedNormally(f, null);
2858      }
2859  
2860      /**
2861 <     * allOf returns a future completed when all components complete
2861 >     * allOf returns a future completed normally with the value null
2862 >     * when all components complete normally
2863       */
2864 <    public void testAllOf() throws Exception {
2864 >    public void testAllOf_normal() throws Exception {
2865          for (int k = 1; k < 20; ++k) {
2866 <            CompletableFuture[] fs = new CompletableFuture[k];
2866 >            CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2867              for (int i = 0; i < k; ++i)
2868 <                fs[i] = new CompletableFuture<Integer>();
2869 <            CompletableFuture<?> f = CompletableFuture.allOf(fs);
2868 >                fs[i] = new CompletableFuture<>();
2869 >            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2870              for (int i = 0; i < k; ++i) {
2871                  checkIncomplete(f);
2872 +                checkIncomplete(CompletableFuture.allOf(fs));
2873                  fs[i].complete(one);
2874              }
2875 <            assertTrue(f.isDone());
2876 <            assertFalse(f.isCancelled());
2875 >            checkCompletedNormally(f, null);
2876 >            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2877          }
2878      }
2879  
# Line 2372 | Line 2881 | public class CompletableFutureTest exten
2881       * anyOf(no component futures) returns an incomplete future
2882       */
2883      public void testAnyOf_empty() throws Exception {
2884 <        CompletableFuture<?> f = CompletableFuture.anyOf();
2884 >        CompletableFuture<Object> f = CompletableFuture.anyOf();
2885          checkIncomplete(f);
2886      }
2887  
2888      /**
2889 <     * allOf returns a future completed when any components complete
2889 >     * anyOf returns a future completed normally with a value when
2890 >     * a component future does
2891       */
2892 <    public void testAnyOf() throws Exception {
2893 <        for (int k = 1; k < 20; ++k) {
2892 >    public void testAnyOf_normal() throws Exception {
2893 >        for (int k = 0; k < 10; ++k) {
2894              CompletableFuture[] fs = new CompletableFuture[k];
2895              for (int i = 0; i < k; ++i)
2896 <                fs[i] = new CompletableFuture<Integer>();
2897 <            CompletableFuture<?> f = CompletableFuture.anyOf(fs);
2896 >                fs[i] = new CompletableFuture<>();
2897 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2898              checkIncomplete(f);
2899              for (int i = 0; i < k; ++i) {
2900                  fs[i].complete(one);
2901 <                assertTrue(f.isDone());
2901 >                checkCompletedNormally(f, one);
2902 >                checkCompletedNormally(CompletableFuture.anyOf(fs), one);
2903 >            }
2904 >        }
2905 >    }
2906 >
2907 >    /**
2908 >     * anyOf result completes exceptionally when any component does.
2909 >     */
2910 >    public void testAnyOf_exceptional() throws Exception {
2911 >        for (int k = 0; k < 10; ++k) {
2912 >            CompletableFuture[] fs = new CompletableFuture[k];
2913 >            for (int i = 0; i < k; ++i)
2914 >                fs[i] = new CompletableFuture<>();
2915 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2916 >            checkIncomplete(f);
2917 >            for (int i = 0; i < k; ++i) {
2918 >                fs[i].completeExceptionally(new CFException());
2919 >                checkCompletedWithWrappedCFException(f);
2920 >                checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
2921              }
2922          }
2923      }
# Line 2397 | Line 2926 | public class CompletableFutureTest exten
2926       * Completion methods throw NullPointerException with null arguments
2927       */
2928      public void testNPE() {
2929 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2930 <        CompletableFuture<Integer> g = new CompletableFuture<Integer>();
2931 <        CompletableFuture h;
2932 <        try { h = f.thenApply(null); } catch (NullPointerException ok) {}
2933 <        try { h = f.thenAccept(null); } catch (NullPointerException ok) {}
2934 <        try { h = f.thenRun(null); } catch (NullPointerException ok) {}
2935 <        try { h = f.thenCombine(g, null); } catch (NullPointerException ok) {}
2936 <        try { h = f.thenCombine(null, null); } catch (NullPointerException ok) {}
2937 <        try { h = f.applyToEither(g, null); } catch (NullPointerException ok) {}
2938 <        try { h = f.applyToEither(null, null); } catch (NullPointerException ok) {}
2939 <        try { h = f.thenAcceptBoth(g, null); } catch (NullPointerException ok) {}
2940 <        try { h = f.thenAcceptBoth(null, null); } catch (NullPointerException ok) {}
2941 <        try { h = f.runAfterEither(g, null); } catch (NullPointerException ok) {}
2942 <        try { h = f.runAfterEither(null, null); } catch (NullPointerException ok) {}
2943 <        try { h = f.runAfterBoth(g, null); } catch (NullPointerException ok) {}
2944 <        try { h = f.runAfterBoth(null, null); } catch (NullPointerException ok) {}
2945 <        try { h = f.exceptionally(null); } catch (NullPointerException ok) {}
2946 <        try { h = f.handle(null); } catch (NullPointerException ok) {}
2947 <        try { h = f.thenCompose(null); } catch (NullPointerException ok) {}
2948 <
2949 <        try { h = f.thenApplyAsync(null); } catch (NullPointerException ok) {}
2950 <        try { h = f.thenAcceptAsync(null); } catch (NullPointerException ok) {}
2951 <        try { h = f.thenRunAsync(null); } catch (NullPointerException ok) {}
2952 <        try { h = f.thenCombineAsync(g, null); } catch (NullPointerException ok) {}
2953 <        try { h = f.thenCombineAsync(null, null); } catch (NullPointerException ok) {}
2954 <        try { h = f.applyToEitherAsync(g, null); } catch (NullPointerException ok) {}
2955 <        try { h = f.applyToEitherAsync(null, null); } catch (NullPointerException ok) {}
2956 <        try { h = f.thenAcceptBothAsync(g, null); } catch (NullPointerException ok) {}
2957 <        try { h = f.thenAcceptBothAsync(null, null); } catch (NullPointerException ok) {}
2958 <        try { h = f.runAfterEitherAsync(g, null); } catch (NullPointerException ok) {}
2959 <        try { h = f.runAfterEitherAsync(null, null); } catch (NullPointerException ok) {}
2960 <        try { h = f.runAfterBothAsync(g, null); } catch (NullPointerException ok) {}
2961 <        try { h = f.runAfterBothAsync(null, null); } catch (NullPointerException ok) {}
2929 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2930 >        CompletableFuture<Integer> g = new CompletableFuture<>();
2931 >        CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null;
2932 >        CompletableFuture<?> h;
2933 >        ThreadExecutor exec = new ThreadExecutor();
2934 >
2935 >        Runnable[] throwingActions = {
2936 >            () -> { CompletableFuture.supplyAsync(null); },
2937 >            () -> { CompletableFuture.supplyAsync(null, exec); },
2938 >            () -> { CompletableFuture.supplyAsync(supplyOne, null); },
2939 >
2940 >            () -> { CompletableFuture.runAsync(null); },
2941 >            () -> { CompletableFuture.runAsync(null, exec); },
2942 >            () -> { CompletableFuture.runAsync(() -> {}, null); },
2943 >
2944 >            () -> { f.completeExceptionally(null); },
2945 >
2946 >            () -> { f.thenApply(null); },
2947 >            () -> { f.thenApplyAsync(null); },
2948 >            () -> { f.thenApplyAsync((x) -> x, null); },
2949 >            () -> { f.thenApplyAsync(null, exec); },
2950 >
2951 >            () -> { f.thenAccept(null); },
2952 >            () -> { f.thenAcceptAsync(null); },
2953 >            () -> { f.thenAcceptAsync((x) -> { ; }, null); },
2954 >            () -> { f.thenAcceptAsync(null, exec); },
2955 >
2956 >            () -> { f.thenRun(null); },
2957 >            () -> { f.thenRunAsync(null); },
2958 >            () -> { f.thenRunAsync(() -> { ; }, null); },
2959 >            () -> { f.thenRunAsync(null, exec); },
2960 >
2961 >            () -> { f.thenCombine(g, null); },
2962 >            () -> { f.thenCombineAsync(g, null); },
2963 >            () -> { f.thenCombineAsync(g, null, exec); },
2964 >            () -> { f.thenCombine(nullFuture, (x, y) -> x); },
2965 >            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x); },
2966 >            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); },
2967 >            () -> { f.thenCombineAsync(g, (x, y) -> x, null); },
2968 >
2969 >            () -> { f.thenAcceptBoth(g, null); },
2970 >            () -> { f.thenAcceptBothAsync(g, null); },
2971 >            () -> { f.thenAcceptBothAsync(g, null, exec); },
2972 >            () -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); },
2973 >            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); },
2974 >            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); },
2975 >            () -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); },
2976 >
2977 >            () -> { f.runAfterBoth(g, null); },
2978 >            () -> { f.runAfterBothAsync(g, null); },
2979 >            () -> { f.runAfterBothAsync(g, null, exec); },
2980 >            () -> { f.runAfterBoth(nullFuture, () -> {}); },
2981 >            () -> { f.runAfterBothAsync(nullFuture, () -> {}); },
2982 >            () -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); },
2983 >            () -> { f.runAfterBothAsync(g, () -> {}, null); },
2984 >
2985 >            () -> { f.applyToEither(g, null); },
2986 >            () -> { f.applyToEitherAsync(g, null); },
2987 >            () -> { f.applyToEitherAsync(g, null, exec); },
2988 >            () -> { f.applyToEither(nullFuture, (x) -> x); },
2989 >            () -> { f.applyToEitherAsync(nullFuture, (x) -> x); },
2990 >            () -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); },
2991 >            () -> { f.applyToEitherAsync(g, (x) -> x, null); },
2992 >
2993 >            () -> { f.acceptEither(g, null); },
2994 >            () -> { f.acceptEitherAsync(g, null); },
2995 >            () -> { f.acceptEitherAsync(g, null, exec); },
2996 >            () -> { f.acceptEither(nullFuture, (x) -> {}); },
2997 >            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}); },
2998 >            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); },
2999 >            () -> { f.acceptEitherAsync(g, (x) -> {}, null); },
3000 >
3001 >            () -> { f.runAfterEither(g, null); },
3002 >            () -> { f.runAfterEitherAsync(g, null); },
3003 >            () -> { f.runAfterEitherAsync(g, null, exec); },
3004 >            () -> { f.runAfterEither(nullFuture, () -> {}); },
3005 >            () -> { f.runAfterEitherAsync(nullFuture, () -> {}); },
3006 >            () -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); },
3007 >            () -> { f.runAfterEitherAsync(g, () -> {}, null); },
3008 >
3009 >            () -> { f.thenCompose(null); },
3010 >            () -> { f.thenComposeAsync(null); },
3011 >            () -> { f.thenComposeAsync(new CompletableFutureInc(), null); },
3012 >            () -> { f.thenComposeAsync(null, exec); },
3013 >
3014 >            () -> { f.exceptionally(null); },
3015 >
3016 >            () -> { f.handle(null); },
3017 >
3018 >            () -> { CompletableFuture.allOf((CompletableFuture<?>)null); },
3019 >            () -> { CompletableFuture.allOf((CompletableFuture<?>[])null); },
3020 >            () -> { CompletableFuture.allOf(f, null); },
3021 >            () -> { CompletableFuture.allOf(null, f); },
3022 >
3023 >            () -> { CompletableFuture.anyOf((CompletableFuture<?>)null); },
3024 >            () -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); },
3025 >            () -> { CompletableFuture.anyOf(f, null); },
3026 >            () -> { CompletableFuture.anyOf(null, f); },
3027 >        };
3028 >
3029 >        assertThrows(NullPointerException.class, throwingActions);
3030 >        assertEquals(0, exec.count.get());
3031 >    }
3032 >
3033 >    /**
3034 >     * toCompletableFuture returns this CompletableFuture.
3035 >     */
3036 >    public void testToCompletableFuture() {
3037 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3038 >        assertSame(f, f.toCompletableFuture());
3039 >    }
3040 >
3041 >    /**
3042 >     * whenComplete action executes on normal completion, propagating
3043 >     * source result.
3044 >     */
3045 >    public void testWhenComplete1() {
3046 >        final AtomicInteger a = new AtomicInteger();
3047 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3048 >        CompletableFuture<Integer> g =
3049 >            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3050 >        f.complete(three);
3051 >        checkCompletedNormally(f, three);
3052 >        checkCompletedNormally(g, three);
3053 >        assertEquals(a.get(), 1);
3054 >    }
3055 >
3056 >    /**
3057 >     * whenComplete action executes on exceptional completion, propagating
3058 >     * source result.
3059 >     */
3060 >    public void testWhenComplete2() {
3061 >        final AtomicInteger a = new AtomicInteger();
3062 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3063 >        CompletableFuture<Integer> g =
3064 >            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3065 >        f.completeExceptionally(new CFException());
3066 >        assertTrue(f.isCompletedExceptionally());
3067 >        assertTrue(g.isCompletedExceptionally());
3068 >        assertEquals(a.get(), 1);
3069 >    }
3070  
3071 +    /**
3072 +     * If a whenComplete action throws an exception when triggered by
3073 +     * a normal completion, it completes exceptionally
3074 +     */
3075 +    public void testWhenComplete3() {
3076 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3077 +        CompletableFuture<Integer> g =
3078 +            f.whenComplete((Integer x, Throwable t) ->
3079 +                           { throw new CFException(); } );
3080 +        f.complete(three);
3081 +        checkCompletedNormally(f, three);
3082 +        assertTrue(g.isCompletedExceptionally());
3083 +        checkCompletedWithWrappedCFException(g);
3084 +    }
3085 +
3086 +    /**
3087 +     * whenCompleteAsync action executes on normal completion, propagating
3088 +     * source result.
3089 +     */
3090 +    public void testWhenCompleteAsync1() {
3091 +        final AtomicInteger a = new AtomicInteger();
3092 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3093 +        CompletableFuture<Integer> g =
3094 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3095 +        f.complete(three);
3096 +        checkCompletedNormally(f, three);
3097 +        checkCompletedNormally(g, three);
3098 +        assertEquals(a.get(), 1);
3099 +    }
3100 +
3101 +    /**
3102 +     * whenCompleteAsync action executes on exceptional completion, propagating
3103 +     * source result.
3104 +     */
3105 +    public void testWhenCompleteAsync2() {
3106 +        final AtomicInteger a = new AtomicInteger();
3107 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3108 +        CompletableFuture<Integer> g =
3109 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3110 +        f.completeExceptionally(new CFException());
3111 +        checkCompletedWithWrappedCFException(f);
3112 +        checkCompletedWithWrappedCFException(g);
3113 +    }
3114 +
3115 +    /**
3116 +     * If a whenCompleteAsync action throws an exception when
3117 +     * triggered by a normal completion, it completes exceptionally
3118 +     */
3119 +    public void testWhenCompleteAsync3() {
3120 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3121 +        CompletableFuture<Integer> g =
3122 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3123 +                           { throw new CFException(); } );
3124 +        f.complete(three);
3125 +        checkCompletedNormally(f, three);
3126 +        checkCompletedWithWrappedCFException(g);
3127 +    }
3128 +
3129 +    /**
3130 +     * whenCompleteAsync action executes on normal completion, propagating
3131 +     * source result.
3132 +     */
3133 +    public void testWhenCompleteAsync1e() {
3134 +        final AtomicInteger a = new AtomicInteger();
3135 +        ThreadExecutor exec = new ThreadExecutor();
3136 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3137 +        CompletableFuture<Integer> g =
3138 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3139 +                                exec);
3140 +        f.complete(three);
3141 +        checkCompletedNormally(f, three);
3142 +        checkCompletedNormally(g, three);
3143 +        assertEquals(a.get(), 1);
3144 +    }
3145 +
3146 +    /**
3147 +     * whenCompleteAsync action executes on exceptional completion, propagating
3148 +     * source result.
3149 +     */
3150 +    public void testWhenCompleteAsync2e() {
3151 +        final AtomicInteger a = new AtomicInteger();
3152 +        ThreadExecutor exec = new ThreadExecutor();
3153 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3154 +        CompletableFuture<Integer> g =
3155 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3156 +                                exec);
3157 +        f.completeExceptionally(new CFException());
3158 +        checkCompletedWithWrappedCFException(f);
3159 +        checkCompletedWithWrappedCFException(g);
3160      }
3161  
3162 +    /**
3163 +     * If a whenCompleteAsync action throws an exception when triggered
3164 +     * by a normal completion, it completes exceptionally
3165 +     */
3166 +    public void testWhenCompleteAsync3e() {
3167 +        ThreadExecutor exec = new ThreadExecutor();
3168 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3169 +        CompletableFuture<Integer> g =
3170 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3171 +                                { throw new CFException(); },
3172 +                                exec);
3173 +        f.complete(three);
3174 +        checkCompletedNormally(f, three);
3175 +        checkCompletedWithWrappedCFException(g);
3176 +    }
3177 +
3178 +    /**
3179 +     * handleAsync action completes normally with function value on
3180 +     * either normal or exceptional completion of source
3181 +     */
3182 +    public void testHandleAsync() {
3183 +        CompletableFuture<Integer> f, g;
3184 +        IntegerHandler r;
3185 +
3186 +        f = new CompletableFuture<>();
3187 +        g = f.handleAsync(r = new IntegerHandler());
3188 +        assertFalse(r.ran);
3189 +        f.completeExceptionally(new CFException());
3190 +        checkCompletedWithWrappedCFException(f);
3191 +        checkCompletedNormally(g, three);
3192 +        assertTrue(r.ran);
3193 +
3194 +        f = new CompletableFuture<>();
3195 +        g = f.handleAsync(r = new IntegerHandler());
3196 +        assertFalse(r.ran);
3197 +        f.completeExceptionally(new CFException());
3198 +        checkCompletedWithWrappedCFException(f);
3199 +        checkCompletedNormally(g, three);
3200 +        assertTrue(r.ran);
3201 +
3202 +        f = new CompletableFuture<>();
3203 +        g = f.handleAsync(r = new IntegerHandler());
3204 +        assertFalse(r.ran);
3205 +        f.complete(one);
3206 +        checkCompletedNormally(f, one);
3207 +        checkCompletedNormally(g, two);
3208 +        assertTrue(r.ran);
3209 +
3210 +        f = new CompletableFuture<>();
3211 +        g = f.handleAsync(r = new IntegerHandler());
3212 +        assertFalse(r.ran);
3213 +        f.complete(one);
3214 +        checkCompletedNormally(f, one);
3215 +        checkCompletedNormally(g, two);
3216 +        assertTrue(r.ran);
3217 +    }
3218 +
3219 +    /**
3220 +     * handleAsync action with Executor completes normally with
3221 +     * function value on either normal or exceptional completion of
3222 +     * source
3223 +     */
3224 +    public void testHandleAsync2() {
3225 +        CompletableFuture<Integer> f, g;
3226 +        ThreadExecutor exec = new ThreadExecutor();
3227 +        IntegerHandler r;
3228 +
3229 +        f = new CompletableFuture<>();
3230 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3231 +        assertFalse(r.ran);
3232 +        f.completeExceptionally(new CFException());
3233 +        checkCompletedWithWrappedCFException(f);
3234 +        checkCompletedNormally(g, three);
3235 +        assertTrue(r.ran);
3236 +
3237 +        f = new CompletableFuture<>();
3238 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3239 +        assertFalse(r.ran);
3240 +        f.completeExceptionally(new CFException());
3241 +        checkCompletedWithWrappedCFException(f);
3242 +        checkCompletedNormally(g, three);
3243 +        assertTrue(r.ran);
3244 +
3245 +        f = new CompletableFuture<>();
3246 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3247 +        assertFalse(r.ran);
3248 +        f.complete(one);
3249 +        checkCompletedNormally(f, one);
3250 +        checkCompletedNormally(g, two);
3251 +        assertTrue(r.ran);
3252 +
3253 +        f = new CompletableFuture<>();
3254 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3255 +        assertFalse(r.ran);
3256 +        f.complete(one);
3257 +        checkCompletedNormally(f, one);
3258 +        checkCompletedNormally(g, two);
3259 +        assertTrue(r.ran);
3260 +    }
3261  
3262   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines