6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
< |
import junit.framework.*; |
9 |
> |
import static java.util.concurrent.TimeUnit.DAYS; |
10 |
> |
import static java.util.concurrent.TimeUnit.HOURS; |
11 |
> |
import static java.util.concurrent.TimeUnit.MICROSECONDS; |
12 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
13 |
> |
import static java.util.concurrent.TimeUnit.MINUTES; |
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 |
< |
import static java.util.concurrent.TimeUnit.*; |
20 |
> |
|
21 |
> |
import junit.framework.Test; |
22 |
> |
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() { |
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 |
|
} |