< prev index next >

test/jdk/java/util/Locale/LocaleProviders.java

Print this page
rev 55815 : [mq]: 8228465

@@ -26,10 +26,12 @@
 import java.util.spi.*;
 import sun.util.locale.provider.LocaleProviderAdapter;
 
 public class LocaleProviders {
 
+    private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
+
     public static void main(String[] args) {
         String methodName = args[0];
 
         switch (methodName) {
             case "getPlatformLocale":

@@ -74,10 +76,14 @@
 
             case "bug8220227Test":
                 bug8220227Test();
                 break;
 
+            case "bug8228465Test":
+                bug8228465Test();
+                break;
+
             default:
                 throw new RuntimeException("Test method '"+methodName+"' not found.");
         }
     }
 

@@ -104,11 +110,11 @@
     }
 
     static void bug7198834Test() {
         LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
         LocaleProviderAdapter.Type type = lda.getAdapterType();
-        if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
+        if (type == LocaleProviderAdapter.Type.HOST && IS_WINDOWS) {
             DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
             String date = df.format(new Date());
             if (date.charAt(date.length()-1) == ' ') {
                 throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
             }

@@ -131,11 +137,11 @@
         String nu = nf.format(1234560);
     }
 
     // This test assumes Windows localized language/country display names.
     static void bug8010666Test() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             NumberFormat nf = NumberFormat.getInstance(Locale.US);
             try {
                 double ver = nf.parse(System.getProperty("os.version"))
                                .doubleValue();
                 System.out.printf("Windows version: %.1f\n", ver);

@@ -213,11 +219,11 @@
             // ParseException is fine in this test, as it's not "UTC"
 }
     }
 
     static void bug8013903Test() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             Date sampleDate = new Date(0x10000000000L);
             String hostResult = "\u5e73\u6210 16.11.03 (Wed) AM 11:53:47";
             String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
             Locale l = new Locale("ja", "JP", "JP");
             SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l);

@@ -239,11 +245,11 @@
             }
         }
     }
 
     static void bug8027289Test(String expectedCodePoint) {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             char[] expectedSymbol = Character.toChars(Integer.valueOf(expectedCodePoint, 16));
             NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.CHINA);
             char formatted = nf.format(7000).charAt(0);
             System.out.println("returned: " + formatted + ", expected: " + expectedSymbol[0]);
             if (formatted != expectedSymbol[0]) {

@@ -253,15 +259,31 @@
             }
         }
     }
 
     static void bug8220227Test() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             Locale l = new Locale("xx","XX");
             String country = l.getDisplayCountry();
             if (country.endsWith("(XX)")) {
                 throw new RuntimeException(
                         "Unexpected Region name: " + country);
             }
         }
     }
+
+    static void bug8228465Test() {
+        LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(CalendarNameProvider.class, Locale.US);
+        LocaleProviderAdapter.Type type = lda.getAdapterType();
+        if (type == LocaleProviderAdapter.Type.HOST && IS_WINDOWS) {
+            var names =  new GregorianCalendar()
+                .getDisplayNames(Calendar.ERA, Calendar.SHORT_FORMAT, Locale.US);
+            if (!names.keySet().contains("AD") ||
+                names.get("AD").intValue() != 1) {
+                    throw new RuntimeException(
+                            "Short Era name for 'AD' is missing or incorrect");
+            } else {
+                System.out.println("bug8228465Test succeeded.");
+            }
+        }
+    }
 }
< prev index next >