test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 47030 jdk/test/java/util/Calendar/SupplementalJapaneseEraTest.java@d548b7a9ba3e
child 50478 2e3f73b616c2
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     1
/*
43338
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
     2
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     4
 *
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     8
 *
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    13
 * accompanied this code).
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    14
 *
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    18
 *
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    21
 * questions.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    22
 */
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    23
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    24
import java.text.SimpleDateFormat;
43338
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
    25
import java.time.chrono.JapaneseChronology;
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    26
import java.time.chrono.JapaneseDate;
42696
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
    27
import java.time.chrono.JapaneseEra;
47030
d548b7a9ba3e 8180469: Wrong short form text for supplemental Japanese era
naoto
parents: 43338
diff changeset
    28
import java.time.format.DateTimeFormatter;
42696
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
    29
import java.time.format.TextStyle;
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    30
import java.util.Calendar;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    31
import java.util.Date;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    32
import java.util.GregorianCalendar;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    33
import static java.util.GregorianCalendar.*;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    34
import java.util.Locale;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    35
import java.util.TimeZone;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    36
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    37
/*
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    38
 * Usage:
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    39
 *   java SupplementalJapaneseEraTest <flag>
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    40
 *    <flag>
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    41
 *      -s   prints start time for a test era
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    42
 *      -e   prints the English name of the last predefined era
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    43
 *
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    44
 *   java -Djdk.calendar.japanese.supplemental.era=... SupplementalJapaneseEraTest <flag>
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    45
 *      -t   executes tests with a valid property value
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    46
 *      -b <eraname>
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    47
 *           executes tests with an invalid property value
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    48
 *           <eraname> must be the output with -e
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    49
 */
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    50
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    51
public class SupplementalJapaneseEraTest {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    52
    private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese");
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    53
    private static final String NEW_ERA_NAME = "NewEra";
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    54
    private static final String NEW_ERA_ABBR = "N.E.";
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    55
    private static int errors = 0;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    56
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    57
    public static void main(String[] args) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    58
        // args[0] is a flag.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    59
        switch (args[0]) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    60
        case "-s":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    61
            // print the start time of the new era for testing
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    62
            Calendar cal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    63
                .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    64
                .setTimeZone(TimeZone.getTimeZone("GMT"))
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    65
                .setDate(200, FEBRUARY, 11)
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    66
                .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    67
            System.out.println(cal.getTimeInMillis());
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    68
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    69
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    70
        case "-e":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    71
            // print the current era name in English
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    72
            Calendar jcal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    73
                .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    74
                .setFields(YEAR, 1, DAY_OF_YEAR, 1)
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    75
                .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    76
            System.out.println(jcal.getDisplayName(ERA, LONG, Locale.US));
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    77
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    78
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    79
        case "-t":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    80
            // test with a valid property value
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    81
            testProperty();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    82
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    83
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    84
        case "-b":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    85
            // test with an invalid property value
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    86
            // args[1] is the current era name given by -e.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    87
            testValidation(args[1].replace("\r", "")); // remove any CR for Cygwin
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    88
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    89
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    90
        if (errors != 0) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    91
            throw new RuntimeException("test failed");
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    92
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    93
    }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    94
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    95
    private static void testProperty() {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    96
        Calendar jcal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    97
            .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    98
            .setFields(YEAR, 1, DAY_OF_YEAR, 1)
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    99
            .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   100
        Date firstDayOfEra = jcal.getTime();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   101
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   102
        jcal.set(ERA, jcal.get(ERA) - 1); // previous era
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   103
        jcal.set(YEAR, 1);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   104
        jcal.set(DAY_OF_YEAR, 1);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   105
        Calendar cal = new GregorianCalendar();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   106
        cal.setTimeInMillis(jcal.getTimeInMillis());
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   107
        cal.add(YEAR, 199);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   108
        int year = cal.get(YEAR);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   109
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   110
        SimpleDateFormat sdf;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   111
        String expected, got;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   112
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   113
        // test long era name
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   114
        sdf = new SimpleDateFormat("GGGG y-MM-dd", WAREKI_LOCALE);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   115
        got = sdf.format(firstDayOfEra);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   116
        expected = NEW_ERA_NAME + " 1-02-11";
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   117
        if (!expected.equals(got)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   118
            System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   119
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   120
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   121
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   122
        // test era abbreviation
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   123
        sdf = new SimpleDateFormat("G y-MM-dd", WAREKI_LOCALE);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   124
        got = sdf.format(firstDayOfEra);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   125
        expected = NEW_ERA_ABBR+" 1-02-11";
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   126
        if (!expected.equals(got)) {
43338
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
   127
            System.err.printf("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected);
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   128
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   129
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   130
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   131
        // confirm the gregorian year
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   132
        sdf = new SimpleDateFormat("y", Locale.US);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   133
        int y = Integer.parseInt(sdf.format(firstDayOfEra));
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   134
        if (y != year) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   135
            System.err.printf("Gregorian year: got=%d, expected=%d%n", y, year);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   136
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   137
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   138
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   139
        // test java.time.chrono.JapaneseEra
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   140
        JapaneseDate jdate = JapaneseDate.of(year, 2, 11);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   141
        got = jdate.toString();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   142
        expected = "Japanese " + NEW_ERA_NAME + " 1-02-11";
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   143
        if (!expected.equals(got)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   144
            System.err.printf("JapaneseDate: got=\"%s\", expected=\"%s\"%n", got, expected);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   145
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   146
        }
42696
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   147
        JapaneseEra jera = jdate.getEra();
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   148
        got = jera.getDisplayName(TextStyle.FULL, Locale.US);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   149
        if (!NEW_ERA_NAME.equals(got)) {
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   150
            System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   151
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   152
        }
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   153
        got = jera.getDisplayName(TextStyle.SHORT, Locale.US);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   154
        if (!NEW_ERA_NAME.equals(got)) {
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   155
            System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   156
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   157
        }
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   158
        got = jera.getDisplayName(TextStyle.NARROW, Locale.US);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   159
        if (!NEW_ERA_ABBR.equals(got)) {
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   160
            System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   161
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   162
        }
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   163
        got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   164
        if (!NEW_ERA_ABBR.equals(got)) {
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   165
            System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR);
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   166
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   167
        }
43338
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
   168
47030
d548b7a9ba3e 8180469: Wrong short form text for supplemental Japanese era
naoto
parents: 43338
diff changeset
   169
        // test full/short/narrow names with java.time.format
d548b7a9ba3e 8180469: Wrong short form text for supplemental Japanese era
naoto
parents: 43338
diff changeset
   170
        got = DateTimeFormatter
d548b7a9ba3e 8180469: Wrong short form text for supplemental Japanese era
naoto
parents: 43338
diff changeset
   171
            .ofPattern("GGGG G GGGGG")
d548b7a9ba3e 8180469: Wrong short form text for supplemental Japanese era
naoto
parents: 43338
diff changeset
   172
            .withLocale(Locale.US)
43338
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
   173
            .withChronology(JapaneseChronology.INSTANCE)
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
   174
            .format(jdate);
47030
d548b7a9ba3e 8180469: Wrong short form text for supplemental Japanese era
naoto
parents: 43338
diff changeset
   175
        expected = NEW_ERA_NAME + " " + NEW_ERA_NAME + " " + NEW_ERA_ABBR;
43338
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
   176
        if (!expected.equals(got)) {
47030
d548b7a9ba3e 8180469: Wrong short form text for supplemental Japanese era
naoto
parents: 43338
diff changeset
   177
            System.err.printf("java.time formatter full/short/narrow names: got=\"%s\", expected=\"%s\"%n", got, expected);
43338
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
   178
            errors++;
f9c4f82a8265 8173423: Wrong display name for supplemental Japanese era
naoto
parents: 42696
diff changeset
   179
        }
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   180
    }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   181
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   182
    private static void testValidation(String eraName) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   183
        Calendar jcal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   184
            .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   185
            .setFields(YEAR, 1, DAY_OF_YEAR, 1)
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   186
            .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   187
        if (!jcal.getDisplayName(ERA, LONG, Locale.US).equals(eraName)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   188
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   189
            String prop = System.getProperty("jdk.calendar.japanese.supplemental.era");
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   190
            System.err.println("Era changed with invalid property: " + prop);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   191
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   192
    }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   193
}