< prev index next >

test/java/util/Calendar/SupplementalJapaneseEraTest.java

Print this page
rev 16588 : [mq]: 8173423

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, 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,12 +20,14 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 import java.text.SimpleDateFormat;
+import java.time.chrono.JapaneseChronology;
 import java.time.chrono.JapaneseDate;
 import java.time.chrono.JapaneseEra;
+import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.TextStyle;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import static java.util.GregorianCalendar.*;

@@ -120,11 +122,11 @@
         // test era abbreviation
         sdf = new SimpleDateFormat("G y-MM-dd", WAREKI_LOCALE);
         got = sdf.format(firstDayOfEra);
         expected = NEW_ERA_ABBR+" 1-02-11";
         if (!expected.equals(got)) {
-            System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected);
+            System.err.printf("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected);
             errors++;
         }
 
         // confirm the gregorian year
         sdf = new SimpleDateFormat("y", Locale.US);

@@ -161,10 +163,24 @@
         got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US);
         if (!NEW_ERA_ABBR.equals(got)) {
             System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR);
             errors++;
         }
+
+        // test long/abbreviated names with java.time.format
+        got = new DateTimeFormatterBuilder()
+            .appendPattern("GGGG")
+            .appendLiteral(" ")
+            .appendPattern("G")
+            .toFormatter(Locale.US)
+            .withChronology(JapaneseChronology.INSTANCE)
+            .format(jdate);
+        expected = NEW_ERA_NAME + " " + NEW_ERA_ABBR;
+        if (!expected.equals(got)) {
+            System.err.printf("java.time formatter long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected);
+            errors++;
+        }
     }
 
     private static void testValidation(String eraName) {
         Calendar jcal = new Calendar.Builder()
             .setCalendarType("japanese")
< prev index next >