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.3 by jsr166, Sat Feb 9 19:33:08 2013 UTC vs.
Revision 1.4 by jsr166, Sun Feb 10 21:18:25 2013 UTC

# Line 1 | Line 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
2 > * Written by Doug Lea and Martin Buchholz with assistance from
3 > * members of JCP JSR-166 Expert Group and released to the public
4 > * domain, as explained at
5   * http://creativecommons.org/publicdomain/zero/1.0/
5 * Other contributors include Andrew Wright, Jeffrey Hayes,
6 * Pat Fisher, Mike Judd.
6   */
7  
8   import junit.framework.*;
# Line 28 | Line 27 | public class CompletableFutureTest exten
27          return new TestSuite(CompletableFutureTest.class);
28      }
29  
30 +    void checkIncomplete(CompletableFuture<?> f) {
31 +        assertFalse(f.isDone());
32 +        assertFalse(f.isCancelled());
33 +        assertTrue(f.toString().contains("[Not completed]"));
34 +        try {
35 +            assertNull(f.getNow(null));
36 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
37 +        try {
38 +            f.get(0L, SECONDS);
39 +            shouldThrow();
40 +        }
41 +        catch (TimeoutException success) {}
42 +        catch (Throwable fail) { threadUnexpectedException(fail); }
43 +    }
44 +
45 +    void checkCompletedNormally(CompletableFuture<?> f, Object value) {
46 +        assertTrue(f.isDone());
47 +        assertFalse(f.isCancelled());
48 +        assertTrue(f.toString().contains("[Completed normally]"));
49 +        try {
50 +            assertSame(value, f.join());
51 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
52 +        try {
53 +            assertSame(value, f.getNow(null));
54 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
55 +        try {
56 +            assertSame(value, f.get());
57 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
58 +        try {
59 +            assertSame(value, f.get(0L, SECONDS));
60 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
61 +    }
62 +
63      // XXXX Just a skeleton implementation for now.
64      public void testTODO() {
65          fail("Please add some real tests!");
# Line 46 | Line 78 | public class CompletableFutureTest exten
78          f.completeExceptionally(new IndexOutOfBoundsException());
79          assertTrue(f.toString().contains("[Completed exceptionally]"));
80      }
81 +
82 +    /**
83 +     * allOf(no component futures) returns a future completed normally
84 +     * with the value null
85 +     */
86 +    public void testAllOf_empty() throws Exception {
87 +        CompletableFuture<?> f = CompletableFuture.allOf();
88 +        checkCompletedNormally(f, null);
89 +    }
90 +
91 +    /**
92 +     * anyOf(no component futures) returns an incomplete future
93 +     */
94 +    public void testAnyOf_empty() throws Exception {
95 +        CompletableFuture<?> f = CompletableFuture.anyOf();
96 +        checkIncomplete(f);
97 +    }
98   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines