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