< prev index next >
test/java/time/test/java/time/format/TestNonIsoFormatter.java
Print this page
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -18,10 +18,17 @@
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* 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;
import java.time.LocalDate;
@@ -35,10 +42,11 @@
import java.time.format.DecimalStyle;
import java.time.format.DateTimeFormatter;
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;
import java.util.Locale;
@@ -126,10 +134,20 @@
+ "\u0627\u0644\u0647\u062c\u0631\u064a\u060c "
+ "\u0623\u0645 \u0627\u0644\u0642\u0631\u0649" }, // JDK-8015986
};
}
+ @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) {
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
.withChronology(chrono).withLocale(formatLocale)
@@ -164,6 +182,17 @@
assertEquals(text, expected);
TemporalAccessor ta = dtf.parse(text);
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));
+}
}
< prev index next >