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.5 by dl, Thu Mar 21 16:26:43 2013 UTC vs.
Revision 1.33 by jsr166, Sun Jun 1 20:40:13 2014 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);
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 checkCompletedWithWrappedCFException(CompletableFuture<?> f,
106 >                                              CFException ex) {
107 >        try {
108 >            f.get(LONG_DELAY_MS, MILLISECONDS);
109 >            shouldThrow();
110 >        } catch (ExecutionException success) {
111 >            assertSame(ex, success.getCause());
112 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
113 >        try {
114 >            f.join();
115 >            shouldThrow();
116 >        } catch (CompletionException success) {
117 >            assertSame(ex, success.getCause());
118          }
119          try {
120 <            f.get(0L, SECONDS);
120 >            f.getNow(null);
121              shouldThrow();
122 <        } catch (Throwable ex) {
123 <            assertTrue(ex instanceof ExecutionException &&
101 <                       ((ExecutionException)ex).getCause() instanceof CFException);
122 >        } catch (CompletionException success) {
123 >            assertSame(ex, success.getCause());
124          }
125 +        try {
126 +            f.get();
127 +            shouldThrow();
128 +        } catch (ExecutionException success) {
129 +            assertSame(ex, success.getCause());
130 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
131          assertTrue(f.isDone());
132          assertFalse(f.isCancelled());
133 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
134      }
135  
136      void checkCancelled(CompletableFuture<?> f) {
137          try {
138 +            f.get(LONG_DELAY_MS, MILLISECONDS);
139 +            shouldThrow();
140 +        } catch (CancellationException success) {
141 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
142 +        try {
143              f.join();
144              shouldThrow();
145 <        } catch (Throwable ex) {
112 <            assertTrue(ex instanceof CancellationException);
113 <        }
145 >        } catch (CancellationException success) {}
146          try {
147              f.getNow(null);
148              shouldThrow();
149 <        } catch (Throwable ex) {
118 <            assertTrue(ex instanceof CancellationException);
119 <        }
149 >        } catch (CancellationException success) {}
150          try {
151              f.get();
152              shouldThrow();
153 <        } catch (Throwable ex) {
154 <            assertTrue(ex instanceof CancellationException);
125 <        }
126 <        try {
127 <            f.get(0L, SECONDS);
128 <            shouldThrow();
129 <        } catch (Throwable ex) {
130 <            assertTrue(ex instanceof CancellationException);
131 <        }
153 >        } catch (CancellationException success) {
154 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
155          assertTrue(f.isDone());
156 +        assertTrue(f.isCompletedExceptionally());
157          assertTrue(f.isCancelled());
158 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
159      }
160  
161      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
162          try {
163 +            f.get(LONG_DELAY_MS, MILLISECONDS);
164 +            shouldThrow();
165 +        } catch (ExecutionException success) {
166 +            assertTrue(success.getCause() instanceof CancellationException);
167 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
168 +        try {
169              f.join();
170              shouldThrow();
171 <        } catch (Throwable ex) {
172 <            assertTrue(ex instanceof CompletionException &&
142 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
171 >        } catch (CompletionException success) {
172 >            assertTrue(success.getCause() instanceof CancellationException);
173          }
174          try {
175              f.getNow(null);
176              shouldThrow();
177 <        } catch (Throwable ex) {
178 <            assertTrue(ex instanceof CompletionException &&
149 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
177 >        } catch (CompletionException success) {
178 >            assertTrue(success.getCause() instanceof CancellationException);
179          }
180          try {
181              f.get();
182              shouldThrow();
183 <        } catch (Throwable ex) {
184 <            assertTrue(ex instanceof ExecutionException &&
185 <                       ((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 <        }
183 >        } catch (ExecutionException success) {
184 >            assertTrue(success.getCause() instanceof CancellationException);
185 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
186          assertTrue(f.isDone());
187          assertFalse(f.isCancelled());
188 +        assertTrue(f.isCompletedExceptionally());
189 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
190      }
191  
192      /**
# Line 171 | Line 194 | public class CompletableFutureTest exten
194       * by methods isDone, isCancelled, and getNow
195       */
196      public void testConstructor() {
197 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
197 >        CompletableFuture<Integer> f = new CompletableFuture<>();
198          checkIncomplete(f);
199      }
200  
# Line 180 | Line 203 | public class CompletableFutureTest exten
203       * isCancelled, join, get, and getNow
204       */
205      public void testComplete() {
206 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
206 >        CompletableFuture<Integer> f = new CompletableFuture<>();
207          checkIncomplete(f);
208          f.complete(one);
209          checkCompletedNormally(f, one);
# Line 191 | Line 214 | public class CompletableFutureTest exten
214       * methods isDone, isCancelled, join, get, and getNow
215       */
216      public void testCompleteExceptionally() {
217 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
217 >        CompletableFuture<Integer> f = new CompletableFuture<>();
218          checkIncomplete(f);
219          f.completeExceptionally(new CFException());
220          checkCompletedWithWrappedCFException(f);
# Line 202 | Line 225 | public class CompletableFutureTest exten
225       * methods isDone, isCancelled, join, get, and getNow
226       */
227      public void testCancel() {
228 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
228 >        CompletableFuture<Integer> f = new CompletableFuture<>();
229          checkIncomplete(f);
230          assertTrue(f.cancel(true));
231          checkCancelled(f);
# Line 212 | Line 235 | public class CompletableFutureTest exten
235       * obtrudeValue forces completion with given value
236       */
237      public void testObtrudeValue() {
238 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
238 >        CompletableFuture<Integer> f = new CompletableFuture<>();
239          checkIncomplete(f);
240          f.complete(one);
241          checkCompletedNormally(f, one);
# Line 220 | Line 243 | public class CompletableFutureTest exten
243          checkCompletedNormally(f, three);
244          f.obtrudeValue(two);
245          checkCompletedNormally(f, two);
246 <        f = new CompletableFuture<Integer>();
246 >        f = new CompletableFuture<>();
247          f.obtrudeValue(three);
248          checkCompletedNormally(f, three);
249 <        f = new CompletableFuture<Integer>();
249 >        f = new CompletableFuture<>();
250          f.completeExceptionally(new CFException());
251          f.obtrudeValue(four);
252          checkCompletedNormally(f, four);
# Line 233 | Line 256 | public class CompletableFutureTest exten
256       * obtrudeException forces completion with given exception
257       */
258      public void testObtrudeException() {
259 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
259 >        CompletableFuture<Integer> f = new CompletableFuture<>();
260          checkIncomplete(f);
261          f.complete(one);
262          checkCompletedNormally(f, one);
263          f.obtrudeException(new CFException());
264          checkCompletedWithWrappedCFException(f);
265 <        f = new CompletableFuture<Integer>();
265 >        f = new CompletableFuture<>();
266          f.obtrudeException(new CFException());
267          checkCompletedWithWrappedCFException(f);
268 <        f = new CompletableFuture<Integer>();
268 >        f = new CompletableFuture<>();
269          f.completeExceptionally(new CFException());
270          f.obtrudeValue(four);
271          checkCompletedNormally(f, four);
272          f.obtrudeException(new CFException());
273          checkCompletedWithWrappedCFException(f);
274      }
275 <    
275 >
276      /**
277       * getNumberOfDependents returns number of dependent tasks
278       */
279      public void testGetNumberOfDependents() {
280 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
280 >        CompletableFuture<Integer> f = new CompletableFuture<>();
281          assertEquals(f.getNumberOfDependents(), 0);
282          CompletableFuture g = f.thenRun(new Noop());
283          assertEquals(f.getNumberOfDependents(), 1);
# Line 267 | Line 290 | public class CompletableFutureTest exten
290          assertEquals(g.getNumberOfDependents(), 0);
291      }
292  
270
293      /**
294       * toString indicates current completion state
295       */
# Line 285 | Line 307 | public class CompletableFutureTest exten
307          assertTrue(f.toString().contains("[Completed exceptionally]"));
308      }
309  
310 <    static final Supplier<Integer> supplyOne =
310 >    /**
311 >     * completedFuture returns a completed CompletableFuture with given value
312 >     */
313 >    public void testCompletedFuture() {
314 >        CompletableFuture<String> f = CompletableFuture.completedFuture("test");
315 >        checkCompletedNormally(f, "test");
316 >    }
317 >
318 >    // Choose non-commutative actions for better coverage
319 >
320 >    static final Supplier<Integer> supplyOne =
321          () -> Integer.valueOf(1);
322 <    static final Function<Integer, Integer> inc =
322 >    static final Function<Integer, Integer> inc =
323          (Integer x) -> Integer.valueOf(x.intValue() + 1);
324 <    static final BiFunction<Integer, Integer, Integer> add =
325 <        (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue());
324 >    static final BiFunction<Integer, Integer, Integer> subtract =
325 >        (Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue());
326      static final class IncAction implements Consumer<Integer> {
327          int value;
328          public void accept(Integer x) { value = x.intValue() + 1; }
329      }
330 <    static final class AddAction implements BiConsumer<Integer, Integer> {
330 >    static final class SubtractAction implements BiConsumer<Integer, Integer> {
331          int value;
332 <        public void accept(Integer x, Integer y) {
333 <            value = x.intValue() + y.intValue();
332 >        public void accept(Integer x, Integer y) {
333 >            value = x.intValue() - y.intValue();
334          }
335      }
336      static final class Noop implements Runnable {
# Line 331 | Line 363 | public class CompletableFutureTest exten
363          public void run() { ran = true; throw new CFException(); }
364      }
365  
366 <    static final class CompletableFutureInc implements Function<Integer, CompletableFuture<Integer>> {
366 >    static final class CompletableFutureInc
367 >        implements Function<Integer, CompletableFuture<Integer>> {
368 >        boolean ran;
369          public CompletableFuture<Integer> apply(Integer x) {
370 <            CompletableFuture<Integer> f = new CompletableFuture<Integer>();
370 >            ran = true;
371 >            CompletableFuture<Integer> f = new CompletableFuture<>();
372              f.complete(Integer.valueOf(x.intValue() + 1));
373              return f;
374          }
375      }
376  
377 <    static final class FailingCompletableFutureFunction implements Function<Integer, CompletableFuture<Integer>> {
377 >    static final class FailingCompletableFutureFunction
378 >        implements Function<Integer, CompletableFuture<Integer>> {
379          boolean ran;
380          public CompletableFuture<Integer> apply(Integer x) {
381              ran = true; throw new CFException();
382          }
383      }
384 <    
384 >
385      // Used for explicit executor tests
386      static final class ThreadExecutor implements Executor {
387 +        AtomicInteger count = new AtomicInteger(0);
388 +
389          public void execute(Runnable r) {
390 +            count.getAndIncrement();
391              new Thread(r).start();
392          }
393      }
# Line 358 | Line 397 | public class CompletableFutureTest exten
397      }
398  
399      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
400 <        public Integer apply(Integer x, Throwable t) {
400 >        boolean ran;
401 >        public Integer apply(Integer x, Throwable t) {
402 >            ran = true;
403              return (t == null) ? two : three;
404          }
405      }
406  
366
407      /**
408       * exceptionally action completes with function value on source
409 <     * exception;  otherwise with source value
409 >     * exception; otherwise with source value
410       */
411      public void testExceptionally() {
412 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
412 >        CompletableFuture<Integer> f = new CompletableFuture<>();
413          ExceptionToInteger r = new ExceptionToInteger();
414          CompletableFuture<Integer> g = f.exceptionally(r);
415          f.completeExceptionally(new CFException());
416          checkCompletedNormally(g, three);
417  
418 <        f = new CompletableFuture<Integer>();
418 >        f = new CompletableFuture<>();
419          r = new ExceptionToInteger();
420          g = f.exceptionally(r);
421          f.complete(one);
# Line 387 | Line 427 | public class CompletableFutureTest exten
427       * normal or exceptional completion of source
428       */
429      public void testHandle() {
430 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
431 <        IntegerHandler r = new IntegerHandler();
432 <        CompletableFuture<Integer> g = f.handle(r);
430 >        CompletableFuture<Integer> f, g;
431 >        IntegerHandler r;
432 >
433 >        f = new CompletableFuture<>();
434          f.completeExceptionally(new CFException());
435 +        g = f.handle(r = new IntegerHandler());
436 +        assertTrue(r.ran);
437          checkCompletedNormally(g, three);
438  
439 <        f = new CompletableFuture<Integer>();
440 <        r = new IntegerHandler();
441 <        g = f.handle(r);
439 >        f = new CompletableFuture<>();
440 >        g = f.handle(r = new IntegerHandler());
441 >        assertFalse(r.ran);
442 >        f.completeExceptionally(new CFException());
443 >        checkCompletedNormally(g, three);
444 >        assertTrue(r.ran);
445 >
446 >        f = new CompletableFuture<>();
447 >        f.complete(one);
448 >        g = f.handle(r = new IntegerHandler());
449 >        assertTrue(r.ran);
450 >        checkCompletedNormally(g, two);
451 >
452 >        f = new CompletableFuture<>();
453 >        g = f.handle(r = new IntegerHandler());
454 >        assertFalse(r.ran);
455          f.complete(one);
456 +        assertTrue(r.ran);
457          checkCompletedNormally(g, two);
458      }
459  
# Line 408 | Line 465 | public class CompletableFutureTest exten
465          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
466          assertNull(f.join());
467          assertTrue(r.ran);
468 +        checkCompletedNormally(f, null);
469      }
470  
471      /**
# Line 415 | Line 473 | public class CompletableFutureTest exten
473       */
474      public void testRunAsync2() {
475          Noop r = new Noop();
476 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor());
476 >        ThreadExecutor exec = new ThreadExecutor();
477 >        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
478          assertNull(f.join());
479          assertTrue(r.ran);
480 +        checkCompletedNormally(f, null);
481 +        assertEquals(1, exec.count.get());
482      }
483  
484      /**
# Line 434 | Line 495 | public class CompletableFutureTest exten
495       * supplyAsync completes with result of supplier
496       */
497      public void testSupplyAsync() {
498 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne);
498 >        CompletableFuture<Integer> f;
499 >        f = CompletableFuture.supplyAsync(supplyOne);
500          assertEquals(f.join(), one);
501 +        checkCompletedNormally(f, one);
502      }
503  
504      /**
505       * supplyAsync with executor completes with result of supplier
506       */
507      public void testSupplyAsync2() {
508 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
508 >        CompletableFuture<Integer> f;
509 >        f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
510          assertEquals(f.join(), one);
511 +        checkCompletedNormally(f, one);
512      }
513  
514      /**
# Line 456 | Line 521 | public class CompletableFutureTest exten
521          assertTrue(r.ran);
522      }
523  
524 <    // seq conmpletion methods
525 <    
524 >    // seq completion methods
525 >
526      /**
527       * thenRun result completes normally after normal completion of source
528       */
529      public void testThenRun() {
530 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
531 <        Noop r = new Noop();
532 <        CompletableFuture<Void> g = f.thenRun(r);
530 >        CompletableFuture<Integer> f;
531 >        CompletableFuture<Void> g;
532 >        Noop r;
533 >
534 >        f = new CompletableFuture<>();
535 >        g = f.thenRun(r = new Noop());
536          f.complete(null);
537          checkCompletedNormally(g, null);
538 <        // reordered version
539 <        f = new CompletableFuture<Integer>();
538 >        assertTrue(r.ran);
539 >
540 >        f = new CompletableFuture<>();
541          f.complete(null);
542 <        r = new Noop();
474 <        g = f.thenRun(r);
542 >        g = f.thenRun(r = new Noop());
543          checkCompletedNormally(g, null);
544 +        assertTrue(r.ran);
545      }
546  
547      /**
# Line 480 | Line 549 | public class CompletableFutureTest exten
549       * completion of source
550       */
551      public void testThenRun2() {
552 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
553 <        Noop r = new Noop();
554 <        CompletableFuture<Void> g = f.thenRun(r);
552 >        CompletableFuture<Integer> f;
553 >        CompletableFuture<Void> g;
554 >        Noop r;
555 >
556 >        f = new CompletableFuture<>();
557 >        g = f.thenRun(r = new Noop());
558 >        f.completeExceptionally(new CFException());
559 >        checkCompletedWithWrappedCFException(g);
560 >        assertFalse(r.ran);
561 >
562 >        f = new CompletableFuture<>();
563          f.completeExceptionally(new CFException());
564 +        g = f.thenRun(r = new Noop());
565          checkCompletedWithWrappedCFException(g);
566 +        assertFalse(r.ran);
567      }
568  
569      /**
570       * thenRun result completes exceptionally if action does
571       */
572      public void testThenRun3() {
573 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
574 <        FailingNoop r = new FailingNoop();
575 <        CompletableFuture<Void> g = f.thenRun(r);
573 >        CompletableFuture<Integer> f;
574 >        CompletableFuture<Void> g;
575 >        FailingNoop r;
576 >
577 >        f = new CompletableFuture<>();
578 >        g = f.thenRun(r = new FailingNoop());
579 >        f.complete(null);
580 >        checkCompletedWithWrappedCFException(g);
581 >
582 >        f = new CompletableFuture<>();
583          f.complete(null);
584 +        g = f.thenRun(r = new FailingNoop());
585          checkCompletedWithWrappedCFException(g);
586      }
587  
# Line 502 | Line 589 | public class CompletableFutureTest exten
589       * thenRun result completes exceptionally if source cancelled
590       */
591      public void testThenRun4() {
592 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
593 <        Noop r = new Noop();
594 <        CompletableFuture<Void> g = f.thenRun(r);
592 >        CompletableFuture<Integer> f;
593 >        CompletableFuture<Void> g;
594 >        Noop r;
595 >
596 >        f = new CompletableFuture<>();
597 >        g = f.thenRun(r = new Noop());
598          assertTrue(f.cancel(true));
599          checkCompletedWithWrappedCancellationException(g);
600 +
601 +        f = new CompletableFuture<>();
602 +        assertTrue(f.cancel(true));
603 +        g = f.thenRun(r = new Noop());
604 +        checkCompletedWithWrappedCancellationException(g);
605      }
606  
607      /**
608       * thenApply result completes normally after normal completion of source
609       */
610      public void testThenApply() {
611 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
611 >        CompletableFuture<Integer> f = new CompletableFuture<>();
612          CompletableFuture<Integer> g = f.thenApply(inc);
613          f.complete(one);
614          checkCompletedNormally(g, two);
# Line 524 | Line 619 | public class CompletableFutureTest exten
619       * completion of source
620       */
621      public void testThenApply2() {
622 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
622 >        CompletableFuture<Integer> f = new CompletableFuture<>();
623          CompletableFuture<Integer> g = f.thenApply(inc);
624          f.completeExceptionally(new CFException());
625          checkCompletedWithWrappedCFException(g);
# Line 534 | Line 629 | public class CompletableFutureTest exten
629       * thenApply result completes exceptionally if action does
630       */
631      public void testThenApply3() {
632 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
632 >        CompletableFuture<Integer> f = new CompletableFuture<>();
633          CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
634          f.complete(one);
635          checkCompletedWithWrappedCFException(g);
# Line 544 | Line 639 | public class CompletableFutureTest exten
639       * thenApply result completes exceptionally if source cancelled
640       */
641      public void testThenApply4() {
642 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
642 >        CompletableFuture<Integer> f = new CompletableFuture<>();
643          CompletableFuture<Integer> g = f.thenApply(inc);
644          assertTrue(f.cancel(true));
645          checkCompletedWithWrappedCancellationException(g);
# Line 554 | Line 649 | public class CompletableFutureTest exten
649       * thenAccept result completes normally after normal completion of source
650       */
651      public void testThenAccept() {
652 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
652 >        CompletableFuture<Integer> f = new CompletableFuture<>();
653          IncAction r = new IncAction();
654          CompletableFuture<Void> g = f.thenAccept(r);
655          f.complete(one);
# Line 567 | Line 662 | public class CompletableFutureTest exten
662       * completion of source
663       */
664      public void testThenAccept2() {
665 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
665 >        CompletableFuture<Integer> f = new CompletableFuture<>();
666          IncAction r = new IncAction();
667          CompletableFuture<Void> g = f.thenAccept(r);
668          f.completeExceptionally(new CFException());
# Line 578 | Line 673 | public class CompletableFutureTest exten
673       * thenAccept result completes exceptionally if action does
674       */
675      public void testThenAccept3() {
676 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
676 >        CompletableFuture<Integer> f = new CompletableFuture<>();
677          FailingConsumer r = new FailingConsumer();
678          CompletableFuture<Void> g = f.thenAccept(r);
679          f.complete(one);
# Line 590 | Line 685 | public class CompletableFutureTest exten
685       * thenAccept result completes exceptionally if source cancelled
686       */
687      public void testThenAccept4() {
688 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
688 >        CompletableFuture<Integer> f = new CompletableFuture<>();
689          IncAction r = new IncAction();
690          CompletableFuture<Void> g = f.thenAccept(r);
691          assertTrue(f.cancel(true));
692          checkCompletedWithWrappedCancellationException(g);
693      }
694  
600
695      /**
696 <     * thenCombine result completes normally after normal completion of sources
696 >     * thenCombine result completes normally after normal completion
697 >     * of sources
698       */
699      public void testThenCombine() {
700 <        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);
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 <        checkIncomplete(g);
707 <        f2.complete(two);
708 <        checkCompletedNormally(g, three);
702 >        f = new CompletableFuture<>();
703 >        g = new CompletableFuture<>();
704 >        h = f.thenCombine(g, subtract);
705 >        f.complete(3);
706 >        checkIncomplete(h);
707 >        g.complete(1);
708 >        checkCompletedNormally(h, 2);
709 >
710 >        f = new CompletableFuture<>();
711 >        g = new CompletableFuture<>();
712 >        h = f.thenCombine(g, subtract);
713 >        g.complete(1);
714 >        checkIncomplete(h);
715 >        f.complete(3);
716 >        checkCompletedNormally(h, 2);
717 >
718 >        f = new CompletableFuture<>();
719 >        g = new CompletableFuture<>();
720 >        g.complete(1);
721 >        f.complete(3);
722 >        h = f.thenCombine(g, subtract);
723 >        checkCompletedNormally(h, 2);
724      }
725  
726      /**
# Line 624 | Line 728 | public class CompletableFutureTest exten
728       * completion of either source
729       */
730      public void testThenCombine2() {
731 <        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);
731 >        CompletableFuture<Integer> f, g, h;
732  
733 <        f = new CompletableFuture<Integer>();
734 <        f.complete(one);
735 <        f2 = new CompletableFuture<Integer>();
736 <        g = f.thenCombine(f2, add);
737 <        f2.completeExceptionally(new CFException());
738 <        checkCompletedWithWrappedCFException(g);
733 >        f = new CompletableFuture<>();
734 >        g = new CompletableFuture<>();
735 >        h = f.thenCombine(g, subtract);
736 >        f.completeExceptionally(new CFException());
737 >        checkIncomplete(h);
738 >        g.complete(1);
739 >        checkCompletedWithWrappedCFException(h);
740 >
741 >        f = new CompletableFuture<>();
742 >        g = new CompletableFuture<>();
743 >        h = f.thenCombine(g, subtract);
744 >        g.completeExceptionally(new CFException());
745 >        checkIncomplete(h);
746 >        f.complete(3);
747 >        checkCompletedWithWrappedCFException(h);
748 >
749 >        f = new CompletableFuture<>();
750 >        g = new CompletableFuture<>();
751 >        f.complete(3);
752 >        g.completeExceptionally(new CFException());
753 >        h = f.thenCombine(g, subtract);
754 >        checkCompletedWithWrappedCFException(h);
755 >
756 >        f = new CompletableFuture<>();
757 >        g = new CompletableFuture<>();
758 >        f.completeExceptionally(new CFException());
759 >        g.complete(3);
760 >        h = f.thenCombine(g, subtract);
761 >        checkCompletedWithWrappedCFException(h);
762      }
763  
764      /**
765       * thenCombine result completes exceptionally if action does
766       */
767      public void testThenCombine3() {
768 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
769 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
768 >        CompletableFuture<Integer> f = new CompletableFuture<>();
769 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
770          FailingBiFunction r = new FailingBiFunction();
771          CompletableFuture<Integer> g = f.thenCombine(f2, r);
772          f.complete(one);
773          checkIncomplete(g);
774 +        assertFalse(r.ran);
775          f2.complete(two);
776          checkCompletedWithWrappedCFException(g);
777 +        assertTrue(r.ran);
778      }
779  
780      /**
781       * thenCombine result completes exceptionally if either source cancelled
782       */
783      public void testThenCombine4() {
784 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
785 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
786 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
787 <        assertTrue(f.cancel(true));
788 <        f2.complete(two);
789 <        checkCompletedWithWrappedCancellationException(g);
790 <        f = new CompletableFuture<Integer>();
791 <        f2 = new CompletableFuture<Integer>();
792 <        g = f.thenCombine(f2, add);
793 <        f.complete(one);
794 <        assertTrue(f2.cancel(true));
795 <        checkCompletedWithWrappedCancellationException(g);
784 >        CompletableFuture<Integer> f, g, h;
785 >
786 >        f = new CompletableFuture<>();
787 >        g = new CompletableFuture<>();
788 >        h = f.thenCombine(g, subtract);
789 >        assertTrue(f.cancel(true));
790 >        checkIncomplete(h);
791 >        g.complete(1);
792 >        checkCompletedWithWrappedCancellationException(h);
793 >
794 >        f = new CompletableFuture<>();
795 >        g = new CompletableFuture<>();
796 >        h = f.thenCombine(g, subtract);
797 >        assertTrue(g.cancel(true));
798 >        checkIncomplete(h);
799 >        f.complete(3);
800 >        checkCompletedWithWrappedCancellationException(h);
801 >
802 >        f = new CompletableFuture<>();
803 >        g = new CompletableFuture<>();
804 >        assertTrue(f.cancel(true));
805 >        assertTrue(g.cancel(true));
806 >        h = f.thenCombine(g, subtract);
807 >        checkCompletedWithWrappedCancellationException(h);
808      }
809  
810      /**
# Line 676 | Line 812 | public class CompletableFutureTest exten
812       * completion of sources
813       */
814      public void testThenAcceptBoth() {
815 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
816 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
817 <        AddAction r = new AddAction();
818 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
819 <        f.complete(one);
820 <        checkIncomplete(g);
821 <        f2.complete(two);
822 <        checkCompletedNormally(g, null);
823 <        assertEquals(r.value, 3);
815 >        CompletableFuture<Integer> f, g;
816 >        CompletableFuture<Void> h;
817 >        SubtractAction r;
818 >
819 >        f = new CompletableFuture<>();
820 >        g = new CompletableFuture<>();
821 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
822 >        f.complete(3);
823 >        checkIncomplete(h);
824 >        g.complete(1);
825 >        checkCompletedNormally(h, null);
826 >        assertEquals(r.value, 2);
827  
828 <        r = new AddAction();
829 <        f = new CompletableFuture<Integer>();
830 <        f.complete(one);
831 <        f2 = new CompletableFuture<Integer>();
832 <        g = f.thenAcceptBoth(f2, r);
833 <        checkIncomplete(g);
834 <        f2.complete(two);
835 <        checkCompletedNormally(g, null);
836 <        assertEquals(r.value, 3);
828 >        f = new CompletableFuture<>();
829 >        g = new CompletableFuture<>();
830 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
831 >        g.complete(1);
832 >        checkIncomplete(h);
833 >        f.complete(3);
834 >        checkCompletedNormally(h, null);
835 >        assertEquals(r.value, 2);
836 >
837 >        f = new CompletableFuture<>();
838 >        g = new CompletableFuture<>();
839 >        g.complete(1);
840 >        f.complete(3);
841 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
842 >        checkCompletedNormally(h, null);
843 >        assertEquals(r.value, 2);
844      }
845  
846      /**
# Line 702 | Line 848 | public class CompletableFutureTest exten
848       * completion of either source
849       */
850      public void testThenAcceptBoth2() {
851 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
852 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
853 <        AddAction r = new AddAction();
854 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
855 <        f.completeExceptionally(new CFException());
856 <        f2.complete(two);
857 <        checkCompletedWithWrappedCFException(g);
858 <
859 <        r = new AddAction();
860 <        f = new CompletableFuture<Integer>();
861 <        f.complete(one);
862 <        f2 = new CompletableFuture<Integer>();
863 <        g = f.thenAcceptBoth(f2, r);
864 <        f2.completeExceptionally(new CFException());
865 <        checkCompletedWithWrappedCFException(g);
851 >        CompletableFuture<Integer> f, g;
852 >        CompletableFuture<Void> h;
853 >        SubtractAction r;
854 >
855 >        f = new CompletableFuture<>();
856 >        g = new CompletableFuture<>();
857 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
858 >        f.completeExceptionally(new CFException());
859 >        checkIncomplete(h);
860 >        g.complete(1);
861 >        checkCompletedWithWrappedCFException(h);
862 >
863 >        f = new CompletableFuture<>();
864 >        g = new CompletableFuture<>();
865 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
866 >        g.completeExceptionally(new CFException());
867 >        checkIncomplete(h);
868 >        f.complete(3);
869 >        checkCompletedWithWrappedCFException(h);
870 >
871 >        f = new CompletableFuture<>();
872 >        g = new CompletableFuture<>();
873 >        f.complete(3);
874 >        g.completeExceptionally(new CFException());
875 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
876 >        checkCompletedWithWrappedCFException(h);
877 >
878 >        f = new CompletableFuture<>();
879 >        g = new CompletableFuture<>();
880 >        f.completeExceptionally(new CFException());
881 >        g.complete(3);
882 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
883 >        checkCompletedWithWrappedCFException(h);
884      }
885  
886      /**
887       * thenAcceptBoth result completes exceptionally if action does
888       */
889      public void testThenAcceptBoth3() {
890 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
891 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
892 <        FailingBiConsumer r = new FailingBiConsumer();
893 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
894 <        f.complete(one);
895 <        checkIncomplete(g);
896 <        f2.complete(two);
897 <        checkCompletedWithWrappedCFException(g);
890 >        CompletableFuture<Integer> f, g;
891 >        CompletableFuture<Void> h;
892 >        FailingBiConsumer r;
893 >
894 >        f = new CompletableFuture<>();
895 >        g = new CompletableFuture<>();
896 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
897 >        f.complete(3);
898 >        checkIncomplete(h);
899 >        g.complete(1);
900 >        checkCompletedWithWrappedCFException(h);
901 >
902 >        f = new CompletableFuture<>();
903 >        g = new CompletableFuture<>();
904 >        f.complete(3);
905 >        g.complete(1);
906 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
907 >        checkCompletedWithWrappedCFException(h);
908      }
909  
910      /**
911       * thenAcceptBoth result completes exceptionally if either source cancelled
912       */
913      public void testThenAcceptBoth4() {
914 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
915 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
916 <        AddAction r = new AddAction();
917 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
918 <        assertTrue(f.cancel(true));
919 <        f2.complete(two);
920 <        checkCompletedWithWrappedCancellationException(g);
921 <        f = new CompletableFuture<Integer>();
922 <        f2 = new CompletableFuture<Integer>();
923 <        r = new AddAction();
924 <        g = f.thenAcceptBoth(f2, r);
925 <        f.complete(one);
926 <        assertTrue(f2.cancel(true));
927 <        checkCompletedWithWrappedCancellationException(g);
914 >        CompletableFuture<Integer> f, g;
915 >        CompletableFuture<Void> h;
916 >        SubtractAction r;
917 >
918 >        f = new CompletableFuture<>();
919 >        g = new CompletableFuture<>();
920 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
921 >        assertTrue(f.cancel(true));
922 >        checkIncomplete(h);
923 >        g.complete(1);
924 >        checkCompletedWithWrappedCancellationException(h);
925 >
926 >        f = new CompletableFuture<>();
927 >        g = new CompletableFuture<>();
928 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
929 >        assertTrue(g.cancel(true));
930 >        checkIncomplete(h);
931 >        f.complete(3);
932 >        checkCompletedWithWrappedCancellationException(h);
933 >
934 >        f = new CompletableFuture<>();
935 >        g = new CompletableFuture<>();
936 >        f.complete(3);
937 >        assertTrue(g.cancel(true));
938 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
939 >        checkCompletedWithWrappedCancellationException(h);
940 >
941 >        f = new CompletableFuture<>();
942 >        g = new CompletableFuture<>();
943 >        assertTrue(f.cancel(true));
944 >        g.complete(3);
945 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
946 >        checkCompletedWithWrappedCancellationException(h);
947      }
948  
949      /**
950       * runAfterBoth result completes normally after normal
951       * completion of sources
952       */
953 <    public void testRunAfterBoth() {
954 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
955 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
956 <        Noop r = new Noop();
957 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
958 <        f.complete(one);
959 <        checkIncomplete(g);
960 <        f2.complete(two);
961 <        checkCompletedNormally(g, null);
953 >    public void testRunAfterBoth_normalCompletion1() {
954 >        for (Integer v1 : new Integer[] { 1, null })
955 >        for (Integer v2 : new Integer[] { 2, null }) {
956 >
957 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
958 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
959 >        final Noop r = new Noop();
960 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
961 >
962 >        f.complete(v1);
963 >        checkIncomplete(h);
964 >        assertFalse(r.ran);
965 >        g.complete(v2);
966 >
967 >        checkCompletedNormally(h, null);
968          assertTrue(r.ran);
969 +        checkCompletedNormally(f, v1);
970 +        checkCompletedNormally(g, v2);
971 +        }
972 +    }
973  
974 <        r = new Noop();
975 <        f = new CompletableFuture<Integer>();
976 <        f.complete(one);
977 <        f2 = new CompletableFuture<Integer>();
978 <        g = f.runAfterBoth(f2, r);
979 <        checkIncomplete(g);
980 <        f2.complete(two);
981 <        checkCompletedNormally(g, null);
974 >    public void testRunAfterBoth_normalCompletion2() {
975 >        for (Integer v1 : new Integer[] { 1, null })
976 >        for (Integer v2 : new Integer[] { 2, null }) {
977 >
978 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
979 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
980 >        final Noop r = new Noop();
981 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
982 >
983 >        g.complete(v2);
984 >        checkIncomplete(h);
985 >        assertFalse(r.ran);
986 >        f.complete(v1);
987 >
988 >        checkCompletedNormally(h, null);
989          assertTrue(r.ran);
990 +        checkCompletedNormally(f, v1);
991 +        checkCompletedNormally(g, v2);
992 +        }
993 +    }
994 +
995 +    public void testRunAfterBoth_normalCompletion3() {
996 +        for (Integer v1 : new Integer[] { 1, null })
997 +        for (Integer v2 : new Integer[] { 2, null }) {
998 +
999 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1000 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1001 +        final Noop r = new Noop();
1002 +
1003 +        g.complete(v2);
1004 +        f.complete(v1);
1005 +        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1006 +
1007 +        checkCompletedNormally(h, null);
1008 +        assertTrue(r.ran);
1009 +        checkCompletedNormally(f, v1);
1010 +        checkCompletedNormally(g, v2);
1011 +        }
1012 +    }
1013 +
1014 +    public void testRunAfterBoth_normalCompletion4() {
1015 +        for (Integer v1 : new Integer[] { 1, null })
1016 +        for (Integer v2 : new Integer[] { 2, null }) {
1017 +
1018 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1019 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1020 +        final Noop r = new Noop();
1021 +
1022 +        f.complete(v1);
1023 +        g.complete(v2);
1024 +        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1025 +
1026 +        checkCompletedNormally(h, null);
1027 +        assertTrue(r.ran);
1028 +        checkCompletedNormally(f, v1);
1029 +        checkCompletedNormally(g, v2);
1030 +        }
1031      }
1032  
1033      /**
1034       * runAfterBoth result completes exceptionally after exceptional
1035       * completion of either source
1036       */
1037 <    public void testRunAfterBoth2() {
1038 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
788 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
789 <        Noop r = new Noop();
790 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
791 <        f.completeExceptionally(new CFException());
792 <        f2.complete(two);
793 <        checkCompletedWithWrappedCFException(g);
1037 >    public void testRunAfterBoth_exceptionalCompletion1() {
1038 >        for (Integer v1 : new Integer[] { 1, null }) {
1039  
1040 <        r = new Noop();
1041 <        f = new CompletableFuture<Integer>();
1042 <        f.complete(one);
1043 <        f2 = new CompletableFuture<Integer>();
1044 <        g = f.runAfterBoth(f2, r);
1045 <        f2.completeExceptionally(new CFException());
1046 <        checkCompletedWithWrappedCFException(g);
1040 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1041 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1042 >        final Noop r = new Noop();
1043 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1044 >        final CFException ex = new CFException();
1045 >
1046 >        f.completeExceptionally(ex);
1047 >        checkIncomplete(h);
1048 >        g.complete(v1);
1049 >
1050 >        checkCompletedWithWrappedCFException(h, ex);
1051 >        checkCompletedWithWrappedCFException(f, ex);
1052 >        assertFalse(r.ran);
1053 >        checkCompletedNormally(g, v1);
1054 >        }
1055 >    }
1056 >
1057 >    public void testRunAfterBoth_exceptionalCompletion2() {
1058 >        for (Integer v1 : new Integer[] { 1, null }) {
1059 >
1060 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1061 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1062 >        final Noop r = new Noop();
1063 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1064 >        final CFException ex = new CFException();
1065 >
1066 >        g.completeExceptionally(ex);
1067 >        checkIncomplete(h);
1068 >        f.complete(v1);
1069 >
1070 >        checkCompletedWithWrappedCFException(h, ex);
1071 >        checkCompletedWithWrappedCFException(g, ex);
1072 >        assertFalse(r.ran);
1073 >        checkCompletedNormally(f, v1);
1074 >        }
1075 >    }
1076 >
1077 >    public void testRunAfterBoth_exceptionalCompletion3() {
1078 >        for (Integer v1 : new Integer[] { 1, null }) {
1079 >
1080 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1081 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1082 >        final Noop r = new Noop();
1083 >        final CFException ex = new CFException();
1084 >
1085 >        g.completeExceptionally(ex);
1086 >        f.complete(v1);
1087 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1088 >
1089 >        checkCompletedWithWrappedCFException(h, ex);
1090 >        checkCompletedWithWrappedCFException(g, ex);
1091 >        assertFalse(r.ran);
1092 >        checkCompletedNormally(f, v1);
1093 >        }
1094 >    }
1095 >
1096 >    public void testRunAfterBoth_exceptionalCompletion4() {
1097 >        for (Integer v1 : new Integer[] { 1, null }) {
1098 >
1099 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1100 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1101 >        final Noop r = new Noop();
1102 >        final CFException ex = new CFException();
1103 >
1104 >        f.completeExceptionally(ex);
1105 >        g.complete(v1);
1106 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1107 >
1108 >        checkCompletedWithWrappedCFException(h, ex);
1109 >        checkCompletedWithWrappedCFException(f, ex);
1110 >        assertFalse(r.ran);
1111 >        checkCompletedNormally(g, v1);
1112 >        }
1113      }
1114  
1115      /**
1116       * runAfterBoth result completes exceptionally if action does
1117       */
1118 <    public void testRunAfterBoth3() {
1119 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1120 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1121 <        FailingNoop r = new FailingNoop();
1122 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1123 <        f.complete(one);
1124 <        checkIncomplete(g);
1125 <        f2.complete(two);
1126 <        checkCompletedWithWrappedCFException(g);
1118 >    public void testRunAfterBoth_actionFailed1() {
1119 >        for (Integer v1 : new Integer[] { 1, null })
1120 >        for (Integer v2 : new Integer[] { 2, null }) {
1121 >
1122 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1123 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1124 >        final FailingNoop r = new FailingNoop();
1125 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1126 >
1127 >        f.complete(v1);
1128 >        checkIncomplete(h);
1129 >        g.complete(v2);
1130 >
1131 >        checkCompletedWithWrappedCFException(h);
1132 >        checkCompletedNormally(f, v1);
1133 >        checkCompletedNormally(g, v2);
1134 >        }
1135 >    }
1136 >
1137 >    public void testRunAfterBoth_actionFailed2() {
1138 >        for (Integer v1 : new Integer[] { 1, null })
1139 >        for (Integer v2 : new Integer[] { 2, null }) {
1140 >
1141 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1142 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1143 >        final FailingNoop r = new FailingNoop();
1144 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1145 >
1146 >        g.complete(v2);
1147 >        checkIncomplete(h);
1148 >        f.complete(v1);
1149 >
1150 >        checkCompletedWithWrappedCFException(h);
1151 >        checkCompletedNormally(f, v1);
1152 >        checkCompletedNormally(g, v2);
1153 >        }
1154      }
1155  
1156      /**
1157       * runAfterBoth result completes exceptionally if either source cancelled
1158       */
1159 <    public void testRunAfterBoth4() {
1160 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1161 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1162 <        Noop r = new Noop();
1163 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1164 <        assertTrue(f.cancel(true));
1165 <        f2.complete(two);
1166 <        checkCompletedWithWrappedCancellationException(g);
1167 <        f = new CompletableFuture<Integer>();
1168 <        f2 = new CompletableFuture<Integer>();
1169 <        r = new Noop();
1170 <        g = f.runAfterBoth(f2, r);
1171 <        f.complete(one);
1172 <        assertTrue(f2.cancel(true));
1173 <        checkCompletedWithWrappedCancellationException(g);
1159 >    public void testRunAfterBoth_sourceCancelled1() {
1160 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1161 >        for (Integer v1 : new Integer[] { 1, null }) {
1162 >
1163 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1164 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1165 >        final Noop r = new Noop();
1166 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1167 >
1168 >        assertTrue(f.cancel(mayInterruptIfRunning));
1169 >        checkIncomplete(h);
1170 >        g.complete(v1);
1171 >
1172 >        checkCompletedWithWrappedCancellationException(h);
1173 >        checkCancelled(f);
1174 >        assertFalse(r.ran);
1175 >        checkCompletedNormally(g, v1);
1176 >        }
1177 >    }
1178 >
1179 >    public void testRunAfterBoth_sourceCancelled2() {
1180 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1181 >        for (Integer v1 : new Integer[] { 1, null }) {
1182 >
1183 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1184 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1185 >        final Noop r = new Noop();
1186 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1187 >
1188 >        assertTrue(g.cancel(mayInterruptIfRunning));
1189 >        checkIncomplete(h);
1190 >        f.complete(v1);
1191 >
1192 >        checkCompletedWithWrappedCancellationException(h);
1193 >        checkCancelled(g);
1194 >        assertFalse(r.ran);
1195 >        checkCompletedNormally(f, v1);
1196 >        }
1197 >    }
1198 >
1199 >    public void testRunAfterBoth_sourceCancelled3() {
1200 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1201 >        for (Integer v1 : new Integer[] { 1, null }) {
1202 >
1203 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1204 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1205 >        final Noop r = new Noop();
1206 >
1207 >        assertTrue(g.cancel(mayInterruptIfRunning));
1208 >        f.complete(v1);
1209 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1210 >
1211 >        checkCompletedWithWrappedCancellationException(h);
1212 >        checkCancelled(g);
1213 >        assertFalse(r.ran);
1214 >        checkCompletedNormally(f, v1);
1215 >        }
1216 >    }
1217 >
1218 >    public void testRunAfterBoth_sourceCancelled4() {
1219 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1220 >        for (Integer v1 : new Integer[] { 1, null }) {
1221 >
1222 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1223 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1224 >        final Noop r = new Noop();
1225 >
1226 >        assertTrue(f.cancel(mayInterruptIfRunning));
1227 >        g.complete(v1);
1228 >        final CompletableFuture<Void> h = f.runAfterBoth(g, r);
1229 >
1230 >        checkCompletedWithWrappedCancellationException(h);
1231 >        checkCancelled(f);
1232 >        assertFalse(r.ran);
1233 >        checkCompletedNormally(g, v1);
1234 >        }
1235      }
1236  
1237      /**
# Line 840 | Line 1239 | public class CompletableFutureTest exten
1239       * of either source
1240       */
1241      public void testApplyToEither() {
1242 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1243 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1242 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1243 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1244          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1245          f.complete(one);
1246          checkCompletedNormally(g, two);
1247          f2.complete(one);
1248          checkCompletedNormally(g, two);
1249  
1250 <        f = new CompletableFuture<Integer>();
1250 >        f = new CompletableFuture<>();
1251          f.complete(one);
1252 <        f2 = new CompletableFuture<Integer>();
1252 >        f2 = new CompletableFuture<>();
1253          g = f.applyToEither(f2, inc);
1254          checkCompletedNormally(g, two);
1255      }
# Line 860 | Line 1259 | public class CompletableFutureTest exten
1259       * completion of either source
1260       */
1261      public void testApplyToEither2() {
1262 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1263 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1262 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1263 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1264          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1265          f.completeExceptionally(new CFException());
1266          f2.complete(one);
1267          checkCompletedWithWrappedCFException(g);
1268  
1269 <        f = new CompletableFuture<Integer>();
1270 <        f2 = new CompletableFuture<Integer>();
1269 >        f = new CompletableFuture<>();
1270 >        f2 = new CompletableFuture<>();
1271          f2.completeExceptionally(new CFException());
1272          g = f.applyToEither(f2, inc);
1273          checkCompletedWithWrappedCFException(g);
# Line 878 | Line 1277 | public class CompletableFutureTest exten
1277       * applyToEither result completes exceptionally if action does
1278       */
1279      public void testApplyToEither3() {
1280 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1281 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1280 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1281 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1282          FailingFunction r = new FailingFunction();
1283          CompletableFuture<Integer> g = f.applyToEither(f2, r);
1284          f2.complete(two);
# Line 890 | Line 1289 | public class CompletableFutureTest exten
1289       * applyToEither result completes exceptionally if either source cancelled
1290       */
1291      public void testApplyToEither4() {
1292 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1293 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1292 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1293 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1294          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1295          assertTrue(f.cancel(true));
1296          checkCompletedWithWrappedCancellationException(g);
1297 <        f = new CompletableFuture<Integer>();
1298 <        f2 = new CompletableFuture<Integer>();
1297 >        f = new CompletableFuture<>();
1298 >        f2 = new CompletableFuture<>();
1299          assertTrue(f2.cancel(true));
1300          checkCompletedWithWrappedCancellationException(g);
1301      }
# Line 906 | Line 1305 | public class CompletableFutureTest exten
1305       * of either source
1306       */
1307      public void testAcceptEither() {
1308 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1309 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1308 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1309 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1310          IncAction r = new IncAction();
1311          CompletableFuture<Void> g = f.acceptEither(f2, r);
1312          f.complete(one);
# Line 917 | Line 1316 | public class CompletableFutureTest exten
1316          assertEquals(r.value, 2);
1317  
1318          r = new IncAction();
1319 <        f = new CompletableFuture<Integer>();
1319 >        f = new CompletableFuture<>();
1320          f.complete(one);
1321 <        f2 = new CompletableFuture<Integer>();
1321 >        f2 = new CompletableFuture<>();
1322          g = f.acceptEither(f2, r);
1323          checkCompletedNormally(g, null);
1324          assertEquals(r.value, 2);
# Line 930 | Line 1329 | public class CompletableFutureTest exten
1329       * completion of either source
1330       */
1331      public void testAcceptEither2() {
1332 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1333 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1332 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1333 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1334          IncAction r = new IncAction();
1335          CompletableFuture<Void> g = f.acceptEither(f2, r);
1336          f.completeExceptionally(new CFException());
# Line 939 | Line 1338 | public class CompletableFutureTest exten
1338          checkCompletedWithWrappedCFException(g);
1339  
1340          r = new IncAction();
1341 <        f = new CompletableFuture<Integer>();
1342 <        f2 = new CompletableFuture<Integer>();
1341 >        f = new CompletableFuture<>();
1342 >        f2 = new CompletableFuture<>();
1343          f2.completeExceptionally(new CFException());
1344          g = f.acceptEither(f2, r);
1345          checkCompletedWithWrappedCFException(g);
# Line 950 | Line 1349 | public class CompletableFutureTest exten
1349       * acceptEither result completes exceptionally if action does
1350       */
1351      public void testAcceptEither3() {
1352 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1353 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1352 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1353 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1354          FailingConsumer r = new FailingConsumer();
1355          CompletableFuture<Void> g = f.acceptEither(f2, r);
1356          f2.complete(two);
# Line 962 | Line 1361 | public class CompletableFutureTest exten
1361       * acceptEither result completes exceptionally if either source cancelled
1362       */
1363      public void testAcceptEither4() {
1364 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1365 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1364 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1365 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1366          IncAction r = new IncAction();
1367          CompletableFuture<Void> g = f.acceptEither(f2, r);
1368          assertTrue(f.cancel(true));
1369          checkCompletedWithWrappedCancellationException(g);
1370 <        f = new CompletableFuture<Integer>();
1371 <        f2 = new CompletableFuture<Integer>();
1370 >        f = new CompletableFuture<>();
1371 >        f2 = new CompletableFuture<>();
1372          assertTrue(f2.cancel(true));
1373          checkCompletedWithWrappedCancellationException(g);
1374      }
1375  
977
1376      /**
1377       * runAfterEither result completes normally after normal completion
1378       * of either source
1379       */
1380      public void testRunAfterEither() {
1381 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1382 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1381 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1382 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1383          Noop r = new Noop();
1384          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1385          f.complete(one);
# Line 991 | Line 1389 | public class CompletableFutureTest exten
1389          assertTrue(r.ran);
1390  
1391          r = new Noop();
1392 <        f = new CompletableFuture<Integer>();
1392 >        f = new CompletableFuture<>();
1393          f.complete(one);
1394 <        f2 = new CompletableFuture<Integer>();
1394 >        f2 = new CompletableFuture<>();
1395          g = f.runAfterEither(f2, r);
1396          checkCompletedNormally(g, null);
1397          assertTrue(r.ran);
# Line 1004 | Line 1402 | public class CompletableFutureTest exten
1402       * completion of either source
1403       */
1404      public void testRunAfterEither2() {
1405 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1406 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1405 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1406 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1407          Noop r = new Noop();
1408          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1409          f.completeExceptionally(new CFException());
# Line 1013 | Line 1411 | public class CompletableFutureTest exten
1411          checkCompletedWithWrappedCFException(g);
1412  
1413          r = new Noop();
1414 <        f = new CompletableFuture<Integer>();
1415 <        f2 = new CompletableFuture<Integer>();
1414 >        f = new CompletableFuture<>();
1415 >        f2 = new CompletableFuture<>();
1416          f2.completeExceptionally(new CFException());
1417          g = f.runAfterEither(f2, r);
1418          checkCompletedWithWrappedCFException(g);
# Line 1024 | Line 1422 | public class CompletableFutureTest exten
1422       * runAfterEither result completes exceptionally if action does
1423       */
1424      public void testRunAfterEither3() {
1425 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1426 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1425 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1426 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1427          FailingNoop r = new FailingNoop();
1428          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1429          f2.complete(two);
# Line 1036 | Line 1434 | public class CompletableFutureTest exten
1434       * runAfterEither result completes exceptionally if either source cancelled
1435       */
1436      public void testRunAfterEither4() {
1437 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1438 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1437 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1438 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1439          Noop r = new Noop();
1440          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1441          assertTrue(f.cancel(true));
1442          checkCompletedWithWrappedCancellationException(g);
1443 <        f = new CompletableFuture<Integer>();
1444 <        f2 = new CompletableFuture<Integer>();
1443 >        f = new CompletableFuture<>();
1444 >        f2 = new CompletableFuture<>();
1445          assertTrue(f2.cancel(true));
1446          checkCompletedWithWrappedCancellationException(g);
1447      }
# Line 1052 | Line 1450 | public class CompletableFutureTest exten
1450       * thenCompose result completes normally after normal completion of source
1451       */
1452      public void testThenCompose() {
1453 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1454 <        CompletableFutureInc r = new CompletableFutureInc();
1455 <        CompletableFuture<Integer> g = f.thenCompose(r);
1453 >        CompletableFuture<Integer> f, g;
1454 >        CompletableFutureInc r;
1455 >
1456 >        f = new CompletableFuture<>();
1457 >        g = f.thenCompose(r = new CompletableFutureInc());
1458 >        f.complete(one);
1459 >        checkCompletedNormally(g, two);
1460 >        assertTrue(r.ran);
1461 >
1462 >        f = new CompletableFuture<>();
1463          f.complete(one);
1464 +        g = f.thenCompose(r = new CompletableFutureInc());
1465          checkCompletedNormally(g, two);
1466 +        assertTrue(r.ran);
1467      }
1468  
1469      /**
# Line 1064 | Line 1471 | public class CompletableFutureTest exten
1471       * completion of source
1472       */
1473      public void testThenCompose2() {
1474 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1475 <        CompletableFutureInc r = new CompletableFutureInc();
1476 <        CompletableFuture<Integer> g = f.thenCompose(r);
1474 >        CompletableFuture<Integer> f, g;
1475 >        CompletableFutureInc r;
1476 >
1477 >        f = new CompletableFuture<>();
1478 >        g = f.thenCompose(r = new CompletableFutureInc());
1479 >        f.completeExceptionally(new CFException());
1480 >        checkCompletedWithWrappedCFException(g);
1481 >
1482 >        f = new CompletableFuture<>();
1483          f.completeExceptionally(new CFException());
1484 +        g = f.thenCompose(r = new CompletableFutureInc());
1485          checkCompletedWithWrappedCFException(g);
1486      }
1487  
# Line 1075 | Line 1489 | public class CompletableFutureTest exten
1489       * thenCompose result completes exceptionally if action does
1490       */
1491      public void testThenCompose3() {
1492 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1493 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
1494 <        CompletableFuture<Integer> g = f.thenCompose(r);
1492 >        CompletableFuture<Integer> f, g;
1493 >        FailingCompletableFutureFunction r;
1494 >
1495 >        f = new CompletableFuture<>();
1496 >        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1497 >        f.complete(one);
1498 >        checkCompletedWithWrappedCFException(g);
1499 >
1500 >        f = new CompletableFuture<>();
1501          f.complete(one);
1502 +        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1503          checkCompletedWithWrappedCFException(g);
1504      }
1505  
# Line 1086 | Line 1507 | public class CompletableFutureTest exten
1507       * thenCompose result completes exceptionally if source cancelled
1508       */
1509      public void testThenCompose4() {
1510 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1511 <        CompletableFutureInc r = new CompletableFutureInc();
1512 <        CompletableFuture<Integer> g = f.thenCompose(r);
1510 >        CompletableFuture<Integer> f, g;
1511 >        CompletableFutureInc r;
1512 >
1513 >        f = new CompletableFuture<>();
1514 >        g = f.thenCompose(r = new CompletableFutureInc());
1515          assertTrue(f.cancel(true));
1516          checkCompletedWithWrappedCancellationException(g);
1094    }
1517  
1518 +        f = new CompletableFuture<>();
1519 +        assertTrue(f.cancel(true));
1520 +        g = f.thenCompose(r = new CompletableFutureInc());
1521 +        checkCompletedWithWrappedCancellationException(g);
1522 +    }
1523  
1524      // asyncs
1525  
# Line 1100 | Line 1527 | public class CompletableFutureTest exten
1527       * thenRunAsync result completes normally after normal completion of source
1528       */
1529      public void testThenRunAsync() {
1530 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1530 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1531          Noop r = new Noop();
1532          CompletableFuture<Void> g = f.thenRunAsync(r);
1533          f.complete(null);
1534          checkCompletedNormally(g, null);
1535  
1536          // reordered version
1537 <        f = new CompletableFuture<Integer>();
1537 >        f = new CompletableFuture<>();
1538          f.complete(null);
1539          r = new Noop();
1540          g = f.thenRunAsync(r);
# Line 1119 | Line 1546 | public class CompletableFutureTest exten
1546       * completion of source
1547       */
1548      public void testThenRunAsync2() {
1549 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1549 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1550          Noop r = new Noop();
1551          CompletableFuture<Void> g = f.thenRunAsync(r);
1552          f.completeExceptionally(new CFException());
1553          try {
1554              g.join();
1555              shouldThrow();
1556 <        } catch(Exception ok) {
1130 <        }
1556 >        } catch (CompletionException success) {}
1557          checkCompletedWithWrappedCFException(g);
1558      }
1559  
# Line 1135 | Line 1561 | public class CompletableFutureTest exten
1561       * thenRunAsync result completes exceptionally if action does
1562       */
1563      public void testThenRunAsync3() {
1564 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1564 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1565          FailingNoop r = new FailingNoop();
1566          CompletableFuture<Void> g = f.thenRunAsync(r);
1567          f.complete(null);
1568          checkCompletedWithWrappedCFException(g);
1569      }
1570 <        
1570 >
1571      /**
1572       * thenRunAsync result completes exceptionally if source cancelled
1573       */
1574      public void testThenRunAsync4() {
1575 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1575 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1576          Noop r = new Noop();
1577          CompletableFuture<Void> g = f.thenRunAsync(r);
1578          assertTrue(f.cancel(true));
# Line 1157 | Line 1583 | public class CompletableFutureTest exten
1583       * thenApplyAsync result completes normally after normal completion of source
1584       */
1585      public void testThenApplyAsync() {
1586 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1586 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1587          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1588          f.complete(one);
1589          checkCompletedNormally(g, two);
# Line 1168 | Line 1594 | public class CompletableFutureTest exten
1594       * completion of source
1595       */
1596      public void testThenApplyAsync2() {
1597 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1597 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1598          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1599          f.completeExceptionally(new CFException());
1600          checkCompletedWithWrappedCFException(g);
# Line 1178 | Line 1604 | public class CompletableFutureTest exten
1604       * thenApplyAsync result completes exceptionally if action does
1605       */
1606      public void testThenApplyAsync3() {
1607 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1607 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1608          FailingFunction r = new FailingFunction();
1609          CompletableFuture<Integer> g = f.thenApplyAsync(r);
1610          f.complete(null);
1611          checkCompletedWithWrappedCFException(g);
1612      }
1613 <        
1613 >
1614      /**
1615       * thenApplyAsync result completes exceptionally if source cancelled
1616       */
1617      public void testThenApplyAsync4() {
1618 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1618 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1619          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1620          assertTrue(f.cancel(true));
1621          checkCompletedWithWrappedCancellationException(g);
# Line 1200 | Line 1626 | public class CompletableFutureTest exten
1626       * completion of source
1627       */
1628      public void testThenAcceptAsync() {
1629 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1629 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1630          IncAction r = new IncAction();
1631          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1632          f.complete(one);
# Line 1213 | Line 1639 | public class CompletableFutureTest exten
1639       * completion of source
1640       */
1641      public void testThenAcceptAsync2() {
1642 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1642 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1643          IncAction r = new IncAction();
1644          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1645          f.completeExceptionally(new CFException());
# Line 1224 | Line 1650 | public class CompletableFutureTest exten
1650       * thenAcceptAsync result completes exceptionally if action does
1651       */
1652      public void testThenAcceptAsync3() {
1653 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1653 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1654          FailingConsumer r = new FailingConsumer();
1655          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1656          f.complete(null);
1657          checkCompletedWithWrappedCFException(g);
1658      }
1659 <        
1659 >
1660      /**
1661       * thenAcceptAsync result completes exceptionally if source cancelled
1662       */
1663      public void testThenAcceptAsync4() {
1664 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1664 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1665          IncAction r = new IncAction();
1666          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1667          assertTrue(f.cancel(true));
1668          checkCompletedWithWrappedCancellationException(g);
1669      }
1670 +
1671      /**
1672       * thenCombineAsync result completes normally after normal
1673       * completion of sources
1674       */
1675      public void testThenCombineAsync() {
1676 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1677 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1678 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1679 <        f.complete(one);
1680 <        checkIncomplete(g);
1681 <        f2.complete(two);
1682 <        checkCompletedNormally(g, three);
1676 >        CompletableFuture<Integer> f, g, h;
1677 >
1678 >        f = new CompletableFuture<>();
1679 >        g = new CompletableFuture<>();
1680 >        h = f.thenCombineAsync(g, subtract);
1681 >        f.complete(3);
1682 >        checkIncomplete(h);
1683 >        g.complete(1);
1684 >        checkCompletedNormally(h, 2);
1685 >
1686 >        f = new CompletableFuture<>();
1687 >        g = new CompletableFuture<>();
1688 >        h = f.thenCombineAsync(g, subtract);
1689 >        g.complete(1);
1690 >        checkIncomplete(h);
1691 >        f.complete(3);
1692 >        checkCompletedNormally(h, 2);
1693 >
1694 >        f = new CompletableFuture<>();
1695 >        g = new CompletableFuture<>();
1696 >        g.complete(1);
1697 >        f.complete(3);
1698 >        h = f.thenCombineAsync(g, subtract);
1699 >        checkCompletedNormally(h, 2);
1700      }
1701  
1702      /**
1703       * thenCombineAsync result completes exceptionally after exceptional
1704 <     * completion of source
1704 >     * completion of either source
1705       */
1706      public void testThenCombineAsync2() {
1707 <        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);
1707 >        CompletableFuture<Integer> f, g, h;
1708  
1709 <        f = new CompletableFuture<Integer>();
1710 <        f2 = new CompletableFuture<Integer>();
1711 <        g = f.thenCombineAsync(f2, add);
1712 <        f.complete(one);
1713 <        f2.completeExceptionally(new CFException());
1714 <        checkCompletedWithWrappedCFException(g);
1709 >        f = new CompletableFuture<>();
1710 >        g = new CompletableFuture<>();
1711 >        h = f.thenCombineAsync(g, subtract);
1712 >        f.completeExceptionally(new CFException());
1713 >        checkIncomplete(h);
1714 >        g.complete(1);
1715 >        checkCompletedWithWrappedCFException(h);
1716 >
1717 >        f = new CompletableFuture<>();
1718 >        g = new CompletableFuture<>();
1719 >        h = f.thenCombineAsync(g, subtract);
1720 >        g.completeExceptionally(new CFException());
1721 >        checkIncomplete(h);
1722 >        f.complete(3);
1723 >        checkCompletedWithWrappedCFException(h);
1724 >
1725 >        f = new CompletableFuture<>();
1726 >        g = new CompletableFuture<>();
1727 >        g.completeExceptionally(new CFException());
1728 >        f.complete(3);
1729 >        h = f.thenCombineAsync(g, subtract);
1730 >        checkCompletedWithWrappedCFException(h);
1731      }
1732  
1733      /**
1734       * thenCombineAsync result completes exceptionally if action does
1735       */
1736      public void testThenCombineAsync3() {
1737 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1738 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1737 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1738 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1739          FailingBiFunction r = new FailingBiFunction();
1740          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r);
1741          f.complete(one);
1742          checkIncomplete(g);
1743 +        assertFalse(r.ran);
1744          f2.complete(two);
1745          checkCompletedWithWrappedCFException(g);
1746 +        assertTrue(r.ran);
1747      }
1748 <        
1748 >
1749      /**
1750       * thenCombineAsync result completes exceptionally if either source cancelled
1751       */
1752      public void testThenCombineAsync4() {
1753 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1754 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1755 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1756 <        assertTrue(f.cancel(true));
1757 <        f2.complete(two);
1758 <        checkCompletedWithWrappedCancellationException(g);
1759 <        
1760 <        f = new CompletableFuture<Integer>();
1761 <        f2 = new CompletableFuture<Integer>();
1762 <        g = f.thenCombineAsync(f2, add);
1763 <        f.complete(one);
1764 <        assertTrue(f2.cancel(true));
1765 <        checkCompletedWithWrappedCancellationException(g);
1753 >        CompletableFuture<Integer> f, g, h;
1754 >
1755 >        f = new CompletableFuture<>();
1756 >        g = new CompletableFuture<>();
1757 >        h = f.thenCombineAsync(g, subtract);
1758 >        assertTrue(f.cancel(true));
1759 >        checkIncomplete(h);
1760 >        g.complete(1);
1761 >        checkCompletedWithWrappedCancellationException(h);
1762 >
1763 >        f = new CompletableFuture<>();
1764 >        g = new CompletableFuture<>();
1765 >        h = f.thenCombineAsync(g, subtract);
1766 >        assertTrue(g.cancel(true));
1767 >        checkIncomplete(h);
1768 >        f.complete(3);
1769 >        checkCompletedWithWrappedCancellationException(h);
1770 >
1771 >        f = new CompletableFuture<>();
1772 >        g = new CompletableFuture<>();
1773 >        g.complete(3);
1774 >        assertTrue(f.cancel(true));
1775 >        h = f.thenCombineAsync(g, subtract);
1776 >        checkCompletedWithWrappedCancellationException(h);
1777 >
1778 >        f = new CompletableFuture<>();
1779 >        g = new CompletableFuture<>();
1780 >        f.complete(3);
1781 >        assertTrue(g.cancel(true));
1782 >        h = f.thenCombineAsync(g, subtract);
1783 >        checkCompletedWithWrappedCancellationException(h);
1784      }
1785  
1786      /**
# Line 1313 | Line 1788 | public class CompletableFutureTest exten
1788       * completion of sources
1789       */
1790      public void testThenAcceptBothAsync() {
1791 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1792 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1793 <        AddAction r = new AddAction();
1794 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1795 <        f.complete(one);
1796 <        checkIncomplete(g);
1797 <        f2.complete(two);
1798 <        checkCompletedNormally(g, null);
1799 <        assertEquals(r.value, 3);
1791 >        CompletableFuture<Integer> f, g;
1792 >        CompletableFuture<Void> h;
1793 >        SubtractAction r;
1794 >
1795 >        f = new CompletableFuture<>();
1796 >        g = new CompletableFuture<>();
1797 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1798 >        f.complete(3);
1799 >        checkIncomplete(h);
1800 >        g.complete(1);
1801 >        checkCompletedNormally(h, null);
1802 >        assertEquals(r.value, 2);
1803 >
1804 >        f = new CompletableFuture<>();
1805 >        g = new CompletableFuture<>();
1806 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1807 >        g.complete(1);
1808 >        checkIncomplete(h);
1809 >        f.complete(3);
1810 >        checkCompletedNormally(h, null);
1811 >        assertEquals(r.value, 2);
1812 >
1813 >        f = new CompletableFuture<>();
1814 >        g = new CompletableFuture<>();
1815 >        g.complete(1);
1816 >        f.complete(3);
1817 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1818 >        checkCompletedNormally(h, null);
1819 >        assertEquals(r.value, 2);
1820      }
1821  
1822      /**
# Line 1329 | Line 1824 | public class CompletableFutureTest exten
1824       * completion of source
1825       */
1826      public void testThenAcceptBothAsync2() {
1827 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1828 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1829 <        AddAction r = new AddAction();
1830 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1831 <        f.completeExceptionally(new CFException());
1832 <        f2.complete(two);
1833 <        checkCompletedWithWrappedCFException(g);
1834 <
1835 <        r = new AddAction();
1836 <        f = new CompletableFuture<Integer>();
1837 <        f2 = new CompletableFuture<Integer>();
1838 <        g = f.thenAcceptBothAsync(f2, r);
1839 <        f.complete(one);
1840 <        f2.completeExceptionally(new CFException());
1841 <        checkCompletedWithWrappedCFException(g);
1827 >        CompletableFuture<Integer> f, g;
1828 >        CompletableFuture<Void> h;
1829 >        SubtractAction r;
1830 >
1831 >        f = new CompletableFuture<>();
1832 >        g = new CompletableFuture<>();
1833 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1834 >        f.completeExceptionally(new CFException());
1835 >        checkIncomplete(h);
1836 >        g.complete(1);
1837 >        checkCompletedWithWrappedCFException(h);
1838 >
1839 >        f = new CompletableFuture<>();
1840 >        g = new CompletableFuture<>();
1841 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1842 >        g.completeExceptionally(new CFException());
1843 >        checkIncomplete(h);
1844 >        f.complete(3);
1845 >        checkCompletedWithWrappedCFException(h);
1846 >
1847 >        f = new CompletableFuture<>();
1848 >        g = new CompletableFuture<>();
1849 >        f.complete(3);
1850 >        g.completeExceptionally(new CFException());
1851 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1852 >        checkCompletedWithWrappedCFException(h);
1853 >
1854 >        f = new CompletableFuture<>();
1855 >        g = new CompletableFuture<>();
1856 >        f.completeExceptionally(new CFException());
1857 >        g.complete(3);
1858 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1859 >        checkCompletedWithWrappedCFException(h);
1860      }
1861  
1862      /**
1863       * thenAcceptBothAsync result completes exceptionally if action does
1864       */
1865      public void testThenAcceptBothAsync3() {
1866 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1867 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1868 <        FailingBiConsumer r = new FailingBiConsumer();
1869 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);      
1870 <        f.complete(one);
1871 <        checkIncomplete(g);
1872 <        f2.complete(two);
1873 <        checkCompletedWithWrappedCFException(g);
1866 >        CompletableFuture<Integer> f, g;
1867 >        CompletableFuture<Void> h;
1868 >        FailingBiConsumer r;
1869 >
1870 >        f = new CompletableFuture<>();
1871 >        g = new CompletableFuture<>();
1872 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1873 >        f.complete(3);
1874 >        checkIncomplete(h);
1875 >        g.complete(1);
1876 >        checkCompletedWithWrappedCFException(h);
1877 >
1878 >        f = new CompletableFuture<>();
1879 >        g = new CompletableFuture<>();
1880 >        f.complete(3);
1881 >        g.complete(1);
1882 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1883 >        checkCompletedWithWrappedCFException(h);
1884      }
1885 <        
1885 >
1886      /**
1887       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1888       */
1889      public void testThenAcceptBothAsync4() {
1890 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1891 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1892 <        AddAction r = new AddAction();
1893 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1894 <        assertTrue(f.cancel(true));
1895 <        f2.complete(two);
1896 <        checkCompletedWithWrappedCancellationException(g);
1897 <        
1898 <        r = new AddAction();
1899 <        f = new CompletableFuture<Integer>();
1900 <        f2 = new CompletableFuture<Integer>();
1901 <        g = f.thenAcceptBothAsync(f2, r);
1902 <        f.complete(one);
1903 <        assertTrue(f2.cancel(true));
1904 <        checkCompletedWithWrappedCancellationException(g);
1890 >        CompletableFuture<Integer> f, g;
1891 >        CompletableFuture<Void> h;
1892 >        SubtractAction r;
1893 >
1894 >        f = new CompletableFuture<>();
1895 >        g = new CompletableFuture<>();
1896 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1897 >        assertTrue(f.cancel(true));
1898 >        checkIncomplete(h);
1899 >        g.complete(1);
1900 >        checkCompletedWithWrappedCancellationException(h);
1901 >
1902 >        f = new CompletableFuture<>();
1903 >        g = new CompletableFuture<>();
1904 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1905 >        assertTrue(g.cancel(true));
1906 >        checkIncomplete(h);
1907 >        f.complete(3);
1908 >        checkCompletedWithWrappedCancellationException(h);
1909 >
1910 >        f = new CompletableFuture<>();
1911 >        g = new CompletableFuture<>();
1912 >        f.complete(3);
1913 >        assertTrue(g.cancel(true));
1914 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1915 >        checkCompletedWithWrappedCancellationException(h);
1916 >
1917 >        f = new CompletableFuture<>();
1918 >        g = new CompletableFuture<>();
1919 >        assertTrue(f.cancel(true));
1920 >        g.complete(3);
1921 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1922 >        checkCompletedWithWrappedCancellationException(h);
1923      }
1924  
1925      /**
# Line 1386 | Line 1927 | public class CompletableFutureTest exten
1927       * completion of sources
1928       */
1929      public void testRunAfterBothAsync() {
1930 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1931 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1930 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1931 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1932          Noop r = new Noop();
1933          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1934          f.complete(one);
# Line 1402 | Line 1943 | public class CompletableFutureTest exten
1943       * completion of source
1944       */
1945      public void testRunAfterBothAsync2() {
1946 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1947 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1946 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1947 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1948          Noop r = new Noop();
1949          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1950          f.completeExceptionally(new CFException());
# Line 1411 | Line 1952 | public class CompletableFutureTest exten
1952          checkCompletedWithWrappedCFException(g);
1953  
1954          r = new Noop();
1955 <        f = new CompletableFuture<Integer>();
1956 <        f2 = new CompletableFuture<Integer>();
1955 >        f = new CompletableFuture<>();
1956 >        f2 = new CompletableFuture<>();
1957          g = f.runAfterBothAsync(f2, r);
1958          f.complete(one);
1959          f2.completeExceptionally(new CFException());
# Line 1423 | Line 1964 | public class CompletableFutureTest exten
1964       * runAfterBothAsync result completes exceptionally if action does
1965       */
1966      public void testRunAfterBothAsync3() {
1967 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1968 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1967 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1968 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1969          FailingNoop r = new FailingNoop();
1970 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);      
1970 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1971          f.complete(one);
1972          checkIncomplete(g);
1973          f2.complete(two);
1974          checkCompletedWithWrappedCFException(g);
1975      }
1976 <        
1976 >
1977      /**
1978       * runAfterBothAsync result completes exceptionally if either source cancelled
1979       */
1980      public void testRunAfterBothAsync4() {
1981 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1982 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1981 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1982 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1983          Noop r = new Noop();
1984          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1985          assertTrue(f.cancel(true));
1986          f2.complete(two);
1987          checkCompletedWithWrappedCancellationException(g);
1988 <        
1988 >
1989          r = new Noop();
1990 <        f = new CompletableFuture<Integer>();
1991 <        f2 = new CompletableFuture<Integer>();
1990 >        f = new CompletableFuture<>();
1991 >        f2 = new CompletableFuture<>();
1992          g = f.runAfterBothAsync(f2, r);
1993          f.complete(one);
1994          assertTrue(f2.cancel(true));
# Line 1459 | Line 2000 | public class CompletableFutureTest exten
2000       * completion of sources
2001       */
2002      public void testApplyToEitherAsync() {
2003 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2004 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2003 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2004 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2005          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2006          f.complete(one);
2007          checkCompletedNormally(g, two);
2008  
2009 <        f = new CompletableFuture<Integer>();
2009 >        f = new CompletableFuture<>();
2010          f.complete(one);
2011 <        f2 = new CompletableFuture<Integer>();
2011 >        f2 = new CompletableFuture<>();
2012          g = f.applyToEitherAsync(f2, inc);
2013          checkCompletedNormally(g, two);
2014      }
# Line 1477 | Line 2018 | public class CompletableFutureTest exten
2018       * completion of source
2019       */
2020      public void testApplyToEitherAsync2() {
2021 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2022 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2021 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2022 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2023          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2024          f.completeExceptionally(new CFException());
2025          checkCompletedWithWrappedCFException(g);
2026  
2027 <        f = new CompletableFuture<Integer>();
2028 <        f2 = new CompletableFuture<Integer>();
2027 >        f = new CompletableFuture<>();
2028 >        f2 = new CompletableFuture<>();
2029          f2.completeExceptionally(new CFException());
2030          g = f.applyToEitherAsync(f2, inc);
2031          f.complete(one);
# Line 1495 | Line 2036 | public class CompletableFutureTest exten
2036       * applyToEitherAsync result completes exceptionally if action does
2037       */
2038      public void testApplyToEitherAsync3() {
2039 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2040 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2039 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2040 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2041          FailingFunction r = new FailingFunction();
2042 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);      
2042 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
2043          f.complete(one);
2044          checkCompletedWithWrappedCFException(g);
2045      }
2046 <        
2046 >
2047      /**
2048       * applyToEitherAsync result completes exceptionally if either source cancelled
2049       */
2050      public void testApplyToEitherAsync4() {
2051 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2052 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2051 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2052 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2053          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2054          assertTrue(f.cancel(true));
2055          checkCompletedWithWrappedCancellationException(g);
2056 <        
2057 <        f = new CompletableFuture<Integer>();
2058 <        f2 = new CompletableFuture<Integer>();
2056 >
2057 >        f = new CompletableFuture<>();
2058 >        f2 = new CompletableFuture<>();
2059          assertTrue(f2.cancel(true));
2060          g = f.applyToEitherAsync(f2, inc);
2061          checkCompletedWithWrappedCancellationException(g);
# Line 1525 | Line 2066 | public class CompletableFutureTest exten
2066       * completion of sources
2067       */
2068      public void testAcceptEitherAsync() {
2069 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2070 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2069 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2070 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2071          IncAction r = new IncAction();
2072          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2073          f.complete(one);
# Line 1534 | Line 2075 | public class CompletableFutureTest exten
2075          assertEquals(r.value, 2);
2076  
2077          r = new IncAction();
2078 <        f = new CompletableFuture<Integer>();
2078 >        f = new CompletableFuture<>();
2079          f.complete(one);
2080 <        f2 = new CompletableFuture<Integer>();
2080 >        f2 = new CompletableFuture<>();
2081          g = f.acceptEitherAsync(f2, r);
2082          checkCompletedNormally(g, null);
2083          assertEquals(r.value, 2);
# Line 1547 | Line 2088 | public class CompletableFutureTest exten
2088       * completion of source
2089       */
2090      public void testAcceptEitherAsync2() {
2091 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2092 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2091 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2092 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2093          IncAction r = new IncAction();
2094          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2095          f.completeExceptionally(new CFException());
2096          checkCompletedWithWrappedCFException(g);
2097  
2098          r = new IncAction();
2099 <        f = new CompletableFuture<Integer>();
2100 <        f2 = new CompletableFuture<Integer>();
2099 >        f = new CompletableFuture<>();
2100 >        f2 = new CompletableFuture<>();
2101          f2.completeExceptionally(new CFException());
2102          g = f.acceptEitherAsync(f2, r);
2103          f.complete(one);
# Line 1567 | Line 2108 | public class CompletableFutureTest exten
2108       * acceptEitherAsync result completes exceptionally if action does
2109       */
2110      public void testAcceptEitherAsync3() {
2111 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2112 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2111 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2112 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2113          FailingConsumer r = new FailingConsumer();
2114 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);      
2114 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2115          f.complete(one);
2116          checkCompletedWithWrappedCFException(g);
2117      }
2118 <        
2118 >
2119      /**
2120       * acceptEitherAsync result completes exceptionally if either
2121       * source cancelled
2122       */
2123      public void testAcceptEitherAsync4() {
2124 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2125 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2124 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2125 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2126          IncAction r = new IncAction();
2127          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2128          assertTrue(f.cancel(true));
2129          checkCompletedWithWrappedCancellationException(g);
2130 <        
2130 >
2131          r = new IncAction();
2132 <        f = new CompletableFuture<Integer>();
2133 <        f2 = new CompletableFuture<Integer>();
2132 >        f = new CompletableFuture<>();
2133 >        f2 = new CompletableFuture<>();
2134          assertTrue(f2.cancel(true));
2135          g = f.acceptEitherAsync(f2, r);
2136          checkCompletedWithWrappedCancellationException(g);
# Line 1600 | Line 2141 | public class CompletableFutureTest exten
2141       * completion of sources
2142       */
2143      public void testRunAfterEitherAsync() {
2144 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2145 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2144 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2145 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2146          Noop r = new Noop();
2147          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2148          f.complete(one);
# Line 1609 | Line 2150 | public class CompletableFutureTest exten
2150          assertTrue(r.ran);
2151  
2152          r = new Noop();
2153 <        f = new CompletableFuture<Integer>();
2153 >        f = new CompletableFuture<>();
2154          f.complete(one);
2155 <        f2 = new CompletableFuture<Integer>();
2155 >        f2 = new CompletableFuture<>();
2156          g = f.runAfterEitherAsync(f2, r);
2157          checkCompletedNormally(g, null);
2158          assertTrue(r.ran);
# Line 1622 | Line 2163 | public class CompletableFutureTest exten
2163       * completion of source
2164       */
2165      public void testRunAfterEitherAsync2() {
2166 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2167 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2166 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2167 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2168          Noop r = new Noop();
2169          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2170          f.completeExceptionally(new CFException());
2171          checkCompletedWithWrappedCFException(g);
2172  
2173          r = new Noop();
2174 <        f = new CompletableFuture<Integer>();
2175 <        f2 = new CompletableFuture<Integer>();
2174 >        f = new CompletableFuture<>();
2175 >        f2 = new CompletableFuture<>();
2176          f2.completeExceptionally(new CFException());
2177          g = f.runAfterEitherAsync(f2, r);
2178          f.complete(one);
# Line 1642 | Line 2183 | public class CompletableFutureTest exten
2183       * runAfterEitherAsync result completes exceptionally if action does
2184       */
2185      public void testRunAfterEitherAsync3() {
2186 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2187 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2186 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2187 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2188          FailingNoop r = new FailingNoop();
2189 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);      
2189 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2190          f.complete(one);
2191          checkCompletedWithWrappedCFException(g);
2192      }
2193 <        
2193 >
2194      /**
2195       * runAfterEitherAsync result completes exceptionally if either
2196       * source cancelled
2197       */
2198      public void testRunAfterEitherAsync4() {
2199 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2200 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2199 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2200 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2201          Noop r = new Noop();
2202          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2203          assertTrue(f.cancel(true));
2204          checkCompletedWithWrappedCancellationException(g);
2205 <        
2205 >
2206          r = new Noop();
2207 <        f = new CompletableFuture<Integer>();
2208 <        f2 = new CompletableFuture<Integer>();
2207 >        f = new CompletableFuture<>();
2208 >        f2 = new CompletableFuture<>();
2209          assertTrue(f2.cancel(true));
2210          g = f.runAfterEitherAsync(f2, r);
2211          checkCompletedWithWrappedCancellationException(g);
2212      }
2213  
2214      /**
2215 <     * thenCompse result completes normally after normal completion of source
2215 >     * thenComposeAsync result completes normally after normal
2216 >     * completion of source
2217       */
2218      public void testThenComposeAsync() {
2219 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2220 <        CompletableFutureInc r = new CompletableFutureInc();
2221 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2219 >        CompletableFuture<Integer> f, g;
2220 >        CompletableFutureInc r;
2221 >
2222 >        f = new CompletableFuture<>();
2223 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2224          f.complete(one);
2225          checkCompletedNormally(g, two);
2226 +
2227 +        f = new CompletableFuture<>();
2228 +        f.complete(one);
2229 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2230 +        checkCompletedNormally(g, two);
2231      }
2232  
2233      /**
2234 <     * thenComposeAsync result completes exceptionally after exceptional
2235 <     * completion of source
2234 >     * thenComposeAsync result completes exceptionally after
2235 >     * exceptional completion of source
2236       */
2237      public void testThenComposeAsync2() {
2238 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2239 <        CompletableFutureInc r = new CompletableFutureInc();
2240 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2238 >        CompletableFuture<Integer> f, g;
2239 >        CompletableFutureInc r;
2240 >
2241 >        f = new CompletableFuture<>();
2242 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2243          f.completeExceptionally(new CFException());
2244          checkCompletedWithWrappedCFException(g);
2245 +        assertFalse(r.ran);
2246 +
2247 +        f = new CompletableFuture<>();
2248 +        f.completeExceptionally(new CFException());
2249 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2250 +        checkCompletedWithWrappedCFException(g);
2251 +        assertFalse(r.ran);
2252      }
2253  
2254      /**
2255       * thenComposeAsync result completes exceptionally if action does
2256       */
2257      public void testThenComposeAsync3() {
2258 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2259 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2260 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2258 >        CompletableFuture<Integer> f, g;
2259 >        FailingCompletableFutureFunction r;
2260 >
2261 >        f = new CompletableFuture<>();
2262 >        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2263          f.complete(one);
2264          checkCompletedWithWrappedCFException(g);
2265 +
2266 +        f = new CompletableFuture<>();
2267 +        f.complete(one);
2268 +        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2269 +        checkCompletedWithWrappedCFException(g);
2270      }
2271  
2272      /**
2273       * thenComposeAsync result completes exceptionally if source cancelled
2274       */
2275      public void testThenComposeAsync4() {
2276 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2277 <        CompletableFutureInc r = new CompletableFutureInc();
2278 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2276 >        CompletableFuture<Integer> f, g;
2277 >        CompletableFutureInc r;
2278 >
2279 >        f = new CompletableFuture<>();
2280 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2281          assertTrue(f.cancel(true));
2282          checkCompletedWithWrappedCancellationException(g);
1716    }
2283  
2284 +        f = new CompletableFuture<>();
2285 +        assertTrue(f.cancel(true));
2286 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2287 +        checkCompletedWithWrappedCancellationException(g);
2288 +    }
2289  
2290 <    // aaync with explicit executors
2290 >    // async with explicit executors
2291  
2292      /**
2293       * thenRunAsync result completes normally after normal completion of source
2294       */
2295      public void testThenRunAsyncE() {
2296 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2296 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2297          Noop r = new Noop();
2298          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2299          f.complete(null);
2300          checkCompletedNormally(g, null);
2301  
2302          // reordered version
2303 <        f = new CompletableFuture<Integer>();
2303 >        f = new CompletableFuture<>();
2304          f.complete(null);
2305          r = new Noop();
2306          g = f.thenRunAsync(r, new ThreadExecutor());
# Line 1741 | Line 2312 | public class CompletableFutureTest exten
2312       * completion of source
2313       */
2314      public void testThenRunAsync2E() {
2315 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2315 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2316          Noop r = new Noop();
2317          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2318          f.completeExceptionally(new CFException());
2319          try {
2320              g.join();
2321              shouldThrow();
2322 <        } catch(Exception ok) {
1752 <        }
2322 >        } catch (CompletionException success) {}
2323          checkCompletedWithWrappedCFException(g);
2324      }
2325  
# Line 1757 | Line 2327 | public class CompletableFutureTest exten
2327       * thenRunAsync result completes exceptionally if action does
2328       */
2329      public void testThenRunAsync3E() {
2330 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2330 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2331          FailingNoop r = new FailingNoop();
2332          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2333          f.complete(null);
2334          checkCompletedWithWrappedCFException(g);
2335      }
2336 <        
2336 >
2337      /**
2338       * thenRunAsync result completes exceptionally if source cancelled
2339       */
2340      public void testThenRunAsync4E() {
2341 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2341 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2342          Noop r = new Noop();
2343          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2344          assertTrue(f.cancel(true));
# Line 1779 | Line 2349 | public class CompletableFutureTest exten
2349       * thenApplyAsync result completes normally after normal completion of source
2350       */
2351      public void testThenApplyAsyncE() {
2352 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2352 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2353          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2354          f.complete(one);
2355          checkCompletedNormally(g, two);
# Line 1790 | Line 2360 | public class CompletableFutureTest exten
2360       * completion of source
2361       */
2362      public void testThenApplyAsync2E() {
2363 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2363 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2364          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2365          f.completeExceptionally(new CFException());
2366          checkCompletedWithWrappedCFException(g);
# Line 1800 | Line 2370 | public class CompletableFutureTest exten
2370       * thenApplyAsync result completes exceptionally if action does
2371       */
2372      public void testThenApplyAsync3E() {
2373 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2373 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2374          FailingFunction r = new FailingFunction();
2375          CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
2376          f.complete(null);
2377          checkCompletedWithWrappedCFException(g);
2378      }
2379 <        
2379 >
2380      /**
2381       * thenApplyAsync result completes exceptionally if source cancelled
2382       */
2383      public void testThenApplyAsync4E() {
2384 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2384 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2385          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2386          assertTrue(f.cancel(true));
2387          checkCompletedWithWrappedCancellationException(g);
# Line 1822 | Line 2392 | public class CompletableFutureTest exten
2392       * completion of source
2393       */
2394      public void testThenAcceptAsyncE() {
2395 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2395 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2396          IncAction r = new IncAction();
2397          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2398          f.complete(one);
# Line 1835 | Line 2405 | public class CompletableFutureTest exten
2405       * completion of source
2406       */
2407      public void testThenAcceptAsync2E() {
2408 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2408 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2409          IncAction r = new IncAction();
2410          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2411          f.completeExceptionally(new CFException());
# Line 1846 | Line 2416 | public class CompletableFutureTest exten
2416       * thenAcceptAsync result completes exceptionally if action does
2417       */
2418      public void testThenAcceptAsync3E() {
2419 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2419 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2420          FailingConsumer r = new FailingConsumer();
2421          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2422          f.complete(null);
2423          checkCompletedWithWrappedCFException(g);
2424      }
2425 <        
2425 >
2426      /**
2427       * thenAcceptAsync result completes exceptionally if source cancelled
2428       */
2429      public void testThenAcceptAsync4E() {
2430 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2430 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2431          IncAction r = new IncAction();
2432          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2433          assertTrue(f.cancel(true));
2434          checkCompletedWithWrappedCancellationException(g);
2435      }
2436 +
2437      /**
2438       * thenCombineAsync result completes normally after normal
2439       * completion of sources
2440       */
2441      public void testThenCombineAsyncE() {
2442 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2443 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2444 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2445 <        f.complete(one);
2446 <        checkIncomplete(g);
2447 <        f2.complete(two);
2448 <        checkCompletedNormally(g, three);
2442 >        CompletableFuture<Integer> f, g, h;
2443 >        ThreadExecutor e = new ThreadExecutor();
2444 >        int count = 0;
2445 >
2446 >        f = new CompletableFuture<>();
2447 >        g = new CompletableFuture<>();
2448 >        h = f.thenCombineAsync(g, subtract, e);
2449 >        f.complete(3);
2450 >        checkIncomplete(h);
2451 >        g.complete(1);
2452 >        checkCompletedNormally(h, 2);
2453 >        assertEquals(++count, e.count.get());
2454 >
2455 >        f = new CompletableFuture<>();
2456 >        g = new CompletableFuture<>();
2457 >        h = f.thenCombineAsync(g, subtract, e);
2458 >        g.complete(1);
2459 >        checkIncomplete(h);
2460 >        f.complete(3);
2461 >        checkCompletedNormally(h, 2);
2462 >        assertEquals(++count, e.count.get());
2463 >
2464 >        f = new CompletableFuture<>();
2465 >        g = new CompletableFuture<>();
2466 >        g.complete(1);
2467 >        f.complete(3);
2468 >        h = f.thenCombineAsync(g, subtract, e);
2469 >        checkCompletedNormally(h, 2);
2470 >        assertEquals(++count, e.count.get());
2471      }
2472  
2473      /**
2474       * thenCombineAsync result completes exceptionally after exceptional
2475 <     * completion of source
2475 >     * completion of either source
2476       */
2477      public void testThenCombineAsync2E() {
2478 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2479 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2480 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2481 <        f.completeExceptionally(new CFException());
2482 <        f2.complete(two);
2483 <        checkCompletedWithWrappedCFException(g);
2478 >        CompletableFuture<Integer> f, g, h;
2479 >        ThreadExecutor e = new ThreadExecutor();
2480 >        int count = 0;
2481 >
2482 >        f = new CompletableFuture<>();
2483 >        g = new CompletableFuture<>();
2484 >        h = f.thenCombineAsync(g, subtract, e);
2485 >        f.completeExceptionally(new CFException());
2486 >        checkIncomplete(h);
2487 >        g.complete(1);
2488 >        checkCompletedWithWrappedCFException(h);
2489 >
2490 >        f = new CompletableFuture<>();
2491 >        g = new CompletableFuture<>();
2492 >        h = f.thenCombineAsync(g, subtract, e);
2493 >        g.completeExceptionally(new CFException());
2494 >        checkIncomplete(h);
2495 >        f.complete(3);
2496 >        checkCompletedWithWrappedCFException(h);
2497 >
2498 >        f = new CompletableFuture<>();
2499 >        g = new CompletableFuture<>();
2500 >        g.completeExceptionally(new CFException());
2501 >        h = f.thenCombineAsync(g, subtract, e);
2502 >        checkIncomplete(h);
2503 >        f.complete(3);
2504 >        checkCompletedWithWrappedCFException(h);
2505  
2506 <        f = new CompletableFuture<Integer>();
1893 <        f2 = new CompletableFuture<Integer>();
1894 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1895 <        f.complete(one);
1896 <        f2.completeExceptionally(new CFException());
1897 <        checkCompletedWithWrappedCFException(g);
2506 >        assertEquals(0, e.count.get());
2507      }
2508  
2509      /**
2510       * thenCombineAsync result completes exceptionally if action does
2511       */
2512      public void testThenCombineAsync3E() {
2513 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2514 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2513 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2514 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2515          FailingBiFunction r = new FailingBiFunction();
2516          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor());
2517          f.complete(one);
2518          checkIncomplete(g);
2519 +        assertFalse(r.ran);
2520          f2.complete(two);
2521          checkCompletedWithWrappedCFException(g);
2522 +        assertTrue(r.ran);
2523      }
2524 <        
2524 >
2525      /**
2526       * thenCombineAsync result completes exceptionally if either source cancelled
2527       */
2528      public void testThenCombineAsync4E() {
2529 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2530 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2531 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2532 <        assertTrue(f.cancel(true));
2533 <        f2.complete(two);
2534 <        checkCompletedWithWrappedCancellationException(g);
2535 <        
2536 <        f = new CompletableFuture<Integer>();
2537 <        f2 = new CompletableFuture<Integer>();
2538 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2539 <        f.complete(one);
2540 <        assertTrue(f2.cancel(true));
2541 <        checkCompletedWithWrappedCancellationException(g);
2529 >        CompletableFuture<Integer> f, g, h;
2530 >        ThreadExecutor e = new ThreadExecutor();
2531 >
2532 >        f = new CompletableFuture<>();
2533 >        g = new CompletableFuture<>();
2534 >        h = f.thenCombineAsync(g, subtract, e);
2535 >        assertTrue(f.cancel(true));
2536 >        checkIncomplete(h);
2537 >        g.complete(1);
2538 >        checkCompletedWithWrappedCancellationException(h);
2539 >
2540 >        f = new CompletableFuture<>();
2541 >        g = new CompletableFuture<>();
2542 >        h = f.thenCombineAsync(g, subtract, e);
2543 >        assertTrue(g.cancel(true));
2544 >        checkIncomplete(h);
2545 >        f.complete(3);
2546 >        checkCompletedWithWrappedCancellationException(h);
2547 >
2548 >        f = new CompletableFuture<>();
2549 >        g = new CompletableFuture<>();
2550 >        assertTrue(g.cancel(true));
2551 >        h = f.thenCombineAsync(g, subtract, e);
2552 >        checkIncomplete(h);
2553 >        f.complete(3);
2554 >        checkCompletedWithWrappedCancellationException(h);
2555 >
2556 >        f = new CompletableFuture<>();
2557 >        g = new CompletableFuture<>();
2558 >        assertTrue(f.cancel(true));
2559 >        assertTrue(g.cancel(true));
2560 >        h = f.thenCombineAsync(g, subtract, e);
2561 >        checkCompletedWithWrappedCancellationException(h);
2562 >
2563 >        assertEquals(0, e.count.get());
2564      }
2565  
2566      /**
# Line 1935 | Line 2568 | public class CompletableFutureTest exten
2568       * completion of sources
2569       */
2570      public void testThenAcceptBothAsyncE() {
2571 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2572 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2573 <        AddAction r = new AddAction();
2574 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2575 <        f.complete(one);
2576 <        checkIncomplete(g);
2577 <        f2.complete(two);
2578 <        checkCompletedNormally(g, null);
2579 <        assertEquals(r.value, 3);
2571 >        CompletableFuture<Integer> f, g;
2572 >        CompletableFuture<Void> h;
2573 >        SubtractAction r;
2574 >        ThreadExecutor e = new ThreadExecutor();
2575 >
2576 >        f = new CompletableFuture<>();
2577 >        g = new CompletableFuture<>();
2578 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2579 >        f.complete(3);
2580 >        checkIncomplete(h);
2581 >        g.complete(1);
2582 >        checkCompletedNormally(h, null);
2583 >        assertEquals(r.value, 2);
2584 >
2585 >        f = new CompletableFuture<>();
2586 >        g = new CompletableFuture<>();
2587 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2588 >        g.complete(1);
2589 >        checkIncomplete(h);
2590 >        f.complete(3);
2591 >        checkCompletedNormally(h, null);
2592 >        assertEquals(r.value, 2);
2593 >
2594 >        f = new CompletableFuture<>();
2595 >        g = new CompletableFuture<>();
2596 >        g.complete(1);
2597 >        f.complete(3);
2598 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2599 >        checkCompletedNormally(h, null);
2600 >        assertEquals(r.value, 2);
2601 >
2602 >        assertEquals(3, e.count.get());
2603      }
2604  
2605      /**
# Line 1951 | Line 2607 | public class CompletableFutureTest exten
2607       * completion of source
2608       */
2609      public void testThenAcceptBothAsync2E() {
2610 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2611 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2612 <        AddAction r = new AddAction();
2613 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2614 <        f.completeExceptionally(new CFException());
2615 <        f2.complete(two);
2616 <        checkCompletedWithWrappedCFException(g);
2610 >        CompletableFuture<Integer> f, g;
2611 >        CompletableFuture<Void> h;
2612 >        SubtractAction r;
2613 >        ThreadExecutor e = new ThreadExecutor();
2614 >
2615 >        f = new CompletableFuture<>();
2616 >        g = new CompletableFuture<>();
2617 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2618 >        f.completeExceptionally(new CFException());
2619 >        checkIncomplete(h);
2620 >        g.complete(1);
2621 >        checkCompletedWithWrappedCFException(h);
2622 >
2623 >        f = new CompletableFuture<>();
2624 >        g = new CompletableFuture<>();
2625 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2626 >        g.completeExceptionally(new CFException());
2627 >        checkIncomplete(h);
2628 >        f.complete(3);
2629 >        checkCompletedWithWrappedCFException(h);
2630 >
2631 >        f = new CompletableFuture<>();
2632 >        g = new CompletableFuture<>();
2633 >        f.complete(3);
2634 >        g.completeExceptionally(new CFException());
2635 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2636 >        checkCompletedWithWrappedCFException(h);
2637 >
2638 >        f = new CompletableFuture<>();
2639 >        g = new CompletableFuture<>();
2640 >        f.completeExceptionally(new CFException());
2641 >        g.complete(3);
2642 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2643 >        checkCompletedWithWrappedCFException(h);
2644  
2645 <        r = new AddAction();
1963 <        f = new CompletableFuture<Integer>();
1964 <        f2 = new CompletableFuture<Integer>();
1965 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1966 <        f.complete(one);
1967 <        f2.completeExceptionally(new CFException());
1968 <        checkCompletedWithWrappedCFException(g);
2645 >        assertEquals(0, e.count.get());
2646      }
2647  
2648      /**
2649       * thenAcceptBothAsync result completes exceptionally if action does
2650       */
2651      public void testThenAcceptBothAsync3E() {
2652 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2653 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2654 <        FailingBiConsumer r = new FailingBiConsumer();
2655 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());      
2656 <        f.complete(one);
2657 <        checkIncomplete(g);
2658 <        f2.complete(two);
2659 <        checkCompletedWithWrappedCFException(g);
2652 >        CompletableFuture<Integer> f, g;
2653 >        CompletableFuture<Void> h;
2654 >        FailingBiConsumer r;
2655 >        ThreadExecutor e = new ThreadExecutor();
2656 >
2657 >        f = new CompletableFuture<>();
2658 >        g = new CompletableFuture<>();
2659 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2660 >        f.complete(3);
2661 >        checkIncomplete(h);
2662 >        g.complete(1);
2663 >        checkCompletedWithWrappedCFException(h);
2664 >
2665 >        f = new CompletableFuture<>();
2666 >        g = new CompletableFuture<>();
2667 >        f.complete(3);
2668 >        g.complete(1);
2669 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2670 >        checkCompletedWithWrappedCFException(h);
2671 >
2672 >        assertEquals(2, e.count.get());
2673      }
2674 <        
2674 >
2675      /**
2676       * thenAcceptBothAsync result completes exceptionally if either source cancelled
2677       */
2678      public void testThenAcceptBothAsync4E() {
2679 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2680 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2681 <        AddAction r = new AddAction();
2682 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2683 <        assertTrue(f.cancel(true));
2684 <        f2.complete(two);
2685 <        checkCompletedWithWrappedCancellationException(g);
2686 <        
2687 <        r = new AddAction();
2688 <        f = new CompletableFuture<Integer>();
2689 <        f2 = new CompletableFuture<Integer>();
2690 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2691 <        f.complete(one);
2692 <        assertTrue(f2.cancel(true));
2693 <        checkCompletedWithWrappedCancellationException(g);
2679 >        CompletableFuture<Integer> f, g;
2680 >        CompletableFuture<Void> h;
2681 >        SubtractAction r;
2682 >        ThreadExecutor e = new ThreadExecutor();
2683 >
2684 >        f = new CompletableFuture<>();
2685 >        g = new CompletableFuture<>();
2686 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2687 >        assertTrue(f.cancel(true));
2688 >        checkIncomplete(h);
2689 >        g.complete(1);
2690 >        checkCompletedWithWrappedCancellationException(h);
2691 >
2692 >        f = new CompletableFuture<>();
2693 >        g = new CompletableFuture<>();
2694 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2695 >        assertTrue(g.cancel(true));
2696 >        checkIncomplete(h);
2697 >        f.complete(3);
2698 >        checkCompletedWithWrappedCancellationException(h);
2699 >
2700 >        f = new CompletableFuture<>();
2701 >        g = new CompletableFuture<>();
2702 >        f.complete(3);
2703 >        assertTrue(g.cancel(true));
2704 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2705 >        checkCompletedWithWrappedCancellationException(h);
2706 >
2707 >        f = new CompletableFuture<>();
2708 >        g = new CompletableFuture<>();
2709 >        assertTrue(f.cancel(true));
2710 >        g.complete(3);
2711 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2712 >        checkCompletedWithWrappedCancellationException(h);
2713 >
2714 >        assertEquals(0, e.count.get());
2715      }
2716  
2717      /**
# Line 2008 | Line 2719 | public class CompletableFutureTest exten
2719       * completion of sources
2720       */
2721      public void testRunAfterBothAsyncE() {
2722 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2723 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2722 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2723 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2724          Noop r = new Noop();
2725          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2726          f.complete(one);
# Line 2024 | Line 2735 | public class CompletableFutureTest exten
2735       * completion of source
2736       */
2737      public void testRunAfterBothAsync2E() {
2738 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2739 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2738 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2739 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2740          Noop r = new Noop();
2741          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2742          f.completeExceptionally(new CFException());
# Line 2033 | Line 2744 | public class CompletableFutureTest exten
2744          checkCompletedWithWrappedCFException(g);
2745  
2746          r = new Noop();
2747 <        f = new CompletableFuture<Integer>();
2748 <        f2 = new CompletableFuture<Integer>();
2747 >        f = new CompletableFuture<>();
2748 >        f2 = new CompletableFuture<>();
2749          g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2750          f.complete(one);
2751          f2.completeExceptionally(new CFException());
# Line 2045 | Line 2756 | public class CompletableFutureTest exten
2756       * runAfterBothAsync result completes exceptionally if action does
2757       */
2758      public void testRunAfterBothAsync3E() {
2759 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2760 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2759 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2760 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2761          FailingNoop r = new FailingNoop();
2762 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());      
2762 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2763          f.complete(one);
2764          checkIncomplete(g);
2765          f2.complete(two);
2766          checkCompletedWithWrappedCFException(g);
2767      }
2768 <        
2768 >
2769      /**
2770       * runAfterBothAsync result completes exceptionally if either source cancelled
2771       */
2772      public void testRunAfterBothAsync4E() {
2773 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2774 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2773 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2774 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2775          Noop r = new Noop();
2776          CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2777          assertTrue(f.cancel(true));
2778          f2.complete(two);
2779          checkCompletedWithWrappedCancellationException(g);
2780 <        
2780 >
2781          r = new Noop();
2782 <        f = new CompletableFuture<Integer>();
2783 <        f2 = new CompletableFuture<Integer>();
2782 >        f = new CompletableFuture<>();
2783 >        f2 = new CompletableFuture<>();
2784          g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2785          f.complete(one);
2786          assertTrue(f2.cancel(true));
# Line 2081 | Line 2792 | public class CompletableFutureTest exten
2792       * completion of sources
2793       */
2794      public void testApplyToEitherAsyncE() {
2795 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2796 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2795 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2796 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2797          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2798          f.complete(one);
2799          checkCompletedNormally(g, two);
2800  
2801 <        f = new CompletableFuture<Integer>();
2801 >        f = new CompletableFuture<>();
2802          f.complete(one);
2803 <        f2 = new CompletableFuture<Integer>();
2803 >        f2 = new CompletableFuture<>();
2804          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2805          checkCompletedNormally(g, two);
2806      }
# Line 2099 | Line 2810 | public class CompletableFutureTest exten
2810       * completion of source
2811       */
2812      public void testApplyToEitherAsync2E() {
2813 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2814 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2813 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2814 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2815          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2816          f.completeExceptionally(new CFException());
2817          checkCompletedWithWrappedCFException(g);
2818  
2819 <        f = new CompletableFuture<Integer>();
2820 <        f2 = new CompletableFuture<Integer>();
2819 >        f = new CompletableFuture<>();
2820 >        f2 = new CompletableFuture<>();
2821          f2.completeExceptionally(new CFException());
2822          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2823          f.complete(one);
# Line 2117 | Line 2828 | public class CompletableFutureTest exten
2828       * applyToEitherAsync result completes exceptionally if action does
2829       */
2830      public void testApplyToEitherAsync3E() {
2831 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2832 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2831 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2832 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2833          FailingFunction r = new FailingFunction();
2834 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());      
2834 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2835          f.complete(one);
2836          checkCompletedWithWrappedCFException(g);
2837      }
2838 <        
2838 >
2839      /**
2840       * applyToEitherAsync result completes exceptionally if either source cancelled
2841       */
2842      public void testApplyToEitherAsync4E() {
2843 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2844 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2843 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2844 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2845          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2846          assertTrue(f.cancel(true));
2847          checkCompletedWithWrappedCancellationException(g);
2848 <        
2849 <        f = new CompletableFuture<Integer>();
2850 <        f2 = new CompletableFuture<Integer>();
2848 >
2849 >        f = new CompletableFuture<>();
2850 >        f2 = new CompletableFuture<>();
2851          assertTrue(f2.cancel(true));
2852          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2853          checkCompletedWithWrappedCancellationException(g);
# Line 2147 | Line 2858 | public class CompletableFutureTest exten
2858       * completion of sources
2859       */
2860      public void testAcceptEitherAsyncE() {
2861 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2862 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2861 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2862 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2863          IncAction r = new IncAction();
2864          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2865          f.complete(one);
# Line 2156 | Line 2867 | public class CompletableFutureTest exten
2867          assertEquals(r.value, 2);
2868  
2869          r = new IncAction();
2870 <        f = new CompletableFuture<Integer>();
2870 >        f = new CompletableFuture<>();
2871          f.complete(one);
2872 <        f2 = new CompletableFuture<Integer>();
2872 >        f2 = new CompletableFuture<>();
2873          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2874          checkCompletedNormally(g, null);
2875          assertEquals(r.value, 2);
# Line 2169 | Line 2880 | public class CompletableFutureTest exten
2880       * completion of source
2881       */
2882      public void testAcceptEitherAsync2E() {
2883 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2884 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2883 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2884 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2885          IncAction r = new IncAction();
2886          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2887          f.completeExceptionally(new CFException());
2888          checkCompletedWithWrappedCFException(g);
2889  
2890          r = new IncAction();
2891 <        f = new CompletableFuture<Integer>();
2892 <        f2 = new CompletableFuture<Integer>();
2891 >        f = new CompletableFuture<>();
2892 >        f2 = new CompletableFuture<>();
2893          f2.completeExceptionally(new CFException());
2894          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2895          f.complete(one);
# Line 2189 | Line 2900 | public class CompletableFutureTest exten
2900       * acceptEitherAsync result completes exceptionally if action does
2901       */
2902      public void testAcceptEitherAsync3E() {
2903 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2904 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2903 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2904 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2905          FailingConsumer r = new FailingConsumer();
2906 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());      
2906 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2907          f.complete(one);
2908          checkCompletedWithWrappedCFException(g);
2909      }
2910 <        
2910 >
2911      /**
2912       * acceptEitherAsync result completes exceptionally if either
2913       * source cancelled
2914       */
2915      public void testAcceptEitherAsync4E() {
2916 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2917 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2916 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2917 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2918          IncAction r = new IncAction();
2919          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2920          assertTrue(f.cancel(true));
2921          checkCompletedWithWrappedCancellationException(g);
2922 <        
2922 >
2923          r = new IncAction();
2924 <        f = new CompletableFuture<Integer>();
2925 <        f2 = new CompletableFuture<Integer>();
2924 >        f = new CompletableFuture<>();
2925 >        f2 = new CompletableFuture<>();
2926          assertTrue(f2.cancel(true));
2927          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2928          checkCompletedWithWrappedCancellationException(g);
# Line 2222 | Line 2933 | public class CompletableFutureTest exten
2933       * completion of sources
2934       */
2935      public void testRunAfterEitherAsyncE() {
2936 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2937 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2936 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2937 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2938          Noop r = new Noop();
2939          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2940          f.complete(one);
# Line 2231 | Line 2942 | public class CompletableFutureTest exten
2942          assertTrue(r.ran);
2943  
2944          r = new Noop();
2945 <        f = new CompletableFuture<Integer>();
2945 >        f = new CompletableFuture<>();
2946          f.complete(one);
2947 <        f2 = new CompletableFuture<Integer>();
2947 >        f2 = new CompletableFuture<>();
2948          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2949          checkCompletedNormally(g, null);
2950          assertTrue(r.ran);
# Line 2244 | Line 2955 | public class CompletableFutureTest exten
2955       * completion of source
2956       */
2957      public void testRunAfterEitherAsync2E() {
2958 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2959 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2958 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2959 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2960          Noop r = new Noop();
2961          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2962          f.completeExceptionally(new CFException());
2963          checkCompletedWithWrappedCFException(g);
2964  
2965          r = new Noop();
2966 <        f = new CompletableFuture<Integer>();
2967 <        f2 = new CompletableFuture<Integer>();
2966 >        f = new CompletableFuture<>();
2967 >        f2 = new CompletableFuture<>();
2968          f2.completeExceptionally(new CFException());
2969          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2970          f.complete(one);
# Line 2264 | Line 2975 | public class CompletableFutureTest exten
2975       * runAfterEitherAsync result completes exceptionally if action does
2976       */
2977      public void testRunAfterEitherAsync3E() {
2978 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2979 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2978 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2979 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2980          FailingNoop r = new FailingNoop();
2981 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());      
2981 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2982          f.complete(one);
2983          checkCompletedWithWrappedCFException(g);
2984      }
2985 <        
2985 >
2986      /**
2987       * runAfterEitherAsync result completes exceptionally if either
2988       * source cancelled
2989       */
2990      public void testRunAfterEitherAsync4E() {
2991 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2992 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2991 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2992 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2993          Noop r = new Noop();
2994          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2995          assertTrue(f.cancel(true));
2996          checkCompletedWithWrappedCancellationException(g);
2997 <        
2997 >
2998          r = new Noop();
2999 <        f = new CompletableFuture<Integer>();
3000 <        f2 = new CompletableFuture<Integer>();
2999 >        f = new CompletableFuture<>();
3000 >        f2 = new CompletableFuture<>();
3001          assertTrue(f2.cancel(true));
3002          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
3003          checkCompletedWithWrappedCancellationException(g);
3004      }
3005  
3006      /**
3007 <     * thenCompse result completes normally after normal completion of source
3007 >     * thenComposeAsync result completes normally after normal
3008 >     * completion of source
3009       */
3010      public void testThenComposeAsyncE() {
3011 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
3011 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3012          CompletableFutureInc r = new CompletableFutureInc();
3013          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3014          f.complete(one);
# Line 2304 | Line 3016 | public class CompletableFutureTest exten
3016      }
3017  
3018      /**
3019 <     * thenComposeAsync result completes exceptionally after exceptional
3020 <     * completion of source
3019 >     * thenComposeAsync result completes exceptionally after
3020 >     * exceptional completion of source
3021       */
3022      public void testThenComposeAsync2E() {
3023 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
3023 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3024          CompletableFutureInc r = new CompletableFutureInc();
3025          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3026          f.completeExceptionally(new CFException());
# Line 2319 | Line 3031 | public class CompletableFutureTest exten
3031       * thenComposeAsync result completes exceptionally if action does
3032       */
3033      public void testThenComposeAsync3E() {
3034 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
3034 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3035          FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
3036          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3037          f.complete(one);
# Line 2330 | Line 3042 | public class CompletableFutureTest exten
3042       * thenComposeAsync result completes exceptionally if source cancelled
3043       */
3044      public void testThenComposeAsync4E() {
3045 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
3045 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3046          CompletableFutureInc r = new CompletableFutureInc();
3047          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3048          assertTrue(f.cancel(true));
3049          checkCompletedWithWrappedCancellationException(g);
3050      }
3051  
3052 <    // other static methods    
3052 >    // other static methods
3053  
3054      /**
3055       * allOf(no component futures) returns a future completed normally
3056       * with the value null
3057       */
3058      public void testAllOf_empty() throws Exception {
3059 <        CompletableFuture<?> f = CompletableFuture.allOf();
3059 >        CompletableFuture<Void> f = CompletableFuture.allOf();
3060          checkCompletedNormally(f, null);
3061      }
3062  
3063      /**
3064 <     * allOf returns a future completed when all components complete
3064 >     * allOf returns a future completed normally with the value null
3065 >     * when all components complete normally
3066       */
3067 <    public void testAllOf() throws Exception {
3067 >    public void testAllOf_normal() throws Exception {
3068          for (int k = 1; k < 20; ++k) {
3069 <            CompletableFuture[] fs = new CompletableFuture[k];
3070 <            for (int i = 0; i < k; ++i)
3071 <                fs[i] = new CompletableFuture<Integer>();
3072 <            CompletableFuture<?> f = CompletableFuture.allOf(fs);
3069 >            CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
3070 >            for (int i = 0; i < k; ++i)
3071 >                fs[i] = new CompletableFuture<>();
3072 >            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
3073              for (int i = 0; i < k; ++i) {
3074                  checkIncomplete(f);
3075 +                checkIncomplete(CompletableFuture.allOf(fs));
3076                  fs[i].complete(one);
3077              }
3078 <            assertTrue(f.isDone());
3079 <            assertFalse(f.isCancelled());
3078 >            checkCompletedNormally(f, null);
3079 >            checkCompletedNormally(CompletableFuture.allOf(fs), null);
3080          }
3081      }
3082  
# Line 2370 | Line 3084 | public class CompletableFutureTest exten
3084       * anyOf(no component futures) returns an incomplete future
3085       */
3086      public void testAnyOf_empty() throws Exception {
3087 <        CompletableFuture<?> f = CompletableFuture.anyOf();
3087 >        CompletableFuture<Object> f = CompletableFuture.anyOf();
3088          checkIncomplete(f);
3089      }
3090  
3091      /**
3092 <     * allOf returns a future completed when any components complete
3092 >     * anyOf returns a future completed normally with a value when
3093 >     * a component future does
3094       */
3095 <    public void testAnyOf() throws Exception {
3096 <        for (int k = 1; k < 20; ++k) {
3095 >    public void testAnyOf_normal() throws Exception {
3096 >        for (int k = 0; k < 10; ++k) {
3097              CompletableFuture[] fs = new CompletableFuture[k];
3098 <            for (int i = 0; i < k; ++i)
3099 <                fs[i] = new CompletableFuture<Integer>();
3100 <            CompletableFuture<?> f = CompletableFuture.anyOf(fs);
3098 >            for (int i = 0; i < k; ++i)
3099 >                fs[i] = new CompletableFuture<>();
3100 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
3101              checkIncomplete(f);
3102              for (int i = 0; i < k; ++i) {
3103                  fs[i].complete(one);
3104 <                assertTrue(f.isDone());
3104 >                checkCompletedNormally(f, one);
3105 >                checkCompletedNormally(CompletableFuture.anyOf(fs), one);
3106 >            }
3107 >        }
3108 >    }
3109 >
3110 >    /**
3111 >     * anyOf result completes exceptionally when any component does.
3112 >     */
3113 >    public void testAnyOf_exceptional() throws Exception {
3114 >        for (int k = 0; k < 10; ++k) {
3115 >            CompletableFuture[] fs = new CompletableFuture[k];
3116 >            for (int i = 0; i < k; ++i)
3117 >                fs[i] = new CompletableFuture<>();
3118 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
3119 >            checkIncomplete(f);
3120 >            for (int i = 0; i < k; ++i) {
3121 >                fs[i].completeExceptionally(new CFException());
3122 >                checkCompletedWithWrappedCFException(f);
3123 >                checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
3124              }
3125          }
3126      }
# Line 2395 | Line 3129 | public class CompletableFutureTest exten
3129       * Completion methods throw NullPointerException with null arguments
3130       */
3131      public void testNPE() {
3132 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
3133 <        CompletableFuture<Integer> g = new CompletableFuture<Integer>();
3134 <        CompletableFuture h;
3135 <        try { h = f.thenApply(null); } catch (NullPointerException ok) {}
3136 <        try { h = f.thenAccept(null); } catch (NullPointerException ok) {}
3137 <        try { h = f.thenRun(null); } catch (NullPointerException ok) {}
3138 <        try { h = f.thenCombine(g, null); } catch (NullPointerException ok) {}
3139 <        try { h = f.thenCombine(null, null); } catch (NullPointerException ok) {}
3140 <        try { h = f.applyToEither(g, null); } catch (NullPointerException ok) {}
3141 <        try { h = f.applyToEither(null, null); } catch (NullPointerException ok) {}
3142 <        try { h = f.thenAcceptBoth(g, null); } catch (NullPointerException ok) {}
3143 <        try { h = f.thenAcceptBoth(null, null); } catch (NullPointerException ok) {}
3144 <        try { h = f.runAfterEither(g, null); } catch (NullPointerException ok) {}
3145 <        try { h = f.runAfterEither(null, null); } catch (NullPointerException ok) {}
3146 <        try { h = f.runAfterBoth(g, null); } catch (NullPointerException ok) {}
3147 <        try { h = f.runAfterBoth(null, null); } catch (NullPointerException ok) {}
3148 <        try { h = f.exceptionally(null); } catch (NullPointerException ok) {}
3149 <        try { h = f.handle(null); } catch (NullPointerException ok) {}
3150 <        try { h = f.thenCompose(null); } catch (NullPointerException ok) {}
3151 <
3152 <        try { h = f.thenApplyAsync(null); } catch (NullPointerException ok) {}
3153 <        try { h = f.thenAcceptAsync(null); } catch (NullPointerException ok) {}
3154 <        try { h = f.thenRunAsync(null); } catch (NullPointerException ok) {}
3155 <        try { h = f.thenCombineAsync(g, null); } catch (NullPointerException ok) {}
3156 <        try { h = f.thenCombineAsync(null, null); } catch (NullPointerException ok) {}
3157 <        try { h = f.applyToEitherAsync(g, null); } catch (NullPointerException ok) {}
3158 <        try { h = f.applyToEitherAsync(null, null); } catch (NullPointerException ok) {}
3159 <        try { h = f.thenAcceptBothAsync(g, null); } catch (NullPointerException ok) {}
3160 <        try { h = f.thenAcceptBothAsync(null, null); } catch (NullPointerException ok) {}
3161 <        try { h = f.runAfterEitherAsync(g, null); } catch (NullPointerException ok) {}
3162 <        try { h = f.runAfterEitherAsync(null, null); } catch (NullPointerException ok) {}
3163 <        try { h = f.runAfterBothAsync(g, null); } catch (NullPointerException ok) {}
3164 <        try { h = f.runAfterBothAsync(null, null); } catch (NullPointerException ok) {}
3132 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3133 >        CompletableFuture<Integer> g = new CompletableFuture<>();
3134 >        CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null;
3135 >        CompletableFuture<?> h;
3136 >        ThreadExecutor exec = new ThreadExecutor();
3137 >
3138 >        Runnable[] throwingActions = {
3139 >            () -> CompletableFuture.supplyAsync(null),
3140 >            () -> CompletableFuture.supplyAsync(null, exec),
3141 >            () -> CompletableFuture.supplyAsync(supplyOne, null),
3142 >
3143 >            () -> CompletableFuture.runAsync(null),
3144 >            () -> CompletableFuture.runAsync(null, exec),
3145 >            () -> CompletableFuture.runAsync(() -> {}, null),
3146 >
3147 >            () -> f.completeExceptionally(null),
3148 >
3149 >            () -> f.thenApply(null),
3150 >            () -> f.thenApplyAsync(null),
3151 >            () -> f.thenApplyAsync((x) -> x, null),
3152 >            () -> f.thenApplyAsync(null, exec),
3153 >
3154 >            () -> f.thenAccept(null),
3155 >            () -> f.thenAcceptAsync(null),
3156 >            () -> f.thenAcceptAsync((x) -> {} , null),
3157 >            () -> f.thenAcceptAsync(null, exec),
3158 >
3159 >            () -> f.thenRun(null),
3160 >            () -> f.thenRunAsync(null),
3161 >            () -> f.thenRunAsync(() -> {} , null),
3162 >            () -> f.thenRunAsync(null, exec),
3163 >
3164 >            () -> f.thenCombine(g, null),
3165 >            () -> f.thenCombineAsync(g, null),
3166 >            () -> f.thenCombineAsync(g, null, exec),
3167 >            () -> f.thenCombine(nullFuture, (x, y) -> x),
3168 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x),
3169 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec),
3170 >            () -> f.thenCombineAsync(g, (x, y) -> x, null),
3171 >
3172 >            () -> f.thenAcceptBoth(g, null),
3173 >            () -> f.thenAcceptBothAsync(g, null),
3174 >            () -> f.thenAcceptBothAsync(g, null, exec),
3175 >            () -> f.thenAcceptBoth(nullFuture, (x, y) -> {}),
3176 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}),
3177 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec),
3178 >            () -> f.thenAcceptBothAsync(g, (x, y) -> {}, null),
3179 >
3180 >            () -> f.runAfterBoth(g, null),
3181 >            () -> f.runAfterBothAsync(g, null),
3182 >            () -> f.runAfterBothAsync(g, null, exec),
3183 >            () -> f.runAfterBoth(nullFuture, () -> {}),
3184 >            () -> f.runAfterBothAsync(nullFuture, () -> {}),
3185 >            () -> f.runAfterBothAsync(nullFuture, () -> {}, exec),
3186 >            () -> f.runAfterBothAsync(g, () -> {}, null),
3187 >
3188 >            () -> f.applyToEither(g, null),
3189 >            () -> f.applyToEitherAsync(g, null),
3190 >            () -> f.applyToEitherAsync(g, null, exec),
3191 >            () -> f.applyToEither(nullFuture, (x) -> x),
3192 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x),
3193 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x, exec),
3194 >            () -> f.applyToEitherAsync(g, (x) -> x, null),
3195 >
3196 >            () -> f.acceptEither(g, null),
3197 >            () -> f.acceptEitherAsync(g, null),
3198 >            () -> f.acceptEitherAsync(g, null, exec),
3199 >            () -> f.acceptEither(nullFuture, (x) -> {}),
3200 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}),
3201 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec),
3202 >            () -> f.acceptEitherAsync(g, (x) -> {}, null),
3203 >
3204 >            () -> f.runAfterEither(g, null),
3205 >            () -> f.runAfterEitherAsync(g, null),
3206 >            () -> f.runAfterEitherAsync(g, null, exec),
3207 >            () -> f.runAfterEither(nullFuture, () -> {}),
3208 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}),
3209 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}, exec),
3210 >            () -> f.runAfterEitherAsync(g, () -> {}, null),
3211 >
3212 >            () -> f.thenCompose(null),
3213 >            () -> f.thenComposeAsync(null),
3214 >            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
3215 >            () -> f.thenComposeAsync(null, exec),
3216 >
3217 >            () -> f.exceptionally(null),
3218 >
3219 >            () -> f.handle(null),
3220 >
3221 >            () -> CompletableFuture.allOf((CompletableFuture<?>)null),
3222 >            () -> CompletableFuture.allOf((CompletableFuture<?>[])null),
3223 >            () -> CompletableFuture.allOf(f, null),
3224 >            () -> CompletableFuture.allOf(null, f),
3225 >
3226 >            () -> CompletableFuture.anyOf((CompletableFuture<?>)null),
3227 >            () -> CompletableFuture.anyOf((CompletableFuture<?>[])null),
3228 >            () -> CompletableFuture.anyOf(f, null),
3229 >            () -> CompletableFuture.anyOf(null, f),
3230 >
3231 >            () -> f.obtrudeException(null),
3232 >        };
3233 >
3234 >        assertThrows(NullPointerException.class, throwingActions);
3235 >        assertEquals(0, exec.count.get());
3236 >    }
3237 >
3238 >    /**
3239 >     * toCompletableFuture returns this CompletableFuture.
3240 >     */
3241 >    public void testToCompletableFuture() {
3242 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3243 >        assertSame(f, f.toCompletableFuture());
3244 >    }
3245 >
3246 >    /**
3247 >     * whenComplete action executes on normal completion, propagating
3248 >     * source result.
3249 >     */
3250 >    public void testWhenComplete1() {
3251 >        final AtomicInteger a = new AtomicInteger();
3252 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3253 >        CompletableFuture<Integer> g =
3254 >            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3255 >        f.complete(three);
3256 >        checkCompletedNormally(f, three);
3257 >        checkCompletedNormally(g, three);
3258 >        assertEquals(a.get(), 1);
3259 >    }
3260 >
3261 >    /**
3262 >     * whenComplete action executes on exceptional completion, propagating
3263 >     * source result.
3264 >     */
3265 >    public void testWhenComplete2() {
3266 >        final AtomicInteger a = new AtomicInteger();
3267 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3268 >        CompletableFuture<Integer> g =
3269 >            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3270 >        f.completeExceptionally(new CFException());
3271 >        assertTrue(f.isCompletedExceptionally());
3272 >        assertTrue(g.isCompletedExceptionally());
3273 >        assertEquals(a.get(), 1);
3274 >    }
3275 >
3276 >    /**
3277 >     * If a whenComplete action throws an exception when triggered by
3278 >     * a normal completion, it completes exceptionally
3279 >     */
3280 >    public void testWhenComplete3() {
3281 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3282 >        CompletableFuture<Integer> g =
3283 >            f.whenComplete((Integer x, Throwable t) ->
3284 >                           { throw new CFException(); } );
3285 >        f.complete(three);
3286 >        checkCompletedNormally(f, three);
3287 >        assertTrue(g.isCompletedExceptionally());
3288 >        checkCompletedWithWrappedCFException(g);
3289 >    }
3290 >
3291 >    /**
3292 >     * whenCompleteAsync action executes on normal completion, propagating
3293 >     * source result.
3294 >     */
3295 >    public void testWhenCompleteAsync1() {
3296 >        final AtomicInteger a = new AtomicInteger();
3297 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3298 >        CompletableFuture<Integer> g =
3299 >            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3300 >        f.complete(three);
3301 >        checkCompletedNormally(f, three);
3302 >        checkCompletedNormally(g, three);
3303 >        assertEquals(a.get(), 1);
3304 >    }
3305 >
3306 >    /**
3307 >     * whenCompleteAsync action executes on exceptional completion, propagating
3308 >     * source result.
3309 >     */
3310 >    public void testWhenCompleteAsync2() {
3311 >        final AtomicInteger a = new AtomicInteger();
3312 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3313 >        CompletableFuture<Integer> g =
3314 >            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3315 >        f.completeExceptionally(new CFException());
3316 >        checkCompletedWithWrappedCFException(f);
3317 >        checkCompletedWithWrappedCFException(g);
3318 >    }
3319  
3320 +    /**
3321 +     * If a whenCompleteAsync action throws an exception when
3322 +     * triggered by a normal completion, it completes exceptionally
3323 +     */
3324 +    public void testWhenCompleteAsync3() {
3325 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3326 +        CompletableFuture<Integer> g =
3327 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3328 +                           { throw new CFException(); } );
3329 +        f.complete(three);
3330 +        checkCompletedNormally(f, three);
3331 +        checkCompletedWithWrappedCFException(g);
3332 +    }
3333 +
3334 +    /**
3335 +     * whenCompleteAsync action executes on normal completion, propagating
3336 +     * source result.
3337 +     */
3338 +    public void testWhenCompleteAsync1e() {
3339 +        final AtomicInteger a = new AtomicInteger();
3340 +        ThreadExecutor exec = new ThreadExecutor();
3341 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3342 +        CompletableFuture<Integer> g =
3343 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3344 +                                exec);
3345 +        f.complete(three);
3346 +        checkCompletedNormally(f, three);
3347 +        checkCompletedNormally(g, three);
3348 +        assertEquals(a.get(), 1);
3349 +    }
3350 +
3351 +    /**
3352 +     * whenCompleteAsync action executes on exceptional completion, propagating
3353 +     * source result.
3354 +     */
3355 +    public void testWhenCompleteAsync2e() {
3356 +        final AtomicInteger a = new AtomicInteger();
3357 +        ThreadExecutor exec = new ThreadExecutor();
3358 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3359 +        CompletableFuture<Integer> g =
3360 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3361 +                                exec);
3362 +        f.completeExceptionally(new CFException());
3363 +        checkCompletedWithWrappedCFException(f);
3364 +        checkCompletedWithWrappedCFException(g);
3365      }
3366  
3367 +    /**
3368 +     * If a whenCompleteAsync action throws an exception when triggered
3369 +     * by a normal completion, it completes exceptionally
3370 +     */
3371 +    public void testWhenCompleteAsync3e() {
3372 +        ThreadExecutor exec = new ThreadExecutor();
3373 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3374 +        CompletableFuture<Integer> g =
3375 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3376 +                                { throw new CFException(); },
3377 +                                exec);
3378 +        f.complete(three);
3379 +        checkCompletedNormally(f, three);
3380 +        checkCompletedWithWrappedCFException(g);
3381 +    }
3382 +
3383 +    /**
3384 +     * handleAsync action completes normally with function value on
3385 +     * either normal or exceptional completion of source
3386 +     */
3387 +    public void testHandleAsync() {
3388 +        CompletableFuture<Integer> f, g;
3389 +        IntegerHandler r;
3390 +
3391 +        f = new CompletableFuture<>();
3392 +        g = f.handleAsync(r = new IntegerHandler());
3393 +        assertFalse(r.ran);
3394 +        f.completeExceptionally(new CFException());
3395 +        checkCompletedWithWrappedCFException(f);
3396 +        checkCompletedNormally(g, three);
3397 +        assertTrue(r.ran);
3398 +
3399 +        f = new CompletableFuture<>();
3400 +        g = f.handleAsync(r = new IntegerHandler());
3401 +        assertFalse(r.ran);
3402 +        f.completeExceptionally(new CFException());
3403 +        checkCompletedWithWrappedCFException(f);
3404 +        checkCompletedNormally(g, three);
3405 +        assertTrue(r.ran);
3406 +
3407 +        f = new CompletableFuture<>();
3408 +        g = f.handleAsync(r = new IntegerHandler());
3409 +        assertFalse(r.ran);
3410 +        f.complete(one);
3411 +        checkCompletedNormally(f, one);
3412 +        checkCompletedNormally(g, two);
3413 +        assertTrue(r.ran);
3414 +
3415 +        f = new CompletableFuture<>();
3416 +        g = f.handleAsync(r = new IntegerHandler());
3417 +        assertFalse(r.ran);
3418 +        f.complete(one);
3419 +        checkCompletedNormally(f, one);
3420 +        checkCompletedNormally(g, two);
3421 +        assertTrue(r.ran);
3422 +    }
3423 +
3424 +    /**
3425 +     * handleAsync action with Executor completes normally with
3426 +     * function value on either normal or exceptional completion of
3427 +     * source
3428 +     */
3429 +    public void testHandleAsync2() {
3430 +        CompletableFuture<Integer> f, g;
3431 +        ThreadExecutor exec = new ThreadExecutor();
3432 +        IntegerHandler r;
3433 +
3434 +        f = new CompletableFuture<>();
3435 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3436 +        assertFalse(r.ran);
3437 +        f.completeExceptionally(new CFException());
3438 +        checkCompletedWithWrappedCFException(f);
3439 +        checkCompletedNormally(g, three);
3440 +        assertTrue(r.ran);
3441 +
3442 +        f = new CompletableFuture<>();
3443 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3444 +        assertFalse(r.ran);
3445 +        f.completeExceptionally(new CFException());
3446 +        checkCompletedWithWrappedCFException(f);
3447 +        checkCompletedNormally(g, three);
3448 +        assertTrue(r.ran);
3449 +
3450 +        f = new CompletableFuture<>();
3451 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3452 +        assertFalse(r.ran);
3453 +        f.complete(one);
3454 +        checkCompletedNormally(f, one);
3455 +        checkCompletedNormally(g, two);
3456 +        assertTrue(r.ran);
3457 +
3458 +        f = new CompletableFuture<>();
3459 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3460 +        assertFalse(r.ran);
3461 +        f.complete(one);
3462 +        checkCompletedNormally(f, one);
3463 +        checkCompletedNormally(g, two);
3464 +        assertTrue(r.ran);
3465 +    }
3466  
3467   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines