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.5 by dl, Thu Mar 21 16:26:43 2013 UTC vs.
Revision 1.14 by jsr166, Mon Apr 1 20:06:25 2013 UTC

# Line 53 | Line 53 | public class CompletableFutureTest exten
53          catch (Throwable fail) { threadUnexpectedException(fail); }
54      }
55  
56 <    void checkCompletedNormally(CompletableFuture<?> f, Object value) {
56 >    <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
57          try {
58              assertEquals(value, f.join());
59          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 75 | Line 75 | public class CompletableFutureTest exten
75          try {
76              f.join();
77              shouldThrow();
78 <        } catch (Throwable ex) {
79 <            assertTrue(ex instanceof CompletionException &&
80 <                       ((CompletionException)ex).getCause() instanceof CFException);
78 >        } catch (CompletionException success) {
79 >            assertTrue(success.getCause() instanceof CFException);
80          }
81          try {
82              f.getNow(null);
83              shouldThrow();
84 <        } catch (Throwable ex) {
85 <            assertTrue(ex instanceof CompletionException &&
87 <                       ((CompletionException)ex).getCause() instanceof CFException);
84 >        } catch (CompletionException success) {
85 >            assertTrue(success.getCause() instanceof CFException);
86          }
87          try {
88              f.get();
89              shouldThrow();
90 <        } catch (Throwable ex) {
91 <            assertTrue(ex instanceof ExecutionException &&
92 <                       ((ExecutionException)ex).getCause() instanceof CFException);
95 <        }
90 >        } catch (ExecutionException success) {
91 >            assertTrue(success.getCause() instanceof CFException);
92 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
93          try {
94              f.get(0L, SECONDS);
95              shouldThrow();
96 <        } catch (Throwable ex) {
97 <            assertTrue(ex instanceof ExecutionException &&
98 <                       ((ExecutionException)ex).getCause() instanceof CFException);
102 <        }
96 >        } catch (ExecutionException success) {
97 >            assertTrue(success.getCause() instanceof CFException);
98 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
99          assertTrue(f.isDone());
100          assertFalse(f.isCancelled());
101 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
102      }
103  
104      void checkCancelled(CompletableFuture<?> f) {
105          try {
106              f.join();
107              shouldThrow();
108 <        } catch (Throwable ex) {
112 <            assertTrue(ex instanceof CancellationException);
113 <        }
108 >        } catch (CancellationException success) {}
109          try {
110              f.getNow(null);
111              shouldThrow();
112 <        } catch (Throwable ex) {
118 <            assertTrue(ex instanceof CancellationException);
119 <        }
112 >        } catch (CancellationException success) {}
113          try {
114              f.get();
115              shouldThrow();
116 <        } catch (Throwable ex) {
117 <            assertTrue(ex instanceof CancellationException);
125 <        }
116 >        } catch (CancellationException success) {
117 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
118          try {
119              f.get(0L, SECONDS);
120              shouldThrow();
121 <        } catch (Throwable ex) {
122 <            assertTrue(ex instanceof CancellationException);
131 <        }
121 >        } catch (CancellationException success) {
122 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
123          assertTrue(f.isDone());
124          assertTrue(f.isCancelled());
125 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
126      }
127  
128      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
129          try {
130              f.join();
131              shouldThrow();
132 <        } catch (Throwable ex) {
133 <            assertTrue(ex instanceof CompletionException &&
142 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
132 >        } catch (CompletionException success) {
133 >            assertTrue(success.getCause() instanceof CancellationException);
134          }
135          try {
136              f.getNow(null);
137              shouldThrow();
138 <        } catch (Throwable ex) {
139 <            assertTrue(ex instanceof CompletionException &&
149 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
138 >        } catch (CompletionException success) {
139 >            assertTrue(success.getCause() instanceof CancellationException);
140          }
141          try {
142              f.get();
143              shouldThrow();
144 <        } catch (Throwable ex) {
145 <            assertTrue(ex instanceof ExecutionException &&
146 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
157 <        }
144 >        } catch (ExecutionException success) {
145 >            assertTrue(success.getCause() instanceof CancellationException);
146 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
147          try {
148              f.get(0L, SECONDS);
149              shouldThrow();
150 <        } catch (Throwable ex) {
151 <            assertTrue(ex instanceof ExecutionException &&
152 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
164 <        }
150 >        } catch (ExecutionException success) {
151 >            assertTrue(success.getCause() instanceof CancellationException);
152 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
153          assertTrue(f.isDone());
154          assertFalse(f.isCancelled());
155 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
156      }
157  
158      /**
# Line 249 | Line 238 | public class CompletableFutureTest exten
238          f.obtrudeException(new CFException());
239          checkCompletedWithWrappedCFException(f);
240      }
241 <    
241 >
242      /**
243       * getNumberOfDependents returns number of dependent tasks
244       */
# Line 285 | Line 274 | public class CompletableFutureTest exten
274          assertTrue(f.toString().contains("[Completed exceptionally]"));
275      }
276  
277 <    static final Supplier<Integer> supplyOne =
277 >    /**
278 >     * completedFuture returns a completed CompletableFuture with given value
279 >     */
280 >    public void testCompletedFuture() {
281 >        CompletableFuture<String> f = CompletableFuture.completedFuture("test");
282 >        checkCompletedNormally(f, "test");
283 >    }
284 >
285 >    static final Supplier<Integer> supplyOne =
286          () -> Integer.valueOf(1);
287 <    static final Function<Integer, Integer> inc =
287 >    static final Function<Integer, Integer> inc =
288          (Integer x) -> Integer.valueOf(x.intValue() + 1);
289 <    static final BiFunction<Integer, Integer, Integer> add =
289 >    static final BiFunction<Integer, Integer, Integer> add =
290          (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue());
291      static final class IncAction implements Consumer<Integer> {
292          int value;
# Line 297 | Line 294 | public class CompletableFutureTest exten
294      }
295      static final class AddAction implements BiConsumer<Integer, Integer> {
296          int value;
297 <        public void accept(Integer x, Integer y) {
298 <            value = x.intValue() + y.intValue();
297 >        public void accept(Integer x, Integer y) {
298 >            value = x.intValue() + y.intValue();
299          }
300      }
301      static final class Noop implements Runnable {
# Line 345 | Line 342 | public class CompletableFutureTest exten
342              ran = true; throw new CFException();
343          }
344      }
345 <    
345 >
346      // Used for explicit executor tests
347      static final class ThreadExecutor implements Executor {
348          public void execute(Runnable r) {
# Line 358 | Line 355 | public class CompletableFutureTest exten
355      }
356  
357      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
358 <        public Integer apply(Integer x, Throwable t) {
358 >        public Integer apply(Integer x, Throwable t) {
359              return (t == null) ? two : three;
360          }
361      }
# Line 408 | Line 405 | public class CompletableFutureTest exten
405          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
406          assertNull(f.join());
407          assertTrue(r.ran);
408 +        checkCompletedNormally(f, null);
409      }
410  
411      /**
# Line 418 | Line 416 | public class CompletableFutureTest exten
416          CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor());
417          assertNull(f.join());
418          assertTrue(r.ran);
419 +        checkCompletedNormally(f, null);
420      }
421  
422      /**
# Line 456 | Line 455 | public class CompletableFutureTest exten
455          assertTrue(r.ran);
456      }
457  
458 <    // seq conmpletion methods
459 <    
458 >    // seq completion methods
459 >
460      /**
461       * thenRun result completes normally after normal completion of source
462       */
# Line 1126 | Line 1125 | public class CompletableFutureTest exten
1125          try {
1126              g.join();
1127              shouldThrow();
1128 <        } catch(Exception ok) {
1128 >        } catch (Exception ok) {
1129          }
1130          checkCompletedWithWrappedCFException(g);
1131      }
# Line 1141 | Line 1140 | public class CompletableFutureTest exten
1140          f.complete(null);
1141          checkCompletedWithWrappedCFException(g);
1142      }
1143 <        
1143 >
1144      /**
1145       * thenRunAsync result completes exceptionally if source cancelled
1146       */
# Line 1184 | Line 1183 | public class CompletableFutureTest exten
1183          f.complete(null);
1184          checkCompletedWithWrappedCFException(g);
1185      }
1186 <        
1186 >
1187      /**
1188       * thenApplyAsync result completes exceptionally if source cancelled
1189       */
# Line 1230 | Line 1229 | public class CompletableFutureTest exten
1229          f.complete(null);
1230          checkCompletedWithWrappedCFException(g);
1231      }
1232 <        
1232 >
1233      /**
1234       * thenAcceptAsync result completes exceptionally if source cancelled
1235       */
# Line 1288 | Line 1287 | public class CompletableFutureTest exten
1287          f2.complete(two);
1288          checkCompletedWithWrappedCFException(g);
1289      }
1290 <        
1290 >
1291      /**
1292       * thenCombineAsync result completes exceptionally if either source cancelled
1293       */
# Line 1299 | Line 1298 | public class CompletableFutureTest exten
1298          assertTrue(f.cancel(true));
1299          f2.complete(two);
1300          checkCompletedWithWrappedCancellationException(g);
1301 <        
1301 >
1302          f = new CompletableFuture<Integer>();
1303          f2 = new CompletableFuture<Integer>();
1304          g = f.thenCombineAsync(f2, add);
# Line 1353 | Line 1352 | public class CompletableFutureTest exten
1352          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1353          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1354          FailingBiConsumer r = new FailingBiConsumer();
1355 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);      
1355 >        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1356          f.complete(one);
1357          checkIncomplete(g);
1358          f2.complete(two);
1359          checkCompletedWithWrappedCFException(g);
1360      }
1361 <        
1361 >
1362      /**
1363       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1364       */
# Line 1371 | Line 1370 | public class CompletableFutureTest exten
1370          assertTrue(f.cancel(true));
1371          f2.complete(two);
1372          checkCompletedWithWrappedCancellationException(g);
1373 <        
1373 >
1374          r = new AddAction();
1375          f = new CompletableFuture<Integer>();
1376          f2 = new CompletableFuture<Integer>();
# Line 1426 | Line 1425 | public class CompletableFutureTest exten
1425          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1426          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1427          FailingNoop r = new FailingNoop();
1428 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);      
1428 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1429          f.complete(one);
1430          checkIncomplete(g);
1431          f2.complete(two);
1432          checkCompletedWithWrappedCFException(g);
1433      }
1434 <        
1434 >
1435      /**
1436       * runAfterBothAsync result completes exceptionally if either source cancelled
1437       */
# Line 1444 | Line 1443 | public class CompletableFutureTest exten
1443          assertTrue(f.cancel(true));
1444          f2.complete(two);
1445          checkCompletedWithWrappedCancellationException(g);
1446 <        
1446 >
1447          r = new Noop();
1448          f = new CompletableFuture<Integer>();
1449          f2 = new CompletableFuture<Integer>();
# Line 1498 | Line 1497 | public class CompletableFutureTest exten
1497          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1498          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1499          FailingFunction r = new FailingFunction();
1500 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);      
1500 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
1501          f.complete(one);
1502          checkCompletedWithWrappedCFException(g);
1503      }
1504 <        
1504 >
1505      /**
1506       * applyToEitherAsync result completes exceptionally if either source cancelled
1507       */
# Line 1512 | Line 1511 | public class CompletableFutureTest exten
1511          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1512          assertTrue(f.cancel(true));
1513          checkCompletedWithWrappedCancellationException(g);
1514 <        
1514 >
1515          f = new CompletableFuture<Integer>();
1516          f2 = new CompletableFuture<Integer>();
1517          assertTrue(f2.cancel(true));
# Line 1570 | Line 1569 | public class CompletableFutureTest exten
1569          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1570          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1571          FailingConsumer r = new FailingConsumer();
1572 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);      
1572 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1573          f.complete(one);
1574          checkCompletedWithWrappedCFException(g);
1575      }
1576 <        
1576 >
1577      /**
1578       * acceptEitherAsync result completes exceptionally if either
1579       * source cancelled
# Line 1586 | Line 1585 | public class CompletableFutureTest exten
1585          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1586          assertTrue(f.cancel(true));
1587          checkCompletedWithWrappedCancellationException(g);
1588 <        
1588 >
1589          r = new IncAction();
1590          f = new CompletableFuture<Integer>();
1591          f2 = new CompletableFuture<Integer>();
# Line 1645 | Line 1644 | public class CompletableFutureTest exten
1644          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1645          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1646          FailingNoop r = new FailingNoop();
1647 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);      
1647 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1648          f.complete(one);
1649          checkCompletedWithWrappedCFException(g);
1650      }
1651 <        
1651 >
1652      /**
1653       * runAfterEitherAsync result completes exceptionally if either
1654       * source cancelled
# Line 1661 | Line 1660 | public class CompletableFutureTest exten
1660          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1661          assertTrue(f.cancel(true));
1662          checkCompletedWithWrappedCancellationException(g);
1663 <        
1663 >
1664          r = new Noop();
1665          f = new CompletableFuture<Integer>();
1666          f2 = new CompletableFuture<Integer>();
# Line 1671 | Line 1670 | public class CompletableFutureTest exten
1670      }
1671  
1672      /**
1673 <     * thenCompse result completes normally after normal completion of source
1673 >     * thenComposeAsync result completes normally after normal
1674 >     * completion of source
1675       */
1676      public void testThenComposeAsync() {
1677          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 1682 | Line 1682 | public class CompletableFutureTest exten
1682      }
1683  
1684      /**
1685 <     * thenComposeAsync result completes exceptionally after exceptional
1686 <     * completion of source
1685 >     * thenComposeAsync result completes exceptionally after
1686 >     * exceptional completion of source
1687       */
1688      public void testThenComposeAsync2() {
1689          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 1716 | Line 1716 | public class CompletableFutureTest exten
1716      }
1717  
1718  
1719 <    // aaync with explicit executors
1719 >    // async with explicit executors
1720  
1721      /**
1722       * thenRunAsync result completes normally after normal completion of source
# Line 1748 | Line 1748 | public class CompletableFutureTest exten
1748          try {
1749              g.join();
1750              shouldThrow();
1751 <        } catch(Exception ok) {
1751 >        } catch (Exception ok) {
1752          }
1753          checkCompletedWithWrappedCFException(g);
1754      }
# Line 1763 | Line 1763 | public class CompletableFutureTest exten
1763          f.complete(null);
1764          checkCompletedWithWrappedCFException(g);
1765      }
1766 <        
1766 >
1767      /**
1768       * thenRunAsync result completes exceptionally if source cancelled
1769       */
# Line 1806 | Line 1806 | public class CompletableFutureTest exten
1806          f.complete(null);
1807          checkCompletedWithWrappedCFException(g);
1808      }
1809 <        
1809 >
1810      /**
1811       * thenApplyAsync result completes exceptionally if source cancelled
1812       */
# Line 1852 | Line 1852 | public class CompletableFutureTest exten
1852          f.complete(null);
1853          checkCompletedWithWrappedCFException(g);
1854      }
1855 <        
1855 >
1856      /**
1857       * thenAcceptAsync result completes exceptionally if source cancelled
1858       */
# Line 1910 | Line 1910 | public class CompletableFutureTest exten
1910          f2.complete(two);
1911          checkCompletedWithWrappedCFException(g);
1912      }
1913 <        
1913 >
1914      /**
1915       * thenCombineAsync result completes exceptionally if either source cancelled
1916       */
# Line 1921 | Line 1921 | public class CompletableFutureTest exten
1921          assertTrue(f.cancel(true));
1922          f2.complete(two);
1923          checkCompletedWithWrappedCancellationException(g);
1924 <        
1924 >
1925          f = new CompletableFuture<Integer>();
1926          f2 = new CompletableFuture<Integer>();
1927          g = f.thenCombineAsync(f2, add, new ThreadExecutor());
# Line 1975 | Line 1975 | public class CompletableFutureTest exten
1975          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1976          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1977          FailingBiConsumer r = new FailingBiConsumer();
1978 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());      
1978 >        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1979          f.complete(one);
1980          checkIncomplete(g);
1981          f2.complete(two);
1982          checkCompletedWithWrappedCFException(g);
1983      }
1984 <        
1984 >
1985      /**
1986       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1987       */
# Line 1993 | Line 1993 | public class CompletableFutureTest exten
1993          assertTrue(f.cancel(true));
1994          f2.complete(two);
1995          checkCompletedWithWrappedCancellationException(g);
1996 <        
1996 >
1997          r = new AddAction();
1998          f = new CompletableFuture<Integer>();
1999          f2 = new CompletableFuture<Integer>();
# Line 2048 | Line 2048 | public class CompletableFutureTest exten
2048          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2049          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2050          FailingNoop r = new FailingNoop();
2051 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());      
2051 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2052          f.complete(one);
2053          checkIncomplete(g);
2054          f2.complete(two);
2055          checkCompletedWithWrappedCFException(g);
2056      }
2057 <        
2057 >
2058      /**
2059       * runAfterBothAsync result completes exceptionally if either source cancelled
2060       */
# Line 2066 | Line 2066 | public class CompletableFutureTest exten
2066          assertTrue(f.cancel(true));
2067          f2.complete(two);
2068          checkCompletedWithWrappedCancellationException(g);
2069 <        
2069 >
2070          r = new Noop();
2071          f = new CompletableFuture<Integer>();
2072          f2 = new CompletableFuture<Integer>();
# Line 2120 | Line 2120 | public class CompletableFutureTest exten
2120          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2121          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2122          FailingFunction r = new FailingFunction();
2123 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());      
2123 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2124          f.complete(one);
2125          checkCompletedWithWrappedCFException(g);
2126      }
2127 <        
2127 >
2128      /**
2129       * applyToEitherAsync result completes exceptionally if either source cancelled
2130       */
# Line 2134 | Line 2134 | public class CompletableFutureTest exten
2134          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2135          assertTrue(f.cancel(true));
2136          checkCompletedWithWrappedCancellationException(g);
2137 <        
2137 >
2138          f = new CompletableFuture<Integer>();
2139          f2 = new CompletableFuture<Integer>();
2140          assertTrue(f2.cancel(true));
# Line 2192 | Line 2192 | public class CompletableFutureTest exten
2192          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2193          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2194          FailingConsumer r = new FailingConsumer();
2195 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());      
2195 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2196          f.complete(one);
2197          checkCompletedWithWrappedCFException(g);
2198      }
2199 <        
2199 >
2200      /**
2201       * acceptEitherAsync result completes exceptionally if either
2202       * source cancelled
# Line 2208 | Line 2208 | public class CompletableFutureTest exten
2208          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2209          assertTrue(f.cancel(true));
2210          checkCompletedWithWrappedCancellationException(g);
2211 <        
2211 >
2212          r = new IncAction();
2213          f = new CompletableFuture<Integer>();
2214          f2 = new CompletableFuture<Integer>();
# Line 2267 | Line 2267 | public class CompletableFutureTest exten
2267          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2268          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2269          FailingNoop r = new FailingNoop();
2270 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());      
2270 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2271          f.complete(one);
2272          checkCompletedWithWrappedCFException(g);
2273      }
2274 <        
2274 >
2275      /**
2276       * runAfterEitherAsync result completes exceptionally if either
2277       * source cancelled
# Line 2283 | Line 2283 | public class CompletableFutureTest exten
2283          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2284          assertTrue(f.cancel(true));
2285          checkCompletedWithWrappedCancellationException(g);
2286 <        
2286 >
2287          r = new Noop();
2288          f = new CompletableFuture<Integer>();
2289          f2 = new CompletableFuture<Integer>();
# Line 2293 | Line 2293 | public class CompletableFutureTest exten
2293      }
2294  
2295      /**
2296 <     * thenCompse result completes normally after normal completion of source
2296 >     * thenComposeAsync result completes normally after normal
2297 >     * completion of source
2298       */
2299      public void testThenComposeAsyncE() {
2300          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 2304 | Line 2305 | public class CompletableFutureTest exten
2305      }
2306  
2307      /**
2308 <     * thenComposeAsync result completes exceptionally after exceptional
2309 <     * completion of source
2308 >     * thenComposeAsync result completes exceptionally after
2309 >     * exceptional completion of source
2310       */
2311      public void testThenComposeAsync2E() {
2312          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 2337 | Line 2338 | public class CompletableFutureTest exten
2338          checkCompletedWithWrappedCancellationException(g);
2339      }
2340  
2341 <    // other static methods    
2341 >    // other static methods
2342  
2343      /**
2344       * allOf(no component futures) returns a future completed normally
# Line 2354 | Line 2355 | public class CompletableFutureTest exten
2355      public void testAllOf() throws Exception {
2356          for (int k = 1; k < 20; ++k) {
2357              CompletableFuture[] fs = new CompletableFuture[k];
2358 <            for (int i = 0; i < k; ++i)
2358 >            for (int i = 0; i < k; ++i)
2359                  fs[i] = new CompletableFuture<Integer>();
2360 <            CompletableFuture<?> f = CompletableFuture.allOf(fs);
2360 >            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2361              for (int i = 0; i < k; ++i) {
2362                  checkIncomplete(f);
2363                  fs[i].complete(one);
2364              }
2365 <            assertTrue(f.isDone());
2365 <            assertFalse(f.isCancelled());
2365 >            checkCompletedNormally(f, null);
2366          }
2367      }
2368  
# Line 2375 | Line 2375 | public class CompletableFutureTest exten
2375      }
2376  
2377      /**
2378 <     * allOf returns a future completed when any components complete
2378 >     * anyOf returns a future completed when any components complete
2379       */
2380      public void testAnyOf() throws Exception {
2381          for (int k = 1; k < 20; ++k) {
2382              CompletableFuture[] fs = new CompletableFuture[k];
2383 <            for (int i = 0; i < k; ++i)
2383 >            for (int i = 0; i < k; ++i)
2384                  fs[i] = new CompletableFuture<Integer>();
2385 <            CompletableFuture<?> f = CompletableFuture.anyOf(fs);
2385 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2386              checkIncomplete(f);
2387              for (int i = 0; i < k; ++i) {
2388                  fs[i].complete(one);
2389 <                assertTrue(f.isDone());
2389 >                checkCompletedNormally(f, one);
2390              }
2391          }
2392      }
# Line 2397 | Line 2397 | public class CompletableFutureTest exten
2397      public void testNPE() {
2398          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2399          CompletableFuture<Integer> g = new CompletableFuture<Integer>();
2400 <        CompletableFuture h;
2401 <        try { h = f.thenApply(null); } catch (NullPointerException ok) {}
2402 <        try { h = f.thenAccept(null); } catch (NullPointerException ok) {}
2403 <        try { h = f.thenRun(null); } catch (NullPointerException ok) {}
2404 <        try { h = f.thenCombine(g, null); } catch (NullPointerException ok) {}
2405 <        try { h = f.thenCombine(null, null); } catch (NullPointerException ok) {}
2406 <        try { h = f.applyToEither(g, null); } catch (NullPointerException ok) {}
2407 <        try { h = f.applyToEither(null, null); } catch (NullPointerException ok) {}
2408 <        try { h = f.thenAcceptBoth(g, null); } catch (NullPointerException ok) {}
2409 <        try { h = f.thenAcceptBoth(null, null); } catch (NullPointerException ok) {}
2410 <        try { h = f.runAfterEither(g, null); } catch (NullPointerException ok) {}
2411 <        try { h = f.runAfterEither(null, null); } catch (NullPointerException ok) {}
2412 <        try { h = f.runAfterBoth(g, null); } catch (NullPointerException ok) {}
2413 <        try { h = f.runAfterBoth(null, null); } catch (NullPointerException ok) {}
2414 <        try { h = f.exceptionally(null); } catch (NullPointerException ok) {}
2415 <        try { h = f.handle(null); } catch (NullPointerException ok) {}
2416 <        try { h = f.thenCompose(null); } catch (NullPointerException ok) {}
2417 <
2418 <        try { h = f.thenApplyAsync(null); } catch (NullPointerException ok) {}
2419 <        try { h = f.thenAcceptAsync(null); } catch (NullPointerException ok) {}
2420 <        try { h = f.thenRunAsync(null); } catch (NullPointerException ok) {}
2421 <        try { h = f.thenCombineAsync(g, null); } catch (NullPointerException ok) {}
2422 <        try { h = f.thenCombineAsync(null, null); } catch (NullPointerException ok) {}
2423 <        try { h = f.applyToEitherAsync(g, null); } catch (NullPointerException ok) {}
2424 <        try { h = f.applyToEitherAsync(null, null); } catch (NullPointerException ok) {}
2425 <        try { h = f.thenAcceptBothAsync(g, null); } catch (NullPointerException ok) {}
2426 <        try { h = f.thenAcceptBothAsync(null, null); } catch (NullPointerException ok) {}
2427 <        try { h = f.runAfterEitherAsync(g, null); } catch (NullPointerException ok) {}
2428 <        try { h = f.runAfterEitherAsync(null, null); } catch (NullPointerException ok) {}
2429 <        try { h = f.runAfterBothAsync(g, null); } catch (NullPointerException ok) {}
2430 <        try { h = f.runAfterBothAsync(null, null); } catch (NullPointerException ok) {}
2400 >        CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null;
2401 >        CompletableFuture<?> h;
2402 >        Executor exec = new ThreadExecutor();
2403 >
2404 >        Runnable[] throwingActions = {
2405 >            () -> { CompletableFuture.supplyAsync(null); },
2406 >            () -> { CompletableFuture.supplyAsync(null, exec); },
2407 >            () -> { CompletableFuture.supplyAsync(() -> one, null); },
2408 >
2409 >            () -> { CompletableFuture.runAsync(null); },
2410 >            () -> { CompletableFuture.runAsync(null, exec); },
2411 >            () -> { CompletableFuture.runAsync(() -> {}, null); },
2412 >
2413 >            () -> { f.completeExceptionally(null); },
2414 >
2415 >            () -> { f.thenApply(null); },
2416 >            () -> { f.thenApplyAsync(null); },
2417 >            () -> { f.thenApplyAsync((x) -> x, null); },
2418 >            () -> { f.thenApplyAsync(null, exec); },
2419 >
2420 >            () -> { f.thenAccept(null); },
2421 >            () -> { f.thenAcceptAsync(null); },
2422 >            () -> { f.thenAcceptAsync((x) -> { ; }, null); },
2423 >            () -> { f.thenAcceptAsync(null, exec); },
2424 >
2425 >            () -> { f.thenRun(null); },
2426 >            () -> { f.thenRunAsync(null); },
2427 >            () -> { f.thenRunAsync(() -> { ; }, null); },
2428 >            () -> { f.thenRunAsync(null, exec); },
2429 >
2430 >            () -> { f.thenCombine(g, null); },
2431 >            () -> { f.thenCombineAsync(g, null); },
2432 >            () -> { f.thenCombineAsync(g, null, exec); },
2433 >            () -> { f.thenCombine(nullFuture, (x, y) -> x); },
2434 >            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x); },
2435 >            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); },
2436 >            () -> { f.thenCombineAsync(g, (x, y) -> x, null); },
2437 >
2438 >            () -> { f.thenAcceptBoth(g, null); },
2439 >            () -> { f.thenAcceptBothAsync(g, null); },
2440 >            () -> { f.thenAcceptBothAsync(g, null, exec); },
2441 >            () -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); },
2442 >            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); },
2443 >            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); },
2444 >            () -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); },
2445 >
2446 >            () -> { f.runAfterBoth(g, null); },
2447 >            () -> { f.runAfterBothAsync(g, null); },
2448 >            () -> { f.runAfterBothAsync(g, null, exec); },
2449 >            () -> { f.runAfterBoth(nullFuture, () -> {}); },
2450 >            () -> { f.runAfterBothAsync(nullFuture, () -> {}); },
2451 >            () -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); },
2452 >            () -> { f.runAfterBothAsync(g, () -> {}, null); },
2453 >
2454 >            () -> { f.applyToEither(g, null); },
2455 >            () -> { f.applyToEitherAsync(g, null); },
2456 >            () -> { f.applyToEitherAsync(g, null, exec); },
2457 >            () -> { f.applyToEither(nullFuture, (x) -> x); },
2458 >            () -> { f.applyToEitherAsync(nullFuture, (x) -> x); },
2459 >            () -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); },
2460 >            () -> { f.applyToEitherAsync(g, (x) -> x, null); },
2461 >
2462 >            () -> { f.acceptEither(g, null); },
2463 >            () -> { f.acceptEitherAsync(g, null); },
2464 >            () -> { f.acceptEitherAsync(g, null, exec); },
2465 >            () -> { f.acceptEither(nullFuture, (x) -> {}); },
2466 >            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}); },
2467 >            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); },
2468 >            () -> { f.acceptEitherAsync(g, (x) -> {}, null); },
2469 >
2470 >            () -> { f.runAfterEither(g, null); },
2471 >            () -> { f.runAfterEitherAsync(g, null); },
2472 >            () -> { f.runAfterEitherAsync(g, null, exec); },
2473 >            () -> { f.runAfterEither(nullFuture, () -> {}); },
2474 >            () -> { f.runAfterEitherAsync(nullFuture, () -> {}); },
2475 >            () -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); },
2476 >            () -> { f.runAfterEitherAsync(g, () -> {}, null); },
2477 >
2478 >            () -> { f.thenCompose(null); },
2479 >            () -> { f.thenComposeAsync(null); },
2480 >            () -> { f.thenComposeAsync(new CompletableFutureInc(), null); },
2481 >            () -> { f.thenComposeAsync(null, exec); },
2482 >
2483 >            () -> { f.exceptionally(null); },
2484 >
2485 >            () -> { f.handle(null); },
2486 >
2487 >            () -> { CompletableFuture.allOf((CompletableFuture<?>)null); },
2488 >            () -> { CompletableFuture.allOf((CompletableFuture<?>[])null); },
2489 >            () -> { CompletableFuture.allOf(f, null); },
2490 >            () -> { CompletableFuture.allOf(null, f); },
2491 >
2492 >            () -> { CompletableFuture.anyOf((CompletableFuture<?>)null); },
2493 >            () -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); },
2494 >            () -> { CompletableFuture.anyOf(f, null); },
2495 >            () -> { CompletableFuture.anyOf(null, f); },
2496 >
2497 >            // TODO: Crashes javac with lambda-8-2013-03-31...
2498 >            //() -> { CompletableFuture<?> x = f.thenAccept(null); },
2499 >            //() -> { CompletableFuture<Void> x = f.thenRun(null); },
2500 >            //() -> { CompletableFuture<Integer> x = f.thenApply(() -> { ; }); },
2501 >        };
2502  
2503 +        assertThrows(NullPointerException.class, throwingActions);
2504      }
2505  
2434
2506   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines