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.24 by jsr166, Wed Dec 31 19:05:43 2014 UTC vs.
Revision 1.27 by jsr166, Sat Jan 30 22:24:32 2016 UTC

# Line 14 | Line 14 | import static java.util.concurrent.TimeU
14   import static java.util.concurrent.TimeUnit.NANOSECONDS;
15   import static java.util.concurrent.TimeUnit.SECONDS;
16  
17 + import java.time.temporal.ChronoUnit;
18   import java.util.concurrent.CountDownLatch;
19   import java.util.concurrent.TimeUnit;
20  
# Line 22 | Line 23 | import junit.framework.TestSuite;
23  
24   public class TimeUnitTest extends JSR166TestCase {
25      public static void main(String[] args) {
26 <        junit.textui.TestRunner.run(suite());
26 >        main(suite(), args);
27      }
28  
29      public static Test suite() {
# Line 429 | Line 430 | public class TimeUnitTest extends JSR166
430       * a deserialized serialized unit is the same instance
431       */
432      public void testSerialization() throws Exception {
433 <        TimeUnit x = MILLISECONDS;
434 <        assertSame(x, serialClone(x));
433 >        for (TimeUnit x : TimeUnit.values())
434 >            assertSame(x, serialClone(x));
435 >    }
436 >
437 >    /**
438 >     * tests for toChronoUnit.
439 >     */
440 >    public void testToChronoUnit() throws Exception {
441 >        assertSame(ChronoUnit.NANOS,   NANOSECONDS.toChronoUnit());
442 >        assertSame(ChronoUnit.MICROS,  MICROSECONDS.toChronoUnit());
443 >        assertSame(ChronoUnit.MILLIS,  MILLISECONDS.toChronoUnit());
444 >        assertSame(ChronoUnit.SECONDS, SECONDS.toChronoUnit());
445 >        assertSame(ChronoUnit.MINUTES, MINUTES.toChronoUnit());
446 >        assertSame(ChronoUnit.HOURS,   HOURS.toChronoUnit());
447 >        assertSame(ChronoUnit.DAYS,    DAYS.toChronoUnit());
448 >
449 >        // Every TimeUnit has a defined ChronoUnit equivalent
450 >        for (TimeUnit x : TimeUnit.values())
451 >            assertSame(x, TimeUnit.of(x.toChronoUnit()));
452 >    }
453 >
454 >    /**
455 >     * tests for TimeUnit.of(ChronoUnit).
456 >     */
457 >    public void testTimeUnitOf() throws Exception {
458 >        assertSame(NANOSECONDS,  TimeUnit.of(ChronoUnit.NANOS));
459 >        assertSame(MICROSECONDS, TimeUnit.of(ChronoUnit.MICROS));
460 >        assertSame(MILLISECONDS, TimeUnit.of(ChronoUnit.MILLIS));
461 >        assertSame(SECONDS,      TimeUnit.of(ChronoUnit.SECONDS));
462 >        assertSame(MINUTES,      TimeUnit.of(ChronoUnit.MINUTES));
463 >        assertSame(HOURS,        TimeUnit.of(ChronoUnit.HOURS));
464 >        assertSame(DAYS,         TimeUnit.of(ChronoUnit.DAYS));
465 >
466 >        assertThrows(NullPointerException.class,
467 >                     () -> TimeUnit.of((ChronoUnit)null));
468 >
469 >        // ChronoUnits either round trip to their TimeUnit
470 >        // equivalents, or throw IllegalArgumentException.
471 >        for (ChronoUnit cu : ChronoUnit.values()) {
472 >            final TimeUnit tu;
473 >            try {
474 >                tu = TimeUnit.of(cu);
475 >            } catch (IllegalArgumentException acceptable) {
476 >                continue;
477 >            }
478 >            assertSame(cu, tu.toChronoUnit());
479 >        }
480      }
481  
482   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines