jdk/test/java/util/Calendar/SupplementalJapaneseEraTest.java
author okutsu
Thu, 15 Dec 2016 13:08:01 +0900
changeset 42696 a0df1f76b88e
parent 25966 71ee1f15845e
child 43338 f9c4f82a8265
permissions -rw-r--r--
8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era Reviewed-by: rriggs, naoto
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
/*
42696
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
     2
 * Copyright (c) 2014, 2016, 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;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    25
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
    26
import java.time.chrono.JapaneseEra;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
    27
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
    28
import java.util.Calendar;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    29
import java.util.Date;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    30
import java.util.GregorianCalendar;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    31
import static java.util.GregorianCalendar.*;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    32
import java.util.Locale;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    33
import java.util.TimeZone;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    34
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    35
/*
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    36
 * Usage:
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    37
 *   java SupplementalJapaneseEraTest <flag>
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    38
 *    <flag>
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    39
 *      -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
    40
 *      -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
    41
 *
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    42
 *   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
    43
 *      -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
    44
 *      -b <eraname>
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    45
 *           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
    46
 *           <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
    47
 */
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    48
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    49
public class SupplementalJapaneseEraTest {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    50
    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
    51
    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
    52
    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
    53
    private static int errors = 0;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    54
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    55
    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
    56
        // args[0] is a flag.
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    57
        switch (args[0]) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    58
        case "-s":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    59
            // 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
    60
            Calendar cal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    61
                .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    62
                .setTimeZone(TimeZone.getTimeZone("GMT"))
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    63
                .setDate(200, FEBRUARY, 11)
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    64
                .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    65
            System.out.println(cal.getTimeInMillis());
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    66
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    67
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    68
        case "-e":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    69
            // 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
    70
            Calendar jcal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    71
                .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    72
                .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
    73
                .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    74
            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
    75
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    76
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    77
        case "-t":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    78
            // 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
    79
            testProperty();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    80
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    81
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    82
        case "-b":
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    83
            // 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
    84
            // 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
    85
            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
    86
            break;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    87
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    88
        if (errors != 0) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    89
            throw new RuntimeException("test failed");
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    90
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    91
    }
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
    private static void testProperty() {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    94
        Calendar jcal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    95
            .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    96
            .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
    97
            .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    98
        Date firstDayOfEra = jcal.getTime();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
    99
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   100
        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
   101
        jcal.set(YEAR, 1);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   102
        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
   103
        Calendar cal = new GregorianCalendar();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   104
        cal.setTimeInMillis(jcal.getTimeInMillis());
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   105
        cal.add(YEAR, 199);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   106
        int year = cal.get(YEAR);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   107
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   108
        SimpleDateFormat sdf;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   109
        String expected, got;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   110
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   111
        // test long era name
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   112
        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
   113
        got = sdf.format(firstDayOfEra);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   114
        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
   115
        if (!expected.equals(got)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   116
            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
   117
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   118
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   119
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   120
        // test era abbreviation
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   121
        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
   122
        got = sdf.format(firstDayOfEra);
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   123
        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
   124
        if (!expected.equals(got)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   125
            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
   126
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   127
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   128
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   129
        // confirm the gregorian year
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   130
        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
   131
        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
   132
        if (y != year) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   133
            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
   134
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   135
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   136
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   137
        // test java.time.chrono.JapaneseEra
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   138
        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
   139
        got = jdate.toString();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   140
        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
   141
        if (!expected.equals(got)) {
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   142
            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
   143
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   144
        }
42696
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   145
        JapaneseEra jera = jdate.getEra();
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   146
        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
   147
        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
   148
            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
   149
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   150
        }
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   151
        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
   152
        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
   153
            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
   154
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   155
        }
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   156
        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
   157
        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
   158
            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
   159
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   160
        }
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   161
        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
   162
        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
   163
            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
   164
            errors++;
a0df1f76b88e 8054214: JapaneseEra.getDisplayName doesn't return names if it's an additional era
okutsu
parents: 25966
diff changeset
   165
        }
25966
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   166
    }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   167
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   168
    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
   169
        Calendar jcal = new Calendar.Builder()
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   170
            .setCalendarType("japanese")
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   171
            .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
   172
            .build();
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   173
        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
   174
            errors++;
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   175
            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
   176
            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
   177
        }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   178
    }
71ee1f15845e 8048123: Replace calendars.properties with another mechanism to specify a new Japanese calendar era
okutsu
parents:
diff changeset
   179
}