jdk/test/java/util/Locale/LocaleEnhanceTest.java
changeset 6843 6ab7e78c51eb
parent 6501 684810d882b3
child 7513 7091fccbc86d
--- a/jdk/test/java/util/Locale/LocaleEnhanceTest.java	Fri Oct 15 11:45:30 2010 -0700
+++ b/jdk/test/java/util/Locale/LocaleEnhanceTest.java	Mon Oct 18 14:45:00 2010 -0700
@@ -614,6 +614,55 @@
         assertEquals("hans DE", "Simplified Han", hansLocale.getDisplayScript(Locale.GERMANY));
     }
 
+    public void testGetDisplayName() {
+        final Locale[] testLocales = {
+                Locale.ROOT,
+                new Locale("en"),
+                new Locale("en", "US"),
+                new Locale("", "US"),
+                new Locale("no", "NO", "NY"),
+                new Locale("", "", "NY"),
+                Locale.forLanguageTag("zh-Hans"),
+                Locale.forLanguageTag("zh-Hant"),
+                Locale.forLanguageTag("zh-Hans-CN"),
+                Locale.forLanguageTag("und-Hans"),
+        };
+
+        final String[] displayNameEnglish = {
+                "",
+                "English",
+                "English (United States)",
+                "United States",
+                "Norwegian (Norway,Nynorsk)",
+                "Nynorsk",
+                "Chinese (Simplified Han)",
+                "Chinese (Traditional Han)",
+                "Chinese (Simplified Han,China)",
+                "Simplified Han",
+        };
+
+        final String[] displayNameSimplifiedChinese = {
+                "",
+                "\u82f1\u6587",
+                "\u82f1\u6587 (\u7f8e\u56fd)",
+                "\u7f8e\u56fd",
+                "\u632a\u5a01\u6587 (\u632a\u5a01,Nynorsk)",
+                "Nynorsk",
+                "\u4e2d\u6587 (\u7b80\u4f53\u4e2d\u6587)",
+                "\u4e2d\u6587 (\u7e41\u4f53\u4e2d\u6587)",
+                "\u4e2d\u6587 (\u7b80\u4f53\u4e2d\u6587,\u4e2d\u56fd)",
+                "\u7b80\u4f53\u4e2d\u6587",
+        };
+
+        for (int i = 0; i < testLocales.length; i++) {
+            Locale loc = testLocales[i];
+            assertEquals("English display name for " + loc.toLanguageTag(),
+                    displayNameEnglish[i], loc.getDisplayName(Locale.ENGLISH));
+            assertEquals("Simplified Chinese display name for " + loc.toLanguageTag(),
+                    displayNameSimplifiedChinese[i], loc.getDisplayName(Locale.CHINA));
+        }
+    }
+
     ///
     /// Builder tests
     ///