14 |
|
public class FutureTaskTest extends JSR166TestCase { |
15 |
|
|
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run(suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
|
return new TestSuite(FutureTaskTest.class); |
36 |
|
public void testConstructor() { |
37 |
|
try { |
38 |
|
FutureTask task = new FutureTask(null); |
39 |
< |
shouldThrow("NullPointerException"); |
39 |
> |
shouldThrow(); |
40 |
|
} catch (NullPointerException success) {} |
41 |
|
} |
42 |
|
|
46 |
|
public void testConstructor2() { |
47 |
|
try { |
48 |
|
FutureTask task = new FutureTask(null, Boolean.TRUE); |
49 |
< |
shouldThrow("NullPointerException"); |
49 |
> |
shouldThrow(); |
50 |
|
} catch (NullPointerException success) {} |
51 |
|
} |
52 |
|
|
88 |
|
public void testSet() throws Exception { |
89 |
|
PublicFutureTask task = new PublicFutureTask(new NoOpCallable()); |
90 |
|
task.set(one); |
91 |
< |
assertEquals(task.get(), one); |
91 |
> |
assertSame(task.get(), one); |
92 |
|
} |
93 |
|
|
94 |
|
/** |
100 |
|
task.setException(nse); |
101 |
|
try { |
102 |
|
Object x = task.get(); |
103 |
< |
shouldThrow("ExecutionException"); |
103 |
> |
shouldThrow(); |
104 |
|
} catch (ExecutionException success) { |
105 |
|
assertSame(success.getCause(), nse); |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
/** |
110 |
< |
* Cancelling before running succeeds |
110 |
> |
* Cancelling before running succeeds |
111 |
|
*/ |
112 |
|
public void testCancelBeforeRun() { |
113 |
|
FutureTask task = new FutureTask(new NoOpCallable()); |
229 |
|
} |
230 |
|
|
231 |
|
/** |
232 |
< |
* Cancelling a task causes timed get in another thread to throw CancellationException |
232 |
> |
* Cancelling a task causes timed get in another thread to throw |
233 |
> |
* CancellationException |
234 |
|
*/ |
235 |
|
public void testTimedGet_Cancellation() throws InterruptedException { |
236 |
|
final FutureTask ft = |
254 |
|
} |
255 |
|
|
256 |
|
/** |
257 |
< |
* Cancelling a task causes get in another thread to throw CancellationException |
257 |
> |
* Cancelling a task causes get in another thread to throw |
258 |
> |
* CancellationException |
259 |
|
*/ |
260 |
|
public void testGet_Cancellation() throws InterruptedException { |
261 |
|
final FutureTask ft = |
291 |
|
ft.run(); |
292 |
|
try { |
293 |
|
ft.get(); |
294 |
< |
shouldThrow("ExecutionException"); |
294 |
> |
shouldThrow(); |
295 |
|
} catch (ExecutionException success) { |
296 |
|
assertTrue(success.getCause() instanceof ArithmeticException); |
297 |
|
} |
298 |
|
} |
299 |
|
|
300 |
|
/** |
301 |
< |
* A runtime exception in task causes timed get to throw ExecutionException |
301 |
> |
* A runtime exception in task causes timed get to throw ExecutionException |
302 |
|
*/ |
303 |
|
public void testTimedGet_ExecutionException2() throws Exception { |
304 |
|
final FutureTask ft = new FutureTask(new Callable() { |
309 |
|
ft.run(); |
310 |
|
try { |
311 |
|
ft.get(SHORT_DELAY_MS, MILLISECONDS); |
312 |
< |
shouldThrow("ExecutionException"); |
312 |
> |
shouldThrow(); |
313 |
|
} catch (ExecutionException success) { |
314 |
|
assertTrue(success.getCause() instanceof ArithmeticException); |
315 |
|
} |
333 |
|
} |
334 |
|
|
335 |
|
/** |
336 |
< |
* Interrupting a waiting timed get causes it to throw InterruptedException |
336 |
> |
* Interrupting a waiting timed get causes it to throw InterruptedException |
337 |
|
*/ |
338 |
|
public void testTimedGet_InterruptedException2() throws InterruptedException { |
339 |
|
final FutureTask ft = new FutureTask(new NoOpCallable()); |
355 |
|
try { |
356 |
|
FutureTask ft = new FutureTask(new NoOpCallable()); |
357 |
|
ft.get(1,MILLISECONDS); |
358 |
< |
shouldThrow("TimeoutException"); |
358 |
> |
shouldThrow(); |
359 |
|
} catch (TimeoutException success) {} |
360 |
|
} |
361 |
|
|