< prev index next >

test/java/util/Calendar/SupplementalJapaneseEraTest.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 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. --- 1,7 ---- /* ! * Copyright (c) 2017, 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.
*** 58,69 **** import org.testng.annotations.Test; import static org.testng.Assert.*; public class SupplementalJapaneseEraTest { private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese"); ! private static final String NEW_ERA_NAME = "NewEra"; ! private static final String NEW_ERA_ABBR = "N.E."; private static final int NEW_ERA_YEAR = 200; private static final int NEW_ERA_MONTH = FEBRUARY; private static final int NEW_ERA_DAY = 11; private static int errors = 0; --- 58,69 ---- import org.testng.annotations.Test; import static org.testng.Assert.*; public class SupplementalJapaneseEraTest { private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese"); ! private static final String SUP_ERA_NAME = "SupEra"; ! private static final String SUP_ERA_ABBR = "S.E."; private static final int NEW_ERA_YEAR = 200; private static final int NEW_ERA_MONTH = FEBRUARY; private static final int NEW_ERA_DAY = 11; private static int errors = 0;
*** 94,104 **** // copied from JDK9's test private static void testProperty() { Calendar jcal = new Calendar.Builder() .setCalendarType("japanese") ! .setFields(YEAR, 1, DAY_OF_YEAR, 1) .build(); Date firstDayOfEra = jcal.getTime(); jcal.set(ERA, jcal.get(ERA) - 1); // previous era jcal.set(YEAR, 1); --- 94,104 ---- // copied from JDK9's test private static void testProperty() { Calendar jcal = new Calendar.Builder() .setCalendarType("japanese") ! .setFields(ERA, 6, YEAR, 1, DAY_OF_YEAR, 1) .build(); Date firstDayOfEra = jcal.getTime(); jcal.set(ERA, jcal.get(ERA) - 1); // previous era jcal.set(YEAR, 1);
*** 112,131 **** String expected, got; // test long era name sdf = new SimpleDateFormat("GGGG y-MM-dd", WAREKI_LOCALE); got = sdf.format(firstDayOfEra); ! expected = NEW_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } // 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("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } --- 112,131 ---- String expected, got; // test long era name sdf = new SimpleDateFormat("GGGG y-MM-dd", WAREKI_LOCALE); got = sdf.format(firstDayOfEra); ! expected = SUP_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } // test era abbreviation sdf = new SimpleDateFormat("G y-MM-dd", WAREKI_LOCALE); got = sdf.format(firstDayOfEra); ! expected = SUP_ERA_ABBR+" 1-02-11"; if (!expected.equals(got)) { System.err.printf("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; }
*** 138,183 **** } // test java.time.chrono.JapaneseEra JapaneseDate jdate = JapaneseDate.of(year, 2, 11); got = jdate.toString(); ! expected = "Japanese " + NEW_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("JapaneseDate: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } JapaneseEra jera = jdate.getEra(); got = jera.getDisplayName(TextStyle.FULL, Locale.US); ! if (!NEW_ERA_NAME.equals(got)) { ! System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.SHORT, Locale.US); ! if (!NEW_ERA_NAME.equals(got)) { ! System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.NARROW, Locale.US); ! if (!NEW_ERA_ABBR.equals(got)) { ! System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR); errors++; } 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++; } } --- 138,185 ---- } // test java.time.chrono.JapaneseEra JapaneseDate jdate = JapaneseDate.of(year, 2, 11); got = jdate.toString(); ! expected = "Japanese " + SUP_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("JapaneseDate: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } JapaneseEra jera = jdate.getEra(); got = jera.getDisplayName(TextStyle.FULL, Locale.US); ! if (!SUP_ERA_NAME.equals(got)) { ! System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.SHORT, Locale.US); ! if (!SUP_ERA_NAME.equals(got)) { ! System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.NARROW, Locale.US); ! if (!SUP_ERA_ABBR.equals(got)) { ! System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR); errors++; } got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US); ! if (!SUP_ERA_ABBR.equals(got)) { ! System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR); errors++; } // test long/abbreviated names with java.time.format got = new DateTimeFormatterBuilder() .appendPattern("GGGG") .appendLiteral(" ") .appendPattern("G") + .appendLiteral(" ") + .appendPattern("GGGGG") .toFormatter(Locale.US) .withChronology(JapaneseChronology.INSTANCE) .format(jdate); ! expected = SUP_ERA_NAME + " " + SUP_ERA_NAME + " " + SUP_ERA_ABBR; if (!expected.equals(got)) { System.err.printf("java.time formatter long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } }
*** 228,239 **** String eras = p.getProperty(JA_CAL_KEY); if (eras != null) { p.setProperty(JA_CAL_KEY, eras + ! "; name=" + SupplementalJapaneseEraTest.NEW_ERA_NAME + ! ",abbr=" + SupplementalJapaneseEraTest.NEW_ERA_ABBR + ",since=" + since()); } try (BufferedWriter bw = Files.newBufferedWriter(dst)) { p.store(bw, "test calendars.properties for supplemental Japanese era"); } --- 230,241 ---- String eras = p.getProperty(JA_CAL_KEY); if (eras != null) { p.setProperty(JA_CAL_KEY, eras + ! "; name=" + SupplementalJapaneseEraTest.SUP_ERA_NAME + ! ",abbr=" + SupplementalJapaneseEraTest.SUP_ERA_ABBR + ",since=" + since()); } try (BufferedWriter bw = Files.newBufferedWriter(dst)) { p.store(bw, "test calendars.properties for supplemental Japanese era"); }
*** 241,250 **** --- 243,253 ---- private long since() { return new Calendar.Builder() .setCalendarType("japanese") .setTimeZone(TimeZone.getTimeZone("GMT")) + .setFields(ERA, 5) .setDate(SupplementalJapaneseEraTest.NEW_ERA_YEAR, SupplementalJapaneseEraTest.NEW_ERA_MONTH, SupplementalJapaneseEraTest.NEW_ERA_DAY) .build() .getTimeInMillis();
< prev index next >