495 |
|
* thenRun result completes normally after normal completion of source |
496 |
|
*/ |
497 |
|
public void testThenRun() { |
498 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
499 |
< |
Noop r = new Noop(); |
500 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
498 |
> |
CompletableFuture<Integer> f; |
499 |
> |
CompletableFuture<Void> g; |
500 |
> |
Noop r; |
501 |
> |
|
502 |
> |
f = new CompletableFuture<>(); |
503 |
> |
g = f.thenRun(r = new Noop()); |
504 |
|
f.complete(null); |
505 |
|
checkCompletedNormally(g, null); |
506 |
< |
// reordered version |
506 |
> |
assertTrue(r.ran); |
507 |
> |
|
508 |
|
f = new CompletableFuture<>(); |
509 |
|
f.complete(null); |
510 |
< |
r = new Noop(); |
507 |
< |
g = f.thenRun(r); |
510 |
> |
g = f.thenRun(r = new Noop()); |
511 |
|
checkCompletedNormally(g, null); |
512 |
+ |
assertTrue(r.ran); |
513 |
|
} |
514 |
|
|
515 |
|
/** |
517 |
|
* completion of source |
518 |
|
*/ |
519 |
|
public void testThenRun2() { |
520 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
521 |
< |
Noop r = new Noop(); |
522 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
520 |
> |
CompletableFuture<Integer> f; |
521 |
> |
CompletableFuture<Void> g; |
522 |
> |
Noop r; |
523 |
> |
|
524 |
> |
f = new CompletableFuture<>(); |
525 |
> |
g = f.thenRun(r = new Noop()); |
526 |
|
f.completeExceptionally(new CFException()); |
527 |
|
checkCompletedWithWrappedCFException(g); |
528 |
+ |
assertFalse(r.ran); |
529 |
+ |
|
530 |
+ |
f = new CompletableFuture<>(); |
531 |
+ |
f.completeExceptionally(new CFException()); |
532 |
+ |
g = f.thenRun(r = new Noop()); |
533 |
+ |
checkCompletedWithWrappedCFException(g); |
534 |
+ |
assertFalse(r.ran); |
535 |
|
} |
536 |
|
|
537 |
|
/** |
538 |
|
* thenRun result completes exceptionally if action does |
539 |
|
*/ |
540 |
|
public void testThenRun3() { |
541 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
542 |
< |
FailingNoop r = new FailingNoop(); |
543 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
541 |
> |
CompletableFuture<Integer> f; |
542 |
> |
CompletableFuture<Void> g; |
543 |
> |
FailingNoop r; |
544 |
> |
|
545 |
> |
f = new CompletableFuture<>(); |
546 |
> |
g = f.thenRun(r = new FailingNoop()); |
547 |
|
f.complete(null); |
548 |
|
checkCompletedWithWrappedCFException(g); |
549 |
+ |
|
550 |
+ |
f = new CompletableFuture<>(); |
551 |
+ |
f.complete(null); |
552 |
+ |
g = f.thenRun(r = new FailingNoop()); |
553 |
+ |
checkCompletedWithWrappedCFException(g); |
554 |
|
} |
555 |
|
|
556 |
|
/** |
557 |
|
* thenRun result completes exceptionally if source cancelled |
558 |
|
*/ |
559 |
|
public void testThenRun4() { |
560 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
561 |
< |
Noop r = new Noop(); |
562 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
560 |
> |
CompletableFuture<Integer> f; |
561 |
> |
CompletableFuture<Void> g; |
562 |
> |
Noop r; |
563 |
> |
|
564 |
> |
f = new CompletableFuture<>(); |
565 |
> |
g = f.thenRun(r = new Noop()); |
566 |
> |
assertTrue(f.cancel(true)); |
567 |
> |
checkCompletedWithWrappedCancellationException(g); |
568 |
> |
|
569 |
> |
f = new CompletableFuture<>(); |
570 |
|
assertTrue(f.cancel(true)); |
571 |
+ |
g = f.thenRun(r = new Noop()); |
572 |
|
checkCompletedWithWrappedCancellationException(g); |
573 |
|
} |
574 |
|
|