test/java/time/test/java/time/format/TestZoneTextPrinterParser.java

Print this page

        

@@ -21,37 +21,37 @@
  * questions.
  */
 
 package test.java.time.format;
 
+import static org.testng.Assert.assertEquals;
+
 import java.text.DateFormatSymbols;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatSymbols;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.TextStyle;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalQuery;
+import java.time.zone.ZoneRulesProvider;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Random;
 import java.util.Set;
 import java.util.TimeZone;
 
-import java.time.ZonedDateTime;
-import java.time.ZoneId;
-import java.time.temporal.ChronoField;
-import java.time.temporal.Queries;
-import java.time.format.DateTimeFormatSymbols;
-import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeFormatterBuilder;
-import java.time.format.TextStyle;
-import java.time.zone.ZoneRulesProvider;
-
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
 
 /**
  * Test ZoneTextPrinterParser
  */
-@Test(groups={"implementation"})
+@Test
 public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
 
     protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style) {
         return new DateTimeFormatterBuilder().appendZoneText(style)
                                              .toFormatter(locale)

@@ -68,39 +68,36 @@
         //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
         while (N-- > 0) {
             zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                      .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
             for (String zid : zids) {
-                if (zid.equals("ROC") ||
-                    zid.startsWith("UTC") ||
-                    zid.startsWith("GMT") || zid.startsWith("Etc/GMT")) {
-                    // UTC, GMT are treated as zone offset
+                if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                     continue;      // TBD: match jdk behavior?
                 }
                 zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
                 TimeZone tz = TimeZone.getTimeZone(zid);
                 boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
                 for (Locale locale : locales) {
-                    printText(locale, zdt, TextStyle.FULL,
+                    printText(locale, zdt, TextStyle.FULL, tz,
                               tz.getDisplayName(isDST, TimeZone.LONG, locale));
-                    printText(locale, zdt, TextStyle.SHORT,
+                    printText(locale, zdt, TextStyle.SHORT, tz,
                               tz.getDisplayName(isDST, TimeZone.SHORT, locale));
                 }
             }
         }
     }
 
-    private void printText(Locale locale, ZonedDateTime zdt, TextStyle style, String expected) {
+    private void printText(Locale locale, ZonedDateTime zdt, TextStyle style, TimeZone zone, String expected) {
         String result = getFormatter(locale, style).format(zdt);
         if (!result.equals(expected)) {
             if (result.equals("FooLocation")) { // from rules provider test if same vm
                 return;
             }
             System.out.println("----------------");
             System.out.printf("tdz[%s]%n", zdt.toString());
-            System.out.printf("[%-4s, %5s] :[%s]%n", locale.toString(), style.toString(),result);
-            System.out.printf("%4s, %5s  :[%s]%n", "", "", expected);
+            System.out.printf("[%-5s, %5s] :[%s]%n", locale.toString(), style.toString(),result);
+            System.out.printf(" %5s, %5s  :[%s] %s%n", "", "", expected, zone);
         }
         assertEquals(result, expected);
     }
 
     public void test_ParseText() {

@@ -151,11 +148,11 @@
     public void test_ParseText(String expected, String text, Set<ZoneId> preferred, Locale locale, TextStyle style) {
         DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneText(style, preferred)
                                                               .toFormatter(locale)
                                                               .withSymbols(DateTimeFormatSymbols.of(locale));
 
-        String ret = fmt.parse(text, Queries.zone()).getId();
+        String ret = fmt.parse(text, TemporalQuery.zone()).getId();
 
         System.out.printf("[%-5s %s] %24s -> %s(%s)%n",
                           locale.toString(),
                           style == TextStyle.FULL ? " full" :"short",
                           text, ret, expected);

@@ -187,11 +184,11 @@
                        String zid, String expected, String text,
                        Locale locale, TextStyle style, boolean ci) {
         if (ci) {
             text = text.toUpperCase();
         }
-        String ret = fmt.parse(text, Queries.zone()).getId();
+        String ret = fmt.parse(text, TemporalQuery.zone()).getId();
         // TBD: need an excluding list
         // assertEquals(...);
         if (ret.equals(expected) ||
             ret.equals(zid) ||
             ret.equals(ZoneName.toZid(zid)) ||