Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Locale/ExtensionsTest.java
41149 views
1
/*
2
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 7168528
27
* @summary Test Locale.hasExtensions() and Locale.stripExtensions().
28
*/
29
30
import java.util.*;
31
32
public class ExtensionsTest {
33
public static void main(String[] args) {
34
Locale jaJPJP = new Locale("ja", "JP", "JP");
35
if (!jaJPJP.hasExtensions()) {
36
error(jaJPJP + " should have an extension.");
37
}
38
Locale stripped = jaJPJP.stripExtensions();
39
if (stripped.hasExtensions()) {
40
error(stripped + " should NOT have an extension.");
41
}
42
if (jaJPJP.equals(stripped)) {
43
throw new RuntimeException("jaJPJP equals stripped");
44
}
45
if (!"ja-JP-x-lvariant-JP".equals(stripped.toLanguageTag())) {
46
error("stripped.toLanguageTag() isn't ja-JP-x-lvariant-JP");
47
}
48
49
Locale enUSja = Locale.forLanguageTag("en-US-u-ca-japanese");
50
if (!enUSja.stripExtensions().equals(Locale.US)) {
51
error("stripped enUSja not equals Locale.US");
52
}
53
54
// If a Locale has no extensions, stripExtensions() returns self.
55
Locale enUS = Locale.US.stripExtensions();
56
if (enUS != Locale.US) {
57
error("stripped Locale.US != Locale.US");
58
}
59
}
60
61
private static void error(String msg) {
62
throw new RuntimeException(msg);
63
}
64
}
65
66