ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/FutureTaskTest.java
(Generate patch)

Comparing jsr166/src/test/tck/FutureTaskTest.java (file contents):
Revision 1.6 by dl, Thu Sep 25 11:02:41 2003 UTC vs.
Revision 1.10 by dl, Sat Dec 27 19:26:43 2003 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
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
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 21 | Line 22 | public class FutureTaskTest extends JSR1
22      /**
23       * Subclass to expose protected methods
24       */
25 <    static class MyFutureTask extends FutureTask {
26 <        public MyFutureTask(Callable r) { super(r); }
27 <        public boolean reset() { return super.reset(); }
27 <        public void setCancelled() { super.setCancelled(); }
28 <        public void setDone() { super.setDone(); }
25 >    static class PublicFutureTask extends FutureTask {
26 >        public PublicFutureTask(Callable r) { super(r); }
27 >        public boolean runAndReset() { return super.runAndReset(); }
28          public void set(Object x) { super.set(x); }
29          public void setException(Throwable t) { super.setException(t); }
30      }
# Line 65 | Line 64 | public class FutureTaskTest extends JSR1
64      }
65  
66      /**
67 <     * reset of a done task succeeds and changes status to not done
67 >     * runAndReset of a non-cancelled task succeeds
68       */
69 <    public void testReset() {
70 <        MyFutureTask task = new MyFutureTask(new NoOpCallable());
71 <        task.run();
73 <        assertTrue(task.isDone());
74 <        assertTrue(task.reset());      
69 >    public void testRunAndReset() {
70 >        PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
71 >        assertTrue(task.runAndReset());
72          assertFalse(task.isDone());
73      }
74  
75      /**
76 <     * Resetting after cancellation fails
76 >     * runAndReset after cancellation fails
77       */
78      public void testResetAfterCancel() {
79 <        MyFutureTask task = new MyFutureTask(new NoOpCallable());
79 >        PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
80          assertTrue(task.cancel(false));
81 <        task.run();
81 >        assertFalse(task.runAndReset());
82          assertTrue(task.isDone());
83          assertTrue(task.isCancelled());
87        assertFalse(task.reset());
84      }
85  
90    /**
91     * setDone of new task causes isDone to be true
92     */
93    public void testSetDone() {
94        MyFutureTask task = new MyFutureTask(new NoOpCallable());
95        task.setDone();
96        assertTrue(task.isDone());
97        assertFalse(task.isCancelled());
98    }
86  
100    /**
101     * setCancelled of a new task causes isCancelled to be true
102     */
103    public void testSetCancelled() {
104        MyFutureTask task = new MyFutureTask(new NoOpCallable());
105        assertTrue(task.cancel(false));
106        task.setCancelled();
107        assertTrue(task.isDone());
108        assertTrue(task.isCancelled());
109    }
87  
88      /**
89       * setting value gauses get to return it
90       */
91      public void testSet() {
92 <        MyFutureTask task = new MyFutureTask(new NoOpCallable());
92 >        PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
93          task.set(one);
94          try {
95              assertEquals(task.get(), one);
# Line 127 | Line 104 | public class FutureTaskTest extends JSR1
104       */
105      public void testSetException() {
106          Exception nse = new NoSuchElementException();
107 <        MyFutureTask task = new MyFutureTask(new NoOpCallable());
107 >        PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
108          task.setException(nse);
109          try {
110              Object x = task.get();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines