< prev index next >

test/java/util/concurrent/TimeUnit/Basic.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -20,11 +20,11 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 /* @test
- * @bug 5057341 6363898
+ * @bug 5057341 6363898 8141452
  * @summary Basic tests for TimeUnit
  * @author Martin Buchholz
  */
 
 import static java.util.concurrent.TimeUnit.DAYS;

@@ -39,10 +39,11 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectInputStream;
+import java.time.temporal.ChronoUnit;
 import java.util.Arrays;
 import java.util.concurrent.TimeUnit;
 
 public class Basic {
     private static void realMain(String[] args) throws Throwable {

@@ -115,6 +116,57 @@
     static Object readObject(byte[] bytes)
         throws IOException, ClassNotFoundException {
         InputStream is = new ByteArrayInputStream(bytes);
         return new ObjectInputStream(is).readObject();
     }
+
+    //-----------------------------------------------------------------------
+    // toChronoUnit(), of()
+    //-----------------------------------------------------------------------`
+    @DataProvider(name = "convertedUnit")
+    Object[][] data_convertedUnit() {
+        return new Object[][] {
+                {NANOSECONDS, ChronoUnit.NANOS, true},
+                {MICROSECONDS, ChronoUnit.MICROS, true},
+                {MILLISECONDS, ChronoUnit.MILLIS, true},
+                {SECONDS, ChronoUnit.SECONDS, true},
+                {MINUTES, ChronoUnit.MINUTES, true},
+                {HOURS, ChronoUnit.HOURS, true},
+                {DAYS, ChronoUnit.DAYS, true},
+
+                {NANOSECONDS, ChronoUnit.MINUTES, false},
+                {MICROSECONDS, ChronoUnit.SECONDS, false},
+                {MILLISECONDS, ChronoUnit.HOURS, false},
+                {SECONDS, ChronoUnit.MICROS, false},
+                {MINUTES, ChronoUnit.MILLIS, false},
+                {HOURS, ChronoUnit.DAYS, false},
+                {DAYS, ChronoUnit.NANOS, false},
+        };
+    }
+
+    @Test(dataProvider = "convertedUnit")
+    public void test_toChronoUnit(TimeUnit timeUnit, ChronoUnit chronoUnit, boolean expected) {
+        assertEquals(TimeUnit.toChronoUnit(timeUnit).equals(chronoUnit), expected);
+    }
+
+    @Test(expectedExceptions=NullPointerException.class)
+    public void test_toChronoUnit_null() {
+        TimeUnit.toChronoUnit(null);
+    }
+
+    @Test(dataProvider = "convertedUnit")
+    public void test_of(TimeUnit timeUnit, ChronoUnit chronoUnit, boolean expected) {
+        assertEquals(TimeUnit.of(chronoUnit).equals(timeUnit), expected);
+
+    }
+
+    @Test(expectedExceptions=NullPointerException.class)
+    public void test_of_null() {
+        TimeUnit.of(null);
+    }
+
+    @Test(expectedExceptions=IllegalArgumentException.class)
+    public void test_of_illegalArg() {
+        TimeUnit.of(ChronoUnit.ERAS);
+
+    }
 }
< prev index next >