DO NOT MERGE New Japanese Era test changes in ojluni with a placeholder name

This integrates all upstream TEST changes up to OpenJDK 8u212-b01

It consists the following commits from upstream
- 8202088: Japanese new era implementation
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/bc0a3a91a074
- 8212941: Support new Japanese era in java.time.chrono.JapaneseEra
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/c35f231af17a
- 8171049: Era.getDisplayName doesn't work with non-IsoChronology
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/3cb43f3afe1c
- 8177678: Overstatement of universality of Era.getDisplayName() implementation
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/49bcab3213c1
- 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/0d9af9ca16e2

new Android-changed:
- JapaneseImperialCalendar.currentEra is changed to be hard-coded
because Zygote could initialize currentEra with incorrect system time.
- TestNonIsoFormatter#test_lenientEraYear is updated to use CLDR data

Bug: 138560701
Test: CtsLibcoreTestCases
Test: CtsLibcoreOjTestCases
Change-Id: I74b05bcbd39c5caec48c0de13e784127044b19ff
Merged-In: I74b05bcbd39c5caec48c0de13e784127044b19ff
diff --git a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
index 2bc1f4c..29714b3 100644
--- a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
+++ b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -111,6 +111,7 @@
  */
 @Test
 public class TCKJapaneseChronology {
+    private static final int YDIFF_NEWERA = 2018;
     private static final int YDIFF_HEISEI = 1988;
     private static final int YDIFF_MEIJI = 1867;
     private static final int YDIFF_SHOWA = 1925;
@@ -173,6 +174,7 @@
     @DataProvider(name="createByEra")
     Object[][] data_createByEra() {
         return new Object[][] {
+                {JapaneseEra.of(3), 2020 - YDIFF_NEWERA, 2, 29, 60, LocalDate.of(2020, 2, 29)}, // NEWERA
                 {JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(1996, 2, 29)},
                 {JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2000, 2, 29)},
                 {JapaneseEra.MEIJI, 1874 - YDIFF_MEIJI, 2, 28, 59, LocalDate.of(1874, 2, 28)},
@@ -365,8 +367,11 @@
     @DataProvider(name="prolepticYear")
     Object[][] data_prolepticYear() {
         return new Object[][] {
+                {3, JapaneseEra.of(3), 1, 1 + YDIFF_NEWERA, false}, // NEWERA
+                {3, JapaneseEra.of(3), 102, 102 + YDIFF_NEWERA, true}, // NEWERA
+
                 {2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false},
-                {2, JapaneseEra.HEISEI, 100, 100 + YDIFF_HEISEI, true},
+                {2, JapaneseEra.HEISEI, 4, 4 + YDIFF_HEISEI, true},
 
                 {-1, JapaneseEra.MEIJI, 9, 9 + YDIFF_MEIJI, true},
                 {-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false},
@@ -548,6 +553,7 @@
             { JapaneseEra.TAISHO, 0, "Taisho"},
             { JapaneseEra.SHOWA, 1, "Showa"},
             { JapaneseEra.HEISEI, 2, "Heisei"},
+            { JapaneseEra.of(3), 3, "NewEra"}, // NEWERA
         };
     }
 
@@ -562,7 +568,7 @@
 
     @Test
     public void test_Japanese_badEras() {
-        int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000};
+        int badEras[] = {-1000, -998, -997, -2, 4, 5, 1000};
         for (int badEra : badEras) {
             try {
                 Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
@@ -683,6 +689,7 @@
             {JapaneseChronology.INSTANCE.date(1989,  1,  7), "Japanese Showa 64-01-07"},
             {JapaneseChronology.INSTANCE.date(1989,  1,  8), "Japanese Heisei 1-01-08"},
             {JapaneseChronology.INSTANCE.date(2012, 12,  6), "Japanese Heisei 24-12-06"},
+            {JapaneseChronology.INSTANCE.date(2020,  1,  6), "Japanese NewEra 2-01-06"},
         };
     }
 
diff --git a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
index de83e1d..943520d 100644
--- a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
+++ b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -77,6 +77,7 @@
     @DataProvider(name = "JapaneseEras")
     Object[][] data_of_eras() {
         return new Object[][] {
+                    {JapaneseEra.of(3), "NewEra", 3}, // NEWERA
                     {JapaneseEra.HEISEI, "Heisei", 2},
                     {JapaneseEra.SHOWA, "Showa", 1},
                     {JapaneseEra.TAISHO, "Taisho", 0},
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
index 3fbf853..a1df28a 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, 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
@@ -58,6 +58,8 @@
             { JapaneseEra.SHOWA,      1, 12, 25, 1926 },
             { JapaneseEra.SHOWA,     64,  1,  7, 1989 },
             { JapaneseEra.HEISEI,     1,  1,  8, 1989 },
+            { JapaneseEra.HEISEI,    31,  4, 30, 2019 },
+            { JapaneseEra.of(3),      1,  5,  1, 2019 }, // NEWERA
         };
     }
 
@@ -74,6 +76,8 @@
             { JapaneseEra.SHOWA,  64,    7,  1,  7 },
             { JapaneseEra.HEISEI,  1,    1,  1,  8 },
             { JapaneseEra.HEISEI,  2,    8,  1,  8 },
+            { JapaneseEra.HEISEI, 31,  120,  4, 30 },
+            { JapaneseEra.of(3),   1,    1,  5,  1 }, // NEWERA
         };
     }
 
@@ -81,8 +85,8 @@
     Object[][] rangeData() {
         return new Object[][] {
             // field, minSmallest, minLargest, maxSmallest, maxLargest
-            { ChronoField.ERA,         -1, -1, 2, 2},
-            { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-1989 }, // depends on the current era
+            { ChronoField.ERA,         -1, -1, 3, 3},
+            { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-2019}, // depends on the current era
             { ChronoField.DAY_OF_YEAR, 1, 1, 7, 366},
             { ChronoField.YEAR, 1873, 1873, 999999999, 999999999},
         };
@@ -105,7 +109,9 @@
             { JapaneseEra.SHOWA,     65,  1,  1 },
             { JapaneseEra.HEISEI,     1,  1,  7 },
             { JapaneseEra.HEISEI,     1,  2, 29 },
-            { JapaneseEra.HEISEI, Year.MAX_VALUE,  12, 31 },
+            { JapaneseEra.HEISEI,    31,  5,  1 },
+            { JapaneseEra.of(3),      1,  4, 30 }, // NEWERA
+            { JapaneseEra.of(3), Year.MAX_VALUE,  12, 31 }, // NEWERA
         };
     }
 
@@ -124,7 +130,10 @@
             { JapaneseEra.SHOWA,     65 },
             { JapaneseEra.HEISEI,    -1 },
             { JapaneseEra.HEISEI,     0 },
-            { JapaneseEra.HEISEI, Year.MAX_VALUE },
+            { JapaneseEra.HEISEI,    32 },
+            { JapaneseEra.of(3),     -1 }, // NEWERA
+            { JapaneseEra.of(3),      0 }, // NEWERA
+            { JapaneseEra.of(3), Year.MAX_VALUE }, // NEWERA
         };
     }
 
@@ -141,6 +150,9 @@
             { JapaneseEra.SHOWA,  64,   8 },
             { JapaneseEra.HEISEI,  1, 360 },
             { JapaneseEra.HEISEI,  2, 366 },
+            { JapaneseEra.HEISEI, 31, 121 },
+            { JapaneseEra.of(3),   1, 246 }, // NEWERA
+            { JapaneseEra.of(3),   2, 367 }, // NEWERA
         };
     }
 
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java b/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
index ab61c71..cb987f6 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, 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
@@ -72,6 +72,7 @@
 /**
  * Tests for the Umm alQura chronology and data.
  * Note: The dates used for testing are just a sample of calendar data.
+ * @bug 8067800
  */
 @Test
 public class TestUmmAlQuraChronology {
@@ -548,6 +549,7 @@
         assertFalse(HijrahChronology.INSTANCE.isLeapYear(y), "Out of range leap year");
     }
 
+
     // Date samples to convert HijrahDate to LocalDate and vice versa
     @DataProvider(name="samples")
     Object[][] data_samples() {
@@ -773,8 +775,10 @@
             {HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"},
             {HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"},
             {HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"},
-            {HijrahDate.of(1500,6,12), "Japanese Heisei 89-05-05"},
-            {HijrahDate.of(1550,3,11), "Japanese Heisei 137-08-11"},
+            {HijrahDate.of(1440,8,25), "Japanese Heisei 31-04-30"},
+            {HijrahDate.of(1440,8,26), "Japanese NewEra 1-05-01"},
+            {HijrahDate.of(1500,6,12), "Japanese NewEra 59-05-05"},
+            {HijrahDate.of(1550,3,11), "Japanese NewEra 107-08-11"},
         };
     }
 
diff --git a/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java b/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
index 6609f2c..08635ea 100644
--- a/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
+++ b/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, 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
@@ -20,6 +20,13 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/*
+ *
+ * @test
+ * @bug 8206120
+ */
+
 package test.java.time.format;
 
 import static org.testng.Assert.assertEquals;
@@ -37,6 +44,7 @@
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.DateTimeParseException;
 import java.time.format.FormatStyle;
+import java.time.format.ResolverStyle;
 import java.time.format.TextStyle;
 import java.time.temporal.TemporalAccessor;
 import java.time.temporal.TemporalQueries;
@@ -134,6 +142,19 @@
         };
     }
 
+    @DataProvider(name="lenient_eraYear")
+    Object[][] lenientEraYear() {
+        return new Object[][] {
+            // Chronology, lenient era/year, strict era/year
+            { JAPANESE, "Meiji 123", "Heisei 2" },
+            // Android-changed: Eras names have been changed in CLDR data.
+            // { JAPANESE, "Showa 65", "Heisei 2" }
+            // { JAPANESE, "Heisei 32", "NewEra 2" }, // NewEra
+            { JAPANESE, "Shōwa 65", "Heisei 2" },
+            { JAPANESE, "Heisei 32", "Qqqq 2" }, // NewEra
+        };
+    }
+
     @Test(dataProvider="format_data")
     public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale,
                                          ChronoLocalDate date, String expected) {
@@ -172,4 +193,15 @@
         Chronology cal = ta.query(TemporalQueries.chronology());
         assertEquals(cal, chrono);
     }
+
+    @Test(dataProvider="lenient_eraYear")
+    public void test_lenientEraYear(Chronology chrono, String lenient, String strict) {
+        String mdStr = "-01-01";
+        DateTimeFormatter dtf = new DateTimeFormatterBuilder()
+            .appendPattern("GGGG y-M-d")
+            .toFormatter()
+            .withChronology(chrono);
+        DateTimeFormatter dtfLenient = dtf.withResolverStyle(ResolverStyle.LENIENT);
+        assertEquals(LocalDate.parse(lenient+mdStr, dtfLenient), LocalDate.parse(strict+mdStr, dtf));
+    }
 }