1 |
jsr166 |
1.1 |
/* |
2 |
|
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
|
* Expert Group and released to the public domain, as explained at |
4 |
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
|
* Pat Fisher, Mike Judd. |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
import junit.framework.*; |
10 |
|
|
import java.util.concurrent.Callable; |
11 |
|
|
import java.util.concurrent.CancellationException; |
12 |
|
|
import java.util.concurrent.CountDownLatch; |
13 |
|
|
import java.util.concurrent.ExecutionException; |
14 |
|
|
import java.util.concurrent.Future; |
15 |
|
|
import java.util.concurrent.CompletableFuture; |
16 |
|
|
import java.util.concurrent.TimeoutException; |
17 |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
18 |
|
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
19 |
|
|
import static java.util.concurrent.TimeUnit.SECONDS; |
20 |
|
|
import java.util.*; |
21 |
|
|
|
22 |
|
|
public class CompletableFutureTest extends JSR166TestCase { |
23 |
|
|
|
24 |
|
|
public static void main(String[] args) { |
25 |
|
|
junit.textui.TestRunner.run(suite()); |
26 |
|
|
} |
27 |
|
|
public static Test suite() { |
28 |
|
|
return new TestSuite(CompletableFutureTest.class); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
public void testToString() { |
32 |
|
|
CompletableFuture<String> f; |
33 |
|
|
assertTrue(new CompletableFuture<String>().toString() |
34 |
|
|
.contains("[Not completed]")); |
35 |
|
|
f = new CompletableFuture<String>(); |
36 |
|
|
f.complete("foo"); |
37 |
|
|
assertTrue(f.toString().contains("[Completed normally]")); |
38 |
|
|
f = new CompletableFuture<String>(); |
39 |
|
|
f.completeExceptionally(new IndexOutOfBoundsException()); |
40 |
|
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
41 |
|
|
} |
42 |
|
|
} |