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

Comparing jsr166/src/test/tck/TimeUnitTest.java (file contents):
Revision 1.3 by dl, Sun Sep 14 20:42:41 2003 UTC vs.
Revision 1.4 by dl, Sat Sep 20 18:20:08 2003 UTC

# Line 19 | Line 19 | public class TimeUnitTest extends JSR166
19          return new TestSuite(TimeUnitTest.class);
20      }
21  
22 +    /**
23 +     *
24 +     */
25      public void testConvert() {
26          for (long t = 0; t < 10; ++t) {
27              assertEquals(t,
# Line 72 | Line 75 | public class TimeUnitTest extends JSR166
75          }
76      }
77  
78 +    /**
79 +     *
80 +     */
81      public void testToNanos() {
82          for (long t = 0; t < 10; ++t) {
83              assertEquals(1000000000 * t,
# Line 86 | Line 92 | public class TimeUnitTest extends JSR166
92          }
93      }
94  
95 +    /**
96 +     *
97 +     */
98      public void testToMicros() {
99          for (long t = 0; t < 10; ++t) {
100              assertEquals(1000000 * t,
# Line 100 | Line 109 | public class TimeUnitTest extends JSR166
109          }
110      }
111  
112 +    /**
113 +     *
114 +     */
115      public void testToMillis() {
116          for (long t = 0; t < 10; ++t) {
117              assertEquals(1000 * t,
# Line 114 | Line 126 | public class TimeUnitTest extends JSR166
126          }
127      }
128  
129 +    /**
130 +     *
131 +     */
132      public void testToSeconds() {
133          for (long t = 0; t < 10; ++t) {
134              assertEquals(t,
# Line 129 | Line 144 | public class TimeUnitTest extends JSR166
144      }
145  
146  
147 +    /**
148 +     *
149 +     */
150      public void testConvertSaturate() {
151          assertEquals(Long.MAX_VALUE,
152                       TimeUnit.NANOSECONDS.convert(Long.MAX_VALUE / 2,
# Line 139 | Line 157 | public class TimeUnitTest extends JSR166
157  
158      }
159  
160 +    /**
161 +     *
162 +     */
163      public void testToNanosSaturate() {
164              assertEquals(Long.MAX_VALUE,
165                           TimeUnit.MILLISECONDS.toNanos(Long.MAX_VALUE / 2));
# Line 148 | Line 169 | public class TimeUnitTest extends JSR166
169      }
170  
171  
172 +    /**
173 +     *
174 +     */
175      public void testToString() {
176          String s = TimeUnit.SECONDS.toString();
177          assertTrue(s.indexOf("econd") >= 0);
# Line 158 | Line 182 | public class TimeUnitTest extends JSR166
182       *  Timed wait without holding lock throws
183       *  IllegalMonitorStateException
184       */
185 +    /**
186 +     *
187 +     */
188      public void testTimedWait_IllegalMonitorException() {
189          //created a new thread with anonymous runnable
190  
# Line 167 | Line 194 | public class TimeUnitTest extends JSR166
194                      TimeUnit tu = TimeUnit.MILLISECONDS;
195                      try {
196                          tu.timedWait(o,LONG_DELAY_MS);
197 <                        fail("should throw");
197 >                        threadShouldThrow();
198                      }
199                      catch (InterruptedException ie) {
200 <                        fail("should not throw IE here");
200 >                        threadUnexpectedException();
201                      }
202                      catch(IllegalMonitorStateException success) {
203                      }
# Line 183 | Line 210 | public class TimeUnitTest extends JSR166
210              t.interrupt();
211              t.join();
212          } catch(Exception e) {
213 <            fail("Unexpected exception");
213 >            unexpectedException();
214          }
215      }
216      
# Line 193 | Line 220 | public class TimeUnitTest extends JSR166
220       *  Note:  This does not throw IllegalMonitorException since timeWait
221       *         is synchronized on o
222       */
223 +    /**
224 +     *
225 +     */
226      public void testTimedWait() {
227          Thread t = new Thread(new Runnable() {
228                  public void run() {
# Line 203 | Line 233 | public class TimeUnitTest extends JSR166
233                          synchronized(o) {
234                              tu.timedWait(o,MEDIUM_DELAY_MS);
235                          }
236 <                        fail("should throw");
236 >                        threadShouldThrow();
237                      }
238                      catch(InterruptedException success) {}
239                      catch(IllegalMonitorStateException failure) {
240 <                        fail("should not throw");
240 >                        threadUnexpectedException();
241                      }
242                  }
243              });
# Line 217 | Line 247 | public class TimeUnitTest extends JSR166
247              t.interrupt();
248              t.join();
249          } catch(Exception e) {
250 <            fail("Unexpected exception");
250 >            unexpectedException();
251          }
252      }
253      
# Line 226 | Line 256 | public class TimeUnitTest extends JSR166
256       *   timedJoin will throw InterruptedException.
257       *  Thread t waits on timedJoin while the main thread interrupts it.
258       */
259 +    /**
260 +     *
261 +     */
262      public void testTimedJoin() {
263          Thread t = new Thread(new Runnable() {
264                  public void run() {
# Line 233 | Line 266 | public class TimeUnitTest extends JSR166
266                      try {
267                          Thread s = new Thread(new Runnable() {
268                                  public void run() {
269 <                                    try{
269 >                                    try {
270                                          Thread.sleep(MEDIUM_DELAY_MS);
271 <                                    }catch(InterruptedException success){}
271 >                                    } catch(InterruptedException success){}
272                                  }
273                              });
274                          s.start();
275                          tu.timedJoin(s,MEDIUM_DELAY_MS);
276 <                        fail("should throw");
276 >                        threadShouldThrow();
277                      }
278                      catch(Exception e) {}
279                  }
# Line 251 | Line 284 | public class TimeUnitTest extends JSR166
284              t.interrupt();
285              t.join();
286          } catch(Exception e) {
287 <            fail("Unexpected exception");
287 >            unexpectedException();
288          }
289      }
290      
# Line 259 | Line 292 | public class TimeUnitTest extends JSR166
292       *   timedSleep will throw InterruptedException.
293       *  Thread t waits on timedSleep while the main thread interrupts it.
294       */
295 +    /**
296 +     *
297 +     */
298      public void testTimedSleep() {
299          //created a new thread with anonymous runnable
300  
# Line 267 | Line 303 | public class TimeUnitTest extends JSR166
303                      TimeUnit tu = TimeUnit.MILLISECONDS;
304                      try {
305                          tu.sleep(MEDIUM_DELAY_MS);
306 <                        fail("should throw");
306 >                        threadShouldThrow();
307                      }
308                      catch(InterruptedException success) {}
309                  }
# Line 278 | Line 314 | public class TimeUnitTest extends JSR166
314              t.interrupt();
315              t.join();
316          } catch(Exception e) {
317 <            fail("Unexpected exception");
317 >            unexpectedException();
318          }
319      }
320  
321 +    /**
322 +     *
323 +     */
324      public void testSerialization() {
325          TimeUnit q = TimeUnit.MILLISECONDS;
326  
# Line 298 | Line 337 | public class TimeUnitTest extends JSR166
337              assertEquals(q.toString(), r.toString());
338          } catch(Exception e){
339              e.printStackTrace();
340 <            fail("unexpected exception");
340 >            unexpectedException();
341          }
342      }
343  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines