--- old/test/java/time/test/java/time/format/TestNonIsoFormatter.java 2019-02-20 18:40:23.057573200 +0530 +++ new/test/java/time/test/java/time/format/TestNonIsoFormatter.java 2019-02-20 18:40:22.108716500 +0530 @@ -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; @@ -128,6 +136,16 @@ }; } + @DataProvider(name="lenient_eraYear") + Object[][] lenientEraYear() { + return new Object[][] { + // Chronology, lenient era/year, strict era/year + { JAPANESE, "Meiji 123", "Heisei 2" }, + { JAPANESE, "Showa 65", "Heisei 2" }, + { JAPANESE, "Heisei 32", "NewEra 2" }, // NewEra + }; + } + @Test(dataProvider="format_data") public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale, ChronoLocalDate date, String expected) { @@ -166,4 +184,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)); +} }