test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java
changeset 52234 5bd3a6017943
parent 50478 2e3f73b616c2
equal deleted inserted replaced
52233:d682023cdd8c 52234:5bd3a6017943
    30 import java.util.Calendar;
    30 import java.util.Calendar;
    31 import java.util.Date;
    31 import java.util.Date;
    32 import java.util.GregorianCalendar;
    32 import java.util.GregorianCalendar;
    33 import static java.util.GregorianCalendar.*;
    33 import static java.util.GregorianCalendar.*;
    34 import java.util.Locale;
    34 import java.util.Locale;
    35 import java.util.TimeZone;
       
    36 
    35 
    37 /*
    36 /*
    38  * Usage:
    37  * Usage:
    39  *   java SupplementalJapaneseEraTest <flag>
       
    40  *    <flag>
       
    41  *      -s   prints start time for a test era
       
    42  *      -e   prints the English name of the last predefined era
       
    43  *
       
    44  *   java -Djdk.calendar.japanese.supplemental.era=... SupplementalJapaneseEraTest <flag>
    38  *   java -Djdk.calendar.japanese.supplemental.era=... SupplementalJapaneseEraTest <flag>
    45  *      -t   executes tests with a valid property value
    39  *      -t   executes tests with a valid property value
    46  *      -b <eraname>
    40  *      -b <eraname>
    47  *           executes tests with an invalid property value
    41  *           executes tests with an invalid property value
    48  *           <eraname> must be the output with -e
       
    49  */
    42  */
    50 
    43 
    51 public class SupplementalJapaneseEraTest {
    44 public class SupplementalJapaneseEraTest {
    52     private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese");
    45     private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese");
    53     private static final String SUP_ERA_NAME = "SupEra";
    46     private static final String SUP_ERA_NAME = "SupEra";
    55     private static int errors = 0;
    48     private static int errors = 0;
    56 
    49 
    57     public static void main(String[] args) {
    50     public static void main(String[] args) {
    58         // args[0] is a flag.
    51         // args[0] is a flag.
    59         switch (args[0]) {
    52         switch (args[0]) {
    60         case "-s":
       
    61             // print the start time of the new era for testing
       
    62             Calendar cal = new Calendar.Builder()
       
    63                 .setCalendarType("japanese")
       
    64                 .setTimeZone(TimeZone.getTimeZone("GMT"))
       
    65                 .setFields(ERA, 5)
       
    66                 .setDate(200, FEBRUARY, 11)
       
    67                 .build();
       
    68             System.out.println(cal.getTimeInMillis());
       
    69             break;
       
    70 
       
    71         case "-e":
       
    72             // print the current era name in English
       
    73             Calendar jcal = new Calendar.Builder()
       
    74                 .setCalendarType("japanese")
       
    75                 .setFields(YEAR, 1, DAY_OF_YEAR, 1)
       
    76                 .build();
       
    77             System.out.println(jcal.getDisplayName(ERA, LONG, Locale.US));
       
    78             break;
       
    79 
       
    80         case "-t":
    53         case "-t":
    81             // test with a valid property value
    54             // test with a valid property value
    82             testProperty();
    55             testProperty();
    83             break;
    56             break;
    84 
    57 
    85         case "-b":
    58         case "-b":
    86             // test with an invalid property value
    59             // test with an invalid property value
    87             // args[1] is the current era name given by -e.
    60             // args[1] is the current era name.
    88             testValidation(args[1].replace("\r", "")); // remove any CR for Cygwin
    61             testValidation(args[1].replace("\r", "")); // remove any CR for Cygwin
    89             break;
    62             break;
    90         }
    63         }
    91         if (errors != 0) {
    64         if (errors != 0) {
    92             throw new RuntimeException("test failed");
    65             throw new RuntimeException("test failed");