--- jsr166/src/test/tck/CompletableFutureTest.java 2013/02/09 19:33:08 1.3 +++ jsr166/src/test/tck/CompletableFutureTest.java 2013/02/10 21:18:25 1.4 @@ -1,9 +1,8 @@ /* - * Written by Doug Lea with assistance from members of JCP JSR-166 - * Expert Group and released to the public domain, as explained at + * Written by Doug Lea and Martin Buchholz with assistance from + * members of JCP JSR-166 Expert Group and released to the public + * domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ - * Other contributors include Andrew Wright, Jeffrey Hayes, - * Pat Fisher, Mike Judd. */ import junit.framework.*; @@ -28,6 +27,39 @@ public class CompletableFutureTest exten return new TestSuite(CompletableFutureTest.class); } + void checkIncomplete(CompletableFuture f) { + assertFalse(f.isDone()); + assertFalse(f.isCancelled()); + assertTrue(f.toString().contains("[Not completed]")); + try { + assertNull(f.getNow(null)); + } catch (Throwable fail) { threadUnexpectedException(fail); } + try { + f.get(0L, SECONDS); + shouldThrow(); + } + catch (TimeoutException success) {} + catch (Throwable fail) { threadUnexpectedException(fail); } + } + + void checkCompletedNormally(CompletableFuture f, Object value) { + assertTrue(f.isDone()); + assertFalse(f.isCancelled()); + assertTrue(f.toString().contains("[Completed normally]")); + try { + assertSame(value, f.join()); + } catch (Throwable fail) { threadUnexpectedException(fail); } + try { + assertSame(value, f.getNow(null)); + } catch (Throwable fail) { threadUnexpectedException(fail); } + try { + assertSame(value, f.get()); + } catch (Throwable fail) { threadUnexpectedException(fail); } + try { + assertSame(value, f.get(0L, SECONDS)); + } catch (Throwable fail) { threadUnexpectedException(fail); } + } + // XXXX Just a skeleton implementation for now. public void testTODO() { fail("Please add some real tests!"); @@ -46,4 +78,21 @@ public class CompletableFutureTest exten f.completeExceptionally(new IndexOutOfBoundsException()); assertTrue(f.toString().contains("[Completed exceptionally]")); } + + /** + * allOf(no component futures) returns a future completed normally + * with the value null + */ + public void testAllOf_empty() throws Exception { + CompletableFuture f = CompletableFuture.allOf(); + checkCompletedNormally(f, null); + } + + /** + * anyOf(no component futures) returns an incomplete future + */ + public void testAnyOf_empty() throws Exception { + CompletableFuture f = CompletableFuture.anyOf(); + checkIncomplete(f); + } }