2701N/A/*
2706N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2701N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2701N/A *
2701N/A * This code is free software; you can redistribute it and/or modify it
2701N/A * under the terms of the GNU General Public License version 2 only, as
2701N/A * published by the Free Software Foundation.
2701N/A *
2701N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2701N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2701N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2701N/A * version 2 for more details (a copy is included in the LICENSE file that
2701N/A * accompanied this code).
2701N/A *
2701N/A * You should have received a copy of the GNU General Public License version
2701N/A * 2 along with this work; if not, write to the Free Software Foundation,
2701N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2701N/A *
2706N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2706N/A * or visit www.oracle.com if you need additional information or have any
2706N/A * questions.
2701N/A */
2701N/Aimport java.util.Locale;
2701N/A
2701N/Apublic class LocaleCategory {
2701N/A private static Locale base = null;
2701N/A private static Locale disp = null;
2701N/A private static Locale fmt = null;
2701N/A private static String enc = null;
2701N/A
2701N/A public static void main(String[] args) {
3008N/A Locale.Builder builder = new Locale.Builder();
3008N/A
3008N/A base = builder.setLanguage(System.getProperty("user.language", ""))
3008N/A .setScript(System.getProperty("user.script", ""))
3008N/A .setRegion(System.getProperty("user.country", ""))
3008N/A .setVariant(System.getProperty("user.variant", "")).build();
3008N/A disp = builder.setLanguage(System.getProperty("user.language.display",
3008N/A Locale.getDefault().getLanguage()))
3008N/A .setScript(System.getProperty("user.script.display",
3008N/A Locale.getDefault().getScript()))
3008N/A .setRegion(System.getProperty("user.country.display",
3008N/A Locale.getDefault().getCountry()))
3008N/A .setVariant(System.getProperty("user.variant.display",
3008N/A Locale.getDefault().getVariant())).build();
3008N/A fmt = builder.setLanguage(System.getProperty("user.language.format",
3008N/A Locale.getDefault().getLanguage()))
3008N/A .setScript(System.getProperty("user.script.format",
3008N/A Locale.getDefault().getScript()))
3008N/A .setRegion(System.getProperty("user.country.format",
3008N/A Locale.getDefault().getCountry()))
3008N/A .setVariant(System.getProperty("user.variant.format",
3008N/A Locale.getDefault().getVariant())).build();
2701N/A checkDefault();
2701N/A testGetSetDefault();
2701N/A }
2701N/A
2701N/A static void checkDefault() {
2701N/A if (!base.equals(Locale.getDefault()) ||
2701N/A !disp.equals(Locale.getDefault(Locale.Category.DISPLAY)) ||
2701N/A !fmt.equals(Locale.getDefault(Locale.Category.FORMAT))) {
2701N/A throw new RuntimeException("Some of the return values from getDefault() do not agree with the locale derived from \"user.xxxx\" system properties");
2701N/A }
2701N/A }
2701N/A
2701N/A static void testGetSetDefault() {
2701N/A try {
2701N/A Locale.setDefault(null, null);
2701N/A throw new RuntimeException("setDefault(null, null) should throw a NullPointerException");
2701N/A } catch (NullPointerException npe) {}
2701N/A
2701N/A Locale.setDefault(Locale.CHINA);
2701N/A if (!Locale.CHINA.equals(Locale.getDefault(Locale.Category.DISPLAY)) ||
2701N/A !Locale.CHINA.equals(Locale.getDefault(Locale.Category.FORMAT))) {
2701N/A throw new RuntimeException("setDefault() should set all default locales for all categories");
2701N/A }
2701N/A }
2701N/A}
2701N/A