changeset 7023:8c06a38aa2c5

8012638: test/java/time/test/java/util/TestFormatter fails in UTC TZ Summary: updated the offending test case Reviewed-by: alanb
author sherman
date Wed, 24 Apr 2013 21:27:52 +0000
parents bbcebf893b83
children 4da1d43f5843 d8f01bfb1da4
files test/java/time/test/java/util/TestFormatter.java
diffstat 1 files changed, 30 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/time/test/java/util/TestFormatter.java	Wed Apr 24 19:03:07 2013 +0100
+++ b/test/java/time/test/java/util/TestFormatter.java	Wed Apr 24 21:27:52 2013 +0000
@@ -25,6 +25,7 @@
 import java.time.Instant;
 import java.time.OffsetDateTime;
 import java.time.ZonedDateTime;
+import java.time.ZoneId;
 import java.time.temporal.ChronoField;
 
 import java.util.*;
@@ -34,6 +35,7 @@
 
 /* @test
  * @summary Unit test for j.u.Formatter threeten date/time support
+ * @bug 8003680 8012638
  */
 @Test
 public class TestFormatter {
@@ -64,25 +66,33 @@
         //locales = Locale.getAvailableLocales();
         Locale[] locales = new Locale[] {
            Locale.ENGLISH, Locale.FRENCH, Locale.JAPANESE, Locale.CHINESE};
+        Random r = new Random();
+        ZonedDateTime  zdt0 = ZonedDateTime.now();
+        ZonedDateTime[] zdts = new ZonedDateTime[] {
+            zdt0,
+            zdt0.withZoneSameLocal(ZoneId.of("UTC")),
+            zdt0.withZoneSameLocal(ZoneId.of("GMT")),
+            zdt0.withZoneSameLocal(ZoneId.of("UT")),
+        };
 
-        Random r = new Random();
-        ZonedDateTime  zdt = ZonedDateTime.now();
         while (N-- > 0) {
-            zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
-                     .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
-            Instant instant = zdt.toInstant();
-            Calendar cal = Calendar.getInstance();
-            cal.setTimeInMillis(instant.toEpochMilli());
-
-            for (Locale locale : locales) {
+            for (ZonedDateTime zdt : zdts) {
+                zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
+                         .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
+                Instant instant = zdt.toInstant();
+                Calendar cal = Calendar.getInstance();
+                cal.setTimeInMillis(instant.toEpochMilli());
+                cal.setTimeZone(TimeZone.getTimeZone(zdt.getZone()));
+                for (Locale locale : locales) {
                     for (String fmtStr : fmtStrDate) {
-                    testDate(fmtStr, locale, zdt, cal);
+                        testDate(fmtStr, locale, zdt, cal);
+                    }
+                    for (String fmtStr : fmtStrTime) {
+                        testTime(fmtStr, locale, zdt, cal);
+                    }
+                    testZoneId(locale, zdt, cal);
+                    testInstant(locale, instant, zdt, cal);
                 }
-                for (String fmtStr : fmtStrTime) {
-                    testTime(fmtStr, locale, zdt, cal);
-                }
-                testZoneId(locale, zdt, cal);
-                testInstant(locale, instant, zdt, cal);
             }
         }
         if (verbose) {
@@ -146,6 +156,10 @@
     }
 
     private String toZoneIdStr(String expected) {
+        return expected.replaceAll("(?:GMT|UTC)(?<off>[+\\-]?[0-9]{2}:[0-9]{2})", "${off}");
+    }
+
+    private String toZoneOffsetStr(String expected) {
         return expected.replaceAll("(?:GMT|UTC)(?<off>[+\\-]?[0-9]{2}:[0-9]{2})", "${off}")
                        .replaceAll("GMT|UTC|UT", "Z");
     }
@@ -159,7 +173,7 @@
         Calendar cal0 = Calendar.getInstance();
         cal0.setTimeInMillis(zdt.toInstant().toEpochMilli());
         cal0.setTimeZone(TimeZone.getTimeZone("GMT" + zdt.getOffset().getId()));
-        expected = toZoneIdStr(test(fmtStr, locale, null, cal0));
+        expected = toZoneOffsetStr(test(fmtStr, locale, null, cal0));
         test(fmtStr, locale, expected, zdt.toOffsetDateTime());
         test(fmtStr, locale, expected, zdt.toOffsetDateTime().toOffsetTime());