8042131: DateTimeFormatterBuilder Mapped-values do not work for JapaneseDate
authornaoto
Tue, 19 Jun 2018 08:19:54 -0700
changeset 50643 f2d94a0619a2
parent 50642 fff48b02d4a6
child 50644 409bfb0c071e
child 50660 9d7f647a2b6d
child 56783 7add69e2fb68
8042131: DateTimeFormatterBuilder Mapped-values do not work for JapaneseDate Reviewed-by: rriggs, scolebourne Contributed-by: toshiona@jp.ibm.com
src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
test/jdk/java/time/test/java/time/format/TestDateTimeFormatterBuilderWithLocale.java
--- a/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java	Tue Jun 19 18:18:46 2018 +0300
+++ b/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java	Tue Jun 19 08:19:54 2018 -0700
@@ -793,6 +793,11 @@
         final LocaleStore store = new LocaleStore(map);
         DateTimeTextProvider provider = new DateTimeTextProvider() {
             @Override
+            public String getText(Chronology chrono, TemporalField field,
+                                  long value, TextStyle style, Locale locale) {
+                return store.getText(value, style);
+            }
+            @Override
             public String getText(TemporalField field, long value, TextStyle style, Locale locale) {
                 return store.getText(value, style);
             }
--- a/test/jdk/java/time/test/java/time/format/TestDateTimeFormatterBuilderWithLocale.java	Tue Jun 19 18:18:46 2018 +0300
+++ b/test/jdk/java/time/test/java/time/format/TestDateTimeFormatterBuilderWithLocale.java	Tue Jun 19 08:19:54 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, 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
@@ -64,17 +64,23 @@
  */
 package test.java.time.format;
 
+import java.time.chrono.ChronoLocalDate;
 import java.time.chrono.Chronology;
 import java.time.chrono.IsoChronology;
 import java.time.chrono.JapaneseChronology;
+import java.time.chrono.JapaneseEra;
 import java.time.chrono.MinguoChronology;
+import java.time.chrono.ThaiBuddhistChronology;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.FormatStyle;
 import java.time.LocalDate;
+import java.time.temporal.ChronoField;
 import java.time.temporal.Temporal;
 
+import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map;
 
 import static org.testng.Assert.assertEquals;
 
@@ -115,6 +121,29 @@
     }
 
     //-----------------------------------------------------------------------
+    @DataProvider(name="mapTextLookup")
+    Object[][] data_mapTextLookup() {
+        return new Object[][] {
+            {IsoChronology.INSTANCE.date(1, 1, 1), Locale.ENGLISH},
+            {JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 1, 1, 8), Locale.ENGLISH},
+            {MinguoChronology.INSTANCE.date(1, 1, 1), Locale.ENGLISH},
+            {ThaiBuddhistChronology.INSTANCE.date(1, 1, 1), Locale.ENGLISH},
+        };
+    }
+
+    @Test(dataProvider="mapTextLookup")
+    public void test_appendText_mapTextLookup(ChronoLocalDate date, Locale locale) {
+        final String new1st = "1st";
+        Map<Long, String> yearMap = new HashMap<>();
+        yearMap.put(1L, new1st);
+        builder.appendText(ChronoField.YEAR_OF_ERA, yearMap);
+
+        String actual = date.format(builder.toFormatter(locale));
+        assertEquals(actual, new1st);
+    }
+
+
+    //-----------------------------------------------------------------------
     @DataProvider(name="localePatterns")
     Object[][] localizedDateTimePatterns() {
         return new Object[][] {