31 |
|
} |
32 |
|
|
33 |
|
/** |
34 |
< |
* |
34 |
> |
* creating task with null runnable throws NPE |
35 |
|
*/ |
36 |
|
public void testConstructor(){ |
37 |
|
try { |
43 |
|
} |
44 |
|
|
45 |
|
/** |
46 |
< |
* |
46 |
> |
* isDone is true after task is run |
47 |
|
*/ |
48 |
|
public void testIsDone(){ |
49 |
|
CancellableTask task = new CancellableTask(new NoOpRunnable()); |
53 |
|
} |
54 |
|
|
55 |
|
/** |
56 |
< |
* |
56 |
> |
* Cancelling before running succeeds |
57 |
|
*/ |
58 |
< |
public void testReset(){ |
59 |
< |
MyCancellableTask task = new MyCancellableTask(new NoOpRunnable()); |
58 |
> |
public void testCancelBeforeRun() { |
59 |
> |
CancellableTask task = new CancellableTask(new NoOpRunnable()); |
60 |
> |
assertTrue(task.cancel(false)); |
61 |
|
task.run(); |
62 |
|
assertTrue(task.isDone()); |
63 |
< |
assertTrue(task.reset()); |
63 |
> |
assertTrue(task.isCancelled()); |
64 |
|
} |
65 |
|
|
66 |
|
/** |
67 |
< |
* |
67 |
> |
* reset of a done task succeeds and changes status to not done |
68 |
|
*/ |
69 |
< |
public void testCancelBeforeRun() { |
70 |
< |
CancellableTask task = new CancellableTask(new NoOpRunnable()); |
70 |
< |
assertTrue(task.cancel(false)); |
69 |
> |
public void testReset(){ |
70 |
> |
MyCancellableTask task = new MyCancellableTask(new NoOpRunnable()); |
71 |
|
task.run(); |
72 |
|
assertTrue(task.isDone()); |
73 |
< |
assertTrue(task.isCancelled()); |
73 |
> |
assertTrue(task.reset()); |
74 |
> |
assertFalse(task.isDone()); |
75 |
|
} |
76 |
|
|
77 |
|
/** |
78 |
< |
* |
78 |
> |
* Resetting after cancellation fails |
79 |
|
*/ |
80 |
|
public void testResetAfterCancel() { |
81 |
|
MyCancellableTask task = new MyCancellableTask(new NoOpRunnable()); |
87 |
|
} |
88 |
|
|
89 |
|
/** |
90 |
< |
* |
90 |
> |
* Setting the runnable causes it to be used |
91 |
|
*/ |
92 |
|
public void testSetRunnable() { |
93 |
|
MyCancellableTask task = new MyCancellableTask(); |
103 |
|
} |
104 |
|
|
105 |
|
/** |
106 |
< |
* |
106 |
> |
* setDone of new task causes isDone to be true |
107 |
|
*/ |
108 |
|
public void testSetDone() { |
109 |
|
MyCancellableTask task = new MyCancellableTask(new NoOpRunnable()); |
113 |
|
} |
114 |
|
|
115 |
|
/** |
116 |
< |
* |
116 |
> |
* setCancelled of a new task causes isCancelled to be true |
117 |
|
*/ |
118 |
|
public void testSetCancelled() { |
119 |
|
MyCancellableTask task = new MyCancellableTask(new NoOpRunnable()); |
124 |
|
} |
125 |
|
|
126 |
|
/** |
127 |
< |
* |
127 |
> |
* Cancel(true) before run succeeds |
128 |
|
*/ |
129 |
|
public void testCancelBeforeRun2() { |
130 |
|
CancellableTask task = new CancellableTask(new NoOpRunnable()); |
135 |
|
} |
136 |
|
|
137 |
|
/** |
138 |
< |
* |
138 |
> |
* cancel of a completed task fails |
139 |
|
*/ |
140 |
|
public void testCancelAfterRun() { |
141 |
|
CancellableTask task = new CancellableTask(new NoOpRunnable()); |
146 |
|
} |
147 |
|
|
148 |
|
/** |
149 |
< |
* |
149 |
> |
* cancel(true) interrupts a running task |
150 |
|
*/ |
151 |
|
public void testCancelInterrupt(){ |
152 |
|
CancellableTask task = new CancellableTask(new SmallInterruptedRunnable()); |
166 |
|
|
167 |
|
|
168 |
|
/** |
169 |
< |
* |
169 |
> |
* cancel(false) does not interrupt a running task |
170 |
|
*/ |
171 |
|
public void testCancelNoInterrupt(){ |
172 |
|
CancellableTask task = new CancellableTask(new SmallRunnable()); |