6981466: Adding missing test LocaleCategory.java
authornaoto
Tue, 31 Aug 2010 23:56:17 -0700
changeset 6490 98def8a0da66
parent 6489 9e7015635425
child 6492 b0a42d084b26
child 6493 7bbabd9b79e6
6981466: Adding missing test LocaleCategory.java Reviewed-by: okutsu
jdk/test/java/util/Locale/LocaleCategory.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/Locale/LocaleCategory.java	Tue Aug 31 23:56:17 2010 -0700
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+import java.util.Locale;
+
+public class LocaleCategory {
+    private static Locale base = null;
+    private static Locale disp = null;
+    private static Locale fmt = null;
+    private static String enc = null;
+
+    public static void main(String[] args) {
+        base = new Locale(System.getProperty("user.language", ""),
+                          System.getProperty("user.country", ""),
+                          System.getProperty("user.variant", ""));
+        disp = new Locale(System.getProperty("user.language.display", ""),
+                          System.getProperty("user.country.display", ""),
+                          System.getProperty("user.variant.display", ""));
+        fmt  = new Locale(System.getProperty("user.language.format", ""),
+                          System.getProperty("user.country.format", ""),
+                          System.getProperty("user.variant.format", ""));
+        checkDefault();
+        testGetSetDefault();
+    }
+
+    static void checkDefault() {
+        if (!base.equals(Locale.getDefault()) ||
+            !disp.equals(Locale.getDefault(Locale.Category.DISPLAY)) ||
+            !fmt.equals(Locale.getDefault(Locale.Category.FORMAT))) {
+            throw new RuntimeException("Some of the return values from getDefault() do not agree with the locale derived from \"user.xxxx\" system properties");
+        }
+    }
+
+    static void testGetSetDefault() {
+        try {
+            Locale.setDefault(null, null);
+            throw new RuntimeException("setDefault(null, null) should throw a NullPointerException");
+        } catch (NullPointerException npe) {}
+
+        Locale.setDefault(Locale.CHINA);
+        if (!Locale.CHINA.equals(Locale.getDefault(Locale.Category.DISPLAY)) ||
+            !Locale.CHINA.equals(Locale.getDefault(Locale.Category.FORMAT))) {
+            throw new RuntimeException("setDefault() should set all default locales for all categories");
+        }
+    }
+}
+