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 |
|
34 |
f = new CompletableFuture<String>(); |
35 |
assertTrue(f.toString().contains("[Not completed]")); |
36 |
|
37 |
f.complete("foo"); |
38 |
assertTrue(f.toString().contains("[Completed normally]")); |
39 |
|
40 |
f = new CompletableFuture<String>(); |
41 |
f.completeExceptionally(new IndexOutOfBoundsException()); |
42 |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
43 |
} |
44 |
} |