author | mfang |
Wed, 17 Aug 2011 14:18:26 -0700 | |
changeset 10294 | 8fcdae2a7ec7 |
parent 10138 | b7572da25d15 |
child 10339 | 80d9f4bc094b |
permissions | -rw-r--r-- |
6490 | 1 |
/* |
10138 | 2 |
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
6490 | 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. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
6495
3cec0a02688b
6981759: copyright header fix for test/java/util/Locale/LocaleCategory.java
naoto
parents:
6490
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3cec0a02688b
6981759: copyright header fix for test/java/util/Locale/LocaleCategory.java
naoto
parents:
6490
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3cec0a02688b
6981759: copyright header fix for test/java/util/Locale/LocaleCategory.java
naoto
parents:
6490
diff
changeset
|
21 |
* questions. |
6490 | 22 |
*/ |
23 |
import java.util.Locale; |
|
24 |
||
25 |
public class LocaleCategory { |
|
26 |
private static Locale base = null; |
|
27 |
private static Locale disp = null; |
|
28 |
private static Locale fmt = null; |
|
29 |
private static String enc = null; |
|
30 |
||
31 |
public static void main(String[] args) { |
|
10138 | 32 |
Locale reservedLocale = Locale.getDefault(); |
33 |
try { |
|
34 |
Locale.Builder builder = new Locale.Builder(); |
|
7049 | 35 |
|
10138 | 36 |
base = builder.setLanguage(System.getProperty("user.language", "")) |
37 |
.setScript(System.getProperty("user.script", "")) |
|
38 |
.setRegion(System.getProperty("user.country", "")) |
|
39 |
.setVariant(System.getProperty("user.variant", "")).build(); |
|
40 |
disp = builder.setLanguage( |
|
41 |
System.getProperty("user.language.display", |
|
42 |
Locale.getDefault().getLanguage())) |
|
43 |
.setScript(System.getProperty("user.script.display", |
|
44 |
Locale.getDefault().getScript())) |
|
45 |
.setRegion(System.getProperty("user.country.display", |
|
46 |
Locale.getDefault().getCountry())) |
|
47 |
.setVariant(System.getProperty("user.variant.display", |
|
48 |
Locale.getDefault().getVariant())).build(); |
|
49 |
fmt = builder.setLanguage(System.getProperty("user.language.format", |
|
50 |
Locale.getDefault().getLanguage())) |
|
51 |
.setScript(System.getProperty("user.script.format", |
|
52 |
Locale.getDefault().getScript())) |
|
53 |
.setRegion(System.getProperty("user.country.format", |
|
54 |
Locale.getDefault().getCountry())) |
|
55 |
.setVariant(System.getProperty("user.variant.format", |
|
56 |
Locale.getDefault().getVariant())).build(); |
|
57 |
checkDefault(); |
|
58 |
testGetSetDefault(); |
|
59 |
} finally { |
|
60 |
// restore the reserved locale |
|
61 |
Locale.setDefault(reservedLocale); |
|
62 |
} |
|
6490 | 63 |
} |
64 |
||
65 |
static void checkDefault() { |
|
66 |
if (!base.equals(Locale.getDefault()) || |
|
67 |
!disp.equals(Locale.getDefault(Locale.Category.DISPLAY)) || |
|
68 |
!fmt.equals(Locale.getDefault(Locale.Category.FORMAT))) { |
|
69 |
throw new RuntimeException("Some of the return values from getDefault() do not agree with the locale derived from \"user.xxxx\" system properties"); |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
static void testGetSetDefault() { |
|
74 |
try { |
|
75 |
Locale.setDefault(null, null); |
|
76 |
throw new RuntimeException("setDefault(null, null) should throw a NullPointerException"); |
|
77 |
} catch (NullPointerException npe) {} |
|
78 |
||
79 |
Locale.setDefault(Locale.CHINA); |
|
80 |
if (!Locale.CHINA.equals(Locale.getDefault(Locale.Category.DISPLAY)) || |
|
81 |
!Locale.CHINA.equals(Locale.getDefault(Locale.Category.FORMAT))) { |
|
82 |
throw new RuntimeException("setDefault() should set all default locales for all categories"); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |