1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.java.time.chrono;
  27 
  28 import java.time.*;
  29 import java.time.chrono.*;
  30 import java.time.format.*;
  31 import java.util.Locale;
  32 
  33 import org.testng.annotations.DataProvider;
  34 import org.testng.annotations.Test;
  35 import static org.testng.Assert.assertEquals;
  36 
  37 /**
  38  * Tests Era.getDisplayName() correctly returns the name based on each
  39  * chrono implementation.
  40  * Note: The exact result may depend on locale data provider's implementation.
  41  *
  42  * @bug 8171049
  43  */
  44 @Test
  45 public class TestEraDisplayName {
  46     private static final Locale THAI = Locale.forLanguageTag("th-TH");
  47     private static final Locale EGYPT = Locale.forLanguageTag("ar-EG");
  48 
  49     @DataProvider(name="eraDisplayName")
  50     Object[][] eraDisplayName() {
  51         return new Object[][] {
  52             // Era, text style, displyay locale, expected name
  53             // IsoEra
  54             { IsoEra.BCE,   TextStyle.FULL,     Locale.US,      "Before Christ" },
  55             { IsoEra.CE,    TextStyle.FULL,     Locale.US,      "Anno Domini" },
  56             { IsoEra.BCE,   TextStyle.FULL,     Locale.JAPAN,   "\u7d00\u5143\u524d" },
  57             { IsoEra.CE,    TextStyle.FULL,     Locale.JAPAN,   "\u897f\u66a6" },
  58             { IsoEra.BCE,   TextStyle.SHORT,    Locale.US,      "BC" },
  59             { IsoEra.CE,    TextStyle.SHORT,    Locale.US,      "AD" },
  60             { IsoEra.BCE,   TextStyle.SHORT,    Locale.JAPAN,   "\u7d00\u5143\u524d" },
  61             { IsoEra.CE,    TextStyle.SHORT,    Locale.JAPAN,   "\u897f\u66a6" },
  62             { IsoEra.BCE,   TextStyle.NARROW,   Locale.US,      "B" },
  63             { IsoEra.CE,    TextStyle.NARROW,   Locale.US,      "A" },
  64             { IsoEra.BCE,   TextStyle.NARROW,   Locale.JAPAN,   "BC" },
  65             { IsoEra.CE,    TextStyle.NARROW,   Locale.JAPAN,   "AD" },
  66 
  67             // JapaneseEra
  68             { JapaneseEra.MEIJI,    TextStyle.FULL,     Locale.US,      "Meiji" },
  69             { JapaneseEra.TAISHO,   TextStyle.FULL,     Locale.US,      "Taisho" },
  70             { JapaneseEra.SHOWA,    TextStyle.FULL,     Locale.US,      "Showa" },
  71             { JapaneseEra.HEISEI,   TextStyle.FULL,     Locale.US,      "Heisei" },
  72             { JapaneseEra.MEIJI,    TextStyle.FULL,     Locale.JAPAN,   "\u660e\u6cbb" },
  73             { JapaneseEra.TAISHO,   TextStyle.FULL,     Locale.JAPAN,   "\u5927\u6b63" },
  74             { JapaneseEra.SHOWA,    TextStyle.FULL,     Locale.JAPAN,   "\u662d\u548c" },
  75             { JapaneseEra.HEISEI,   TextStyle.FULL,     Locale.JAPAN,   "\u5e73\u6210" },
  76             { JapaneseEra.MEIJI,    TextStyle.SHORT,    Locale.US,      "Meiji" },
  77             { JapaneseEra.TAISHO,   TextStyle.SHORT,    Locale.US,      "Taisho" },
  78             { JapaneseEra.SHOWA,    TextStyle.SHORT,    Locale.US,      "Showa" },
  79             { JapaneseEra.HEISEI,   TextStyle.SHORT,    Locale.US,      "Heisei" },
  80             { JapaneseEra.MEIJI,    TextStyle.SHORT,    Locale.JAPAN,   "\u660e\u6cbb" },
  81             { JapaneseEra.TAISHO,   TextStyle.SHORT,    Locale.JAPAN,   "\u5927\u6b63" },
  82             { JapaneseEra.SHOWA,    TextStyle.SHORT,    Locale.JAPAN,   "\u662d\u548c" },
  83             { JapaneseEra.HEISEI,   TextStyle.SHORT,    Locale.JAPAN,   "\u5e73\u6210" },
  84             { JapaneseEra.MEIJI,    TextStyle.NARROW,   Locale.US,      "M" },
  85             { JapaneseEra.TAISHO,   TextStyle.NARROW,   Locale.US,      "T" },
  86             { JapaneseEra.SHOWA,    TextStyle.NARROW,   Locale.US,      "S" },
  87             { JapaneseEra.HEISEI,   TextStyle.NARROW,   Locale.US,      "H" },
  88             { JapaneseEra.MEIJI,    TextStyle.NARROW,   Locale.JAPAN,   "M" },
  89             { JapaneseEra.TAISHO,   TextStyle.NARROW,   Locale.JAPAN,   "T" },
  90             { JapaneseEra.SHOWA,    TextStyle.NARROW,   Locale.JAPAN,   "S" },
  91             { JapaneseEra.HEISEI,   TextStyle.NARROW,   Locale.JAPAN,   "H" },
  92 
  93             // ThaiBuddhistEra
  94             { ThaiBuddhistEra.BEFORE_BE,    TextStyle.FULL, Locale.US,      "BC" },
  95             { ThaiBuddhistEra.BE,           TextStyle.FULL, Locale.US,      "BE" },
  96             { ThaiBuddhistEra.BEFORE_BE,    TextStyle.FULL, THAI,           "BC" },
  97             { ThaiBuddhistEra.BE,           TextStyle.FULL, THAI,
  98                 "\u0e1e\u0e38\u0e17\u0e18\u0e28\u0e31\u0e01\u0e23\u0e32\u0e0a" },
  99             { ThaiBuddhistEra.BEFORE_BE,    TextStyle.SHORT, Locale.US,     "BC" },
 100             { ThaiBuddhistEra.BE,           TextStyle.SHORT, Locale.US,     "BE" },
 101             { ThaiBuddhistEra.BEFORE_BE,    TextStyle.SHORT, THAI,
 102                 "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a" +
 103                 "\u0e15\u0e4c\u0e01\u0e32\u0e25\u0e17\u0e35\u0e48" },
 104             { ThaiBuddhistEra.BE,           TextStyle.SHORT, THAI,  "\u0e1e.\u0e28." },
 105             { ThaiBuddhistEra.BEFORE_BE,    TextStyle.NARROW, Locale.US,    "BC" },
 106             { ThaiBuddhistEra.BE,           TextStyle.NARROW, Locale.US,    "BE" },
 107             { ThaiBuddhistEra.BEFORE_BE,    TextStyle.NARROW, THAI,         "BC" },
 108             { ThaiBuddhistEra.BE,           TextStyle.NARROW, THAI,         "\u0e1e.\u0e28." },
 109 
 110             // MinguoEra
 111             { MinguoEra.BEFORE_ROC, TextStyle.FULL,     Locale.US,      "Before R.O.C." },
 112             { MinguoEra.ROC,        TextStyle.FULL,     Locale.US,      "Minguo" },
 113             { MinguoEra.BEFORE_ROC, TextStyle.FULL,     Locale.TAIWAN,  "\u6c11\u570b\u524d" },
 114             { MinguoEra.ROC,        TextStyle.FULL,     Locale.TAIWAN,  "\u6c11\u570b" },
 115             { MinguoEra.BEFORE_ROC, TextStyle.SHORT,    Locale.US,      "Before R.O.C." },
 116             { MinguoEra.ROC,        TextStyle.SHORT,    Locale.US,      "Minguo" },
 117             { MinguoEra.BEFORE_ROC, TextStyle.SHORT,    Locale.TAIWAN,  "\u6c11\u570b\u524d" },
 118             { MinguoEra.ROC,        TextStyle.SHORT,    Locale.TAIWAN,  "\u6c11\u570b" },
 119             { MinguoEra.BEFORE_ROC, TextStyle.NARROW,   Locale.US,      "Before R.O.C." },
 120             { MinguoEra.ROC,        TextStyle.NARROW,   Locale.US,      "Minguo" },
 121             { MinguoEra.BEFORE_ROC, TextStyle.NARROW,   Locale.TAIWAN,  "\u6c11\u570b\u524d" },
 122             { MinguoEra.ROC,        TextStyle.NARROW,   Locale.TAIWAN,  "\u6c11\u570b" },
 123 
 124             // HijrahEra
 125             { HijrahEra.AH, TextStyle.FULL,     Locale.US,  "AH" },
 126             { HijrahEra.AH, TextStyle.FULL,     EGYPT,      "\u0647\u0640" },
 127             { HijrahEra.AH, TextStyle.SHORT,    Locale.US,  "AH" },
 128             { HijrahEra.AH, TextStyle.SHORT,    EGYPT,      "\u0647\u0640" },
 129             { HijrahEra.AH, TextStyle.NARROW,   Locale.US,  "AH" },
 130             { HijrahEra.AH, TextStyle.NARROW,   EGYPT,      "\u0647\u0640" },
 131         };
 132     }
 133 
 134     @Test(dataProvider="eraDisplayName")
 135     public void test_eraDisplayName(Era era, TextStyle style, Locale locale, String expected) {
 136         assertEquals(era.getDisplayName(style, locale), expected);
 137     }
 138 }