3577 |
|
* copy returns a CompletableFuture that is completed normally, |
3578 |
|
* with the same value, when source is. |
3579 |
|
*/ |
3580 |
< |
public void testCopy() { |
3580 |
> |
public void testCopy_normalCompletion() { |
3581 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
3582 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
3583 |
> |
{ |
3584 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3585 |
+ |
if (!createIncomplete) assertTrue(f.complete(v1)); |
3586 |
|
CompletableFuture<Integer> g = f.copy(); |
3587 |
< |
checkIncomplete(f); |
3588 |
< |
checkIncomplete(g); |
3589 |
< |
f.complete(1); |
3590 |
< |
checkCompletedNormally(f, 1); |
3591 |
< |
checkCompletedNormally(g, 1); |
3592 |
< |
} |
3587 |
> |
if (createIncomplete) { |
3588 |
> |
checkIncomplete(f); |
3589 |
> |
checkIncomplete(g); |
3590 |
> |
assertTrue(f.complete(v1)); |
3591 |
> |
} |
3592 |
> |
checkCompletedNormally(f, v1); |
3593 |
> |
checkCompletedNormally(g, v1); |
3594 |
> |
}} |
3595 |
|
|
3596 |
|
/** |
3597 |
|
* copy returns a CompletableFuture that is completed exceptionally |
3598 |
|
* when source is. |
3599 |
|
*/ |
3600 |
< |
public void testCopy2() { |
3600 |
> |
public void testCopy_exceptionalCompletion() { |
3601 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
3602 |
> |
{ |
3603 |
> |
CFException ex = new CFException(); |
3604 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3605 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
3606 |
|
CompletableFuture<Integer> g = f.copy(); |
3607 |
< |
checkIncomplete(f); |
3608 |
< |
checkIncomplete(g); |
3609 |
< |
CFException ex = new CFException(); |
3610 |
< |
f.completeExceptionally(ex); |
3607 |
> |
if (createIncomplete) { |
3608 |
> |
checkIncomplete(f); |
3609 |
> |
checkIncomplete(g); |
3610 |
> |
f.completeExceptionally(ex); |
3611 |
> |
} |
3612 |
|
checkCompletedExceptionally(f, ex); |
3613 |
|
checkCompletedWithWrappedException(g, ex); |
3614 |
+ |
}} |
3615 |
+ |
|
3616 |
+ |
/** |
3617 |
+ |
* Completion of a copy does not complete its source. |
3618 |
+ |
*/ |
3619 |
+ |
public void testCopy_oneWayPropagation() { |
3620 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3621 |
+ |
assertTrue(f.copy().complete(1)); |
3622 |
+ |
assertTrue(f.copy().complete(null)); |
3623 |
+ |
assertTrue(f.copy().cancel(true)); |
3624 |
+ |
assertTrue(f.copy().cancel(false)); |
3625 |
+ |
assertTrue(f.copy().completeExceptionally(new CFException())); |
3626 |
+ |
checkIncomplete(f); |
3627 |
|
} |
3628 |
|
|
3629 |
|
/** |