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.7 by jsr166, Fri Mar 22 16:29:42 2013 UTC vs.
Revision 1.11 by jsr166, Sun Mar 31 18:14:19 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      }
# Line 108 | Line 104 | public class CompletableFutureTest exten
104          try {
105              f.join();
106              shouldThrow();
107 <        } catch (Throwable ex) {
112 <            assertTrue(ex instanceof CancellationException);
113 <        }
107 >        } catch (CancellationException success) {}
108          try {
109              f.getNow(null);
110              shouldThrow();
111 <        } catch (Throwable ex) {
118 <            assertTrue(ex instanceof CancellationException);
119 <        }
111 >        } catch (CancellationException success) {}
112          try {
113              f.get();
114              shouldThrow();
115 <        } catch (Throwable ex) {
116 <            assertTrue(ex instanceof CancellationException);
125 <        }
115 >        } catch (CancellationException success) {
116 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
117          try {
118              f.get(0L, SECONDS);
119              shouldThrow();
120 <        } catch (Throwable ex) {
121 <            assertTrue(ex instanceof CancellationException);
131 <        }
120 >        } catch (CancellationException success) {
121 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
122          assertTrue(f.isDone());
123          assertTrue(f.isCancelled());
124      }
# Line 137 | Line 127 | public class CompletableFutureTest exten
127          try {
128              f.join();
129              shouldThrow();
130 <        } catch (Throwable ex) {
131 <            assertTrue(ex instanceof CompletionException &&
142 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
130 >        } catch (CompletionException success) {
131 >            assertTrue(success.getCause() instanceof CancellationException);
132          }
133          try {
134              f.getNow(null);
135              shouldThrow();
136 <        } catch (Throwable ex) {
137 <            assertTrue(ex instanceof CompletionException &&
149 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
136 >        } catch (CompletionException success) {
137 >            assertTrue(success.getCause() instanceof CancellationException);
138          }
139          try {
140              f.get();
141              shouldThrow();
142 <        } catch (Throwable ex) {
143 <            assertTrue(ex instanceof ExecutionException &&
144 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
157 <        }
142 >        } catch (ExecutionException success) {
143 >            assertTrue(success.getCause() instanceof CancellationException);
144 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
145          try {
146              f.get(0L, SECONDS);
147              shouldThrow();
148 <        } catch (Throwable ex) {
149 <            assertTrue(ex instanceof ExecutionException &&
150 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
164 <        }
148 >        } catch (ExecutionException success) {
149 >            assertTrue(success.getCause() instanceof CancellationException);
150 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
151          assertTrue(f.isDone());
152          assertFalse(f.isCancelled());
153      }
# Line 285 | Line 271 | public class CompletableFutureTest exten
271          assertTrue(f.toString().contains("[Completed exceptionally]"));
272      }
273  
274 +    /**
275 +     * completedFuture returns a completed CompletableFuture with given value
276 +     */
277 +    public void testCompletedFuture() {
278 +        CompletableFuture<String> f = CompletableFuture.completedFuture("test");
279 +        checkCompletedNormally(f, "test");
280 +    }
281 +
282      static final Supplier<Integer> supplyOne =
283          () -> Integer.valueOf(1);
284      static final Function<Integer, Integer> inc =
# Line 2358 | Line 2352 | public class CompletableFutureTest exten
2352              CompletableFuture[] fs = new CompletableFuture[k];
2353              for (int i = 0; i < k; ++i)
2354                  fs[i] = new CompletableFuture<Integer>();
2355 <            CompletableFuture<?> f = CompletableFuture.allOf(fs);
2355 >            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2356              for (int i = 0; i < k; ++i) {
2357                  checkIncomplete(f);
2358                  fs[i].complete(one);
2359              }
2360 <            assertTrue(f.isDone());
2367 <            assertFalse(f.isCancelled());
2360 >            checkCompletedNormally(f, null);
2361          }
2362      }
2363  
# Line 2384 | Line 2377 | public class CompletableFutureTest exten
2377              CompletableFuture[] fs = new CompletableFuture[k];
2378              for (int i = 0; i < k; ++i)
2379                  fs[i] = new CompletableFuture<Integer>();
2380 <            CompletableFuture<?> f = CompletableFuture.anyOf(fs);
2380 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2381              checkIncomplete(f);
2382              for (int i = 0; i < k; ++i) {
2383                  fs[i].complete(one);
2384 <                assertTrue(f.isDone());
2384 >                checkCompletedNormally(f, one);
2385              }
2386          }
2387      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines