Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/util/Resources/customSysClassLoader/MessageFormatting.java
41154 views
1
/*
2
* Copyright (c) 2017, 2018, 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
import java.util.*;
25
import sun.security.util.Resources;
26
import sun.security.util.LocalizedMessage;
27
import java.text.MessageFormat;
28
29
/*
30
* @test
31
* @bug 8168075 8196215
32
* @summary Ensure that security message formatting code is capable of
33
* displaying all messages.
34
* @modules java.base/sun.security.util
35
* @run main MessageFormatting
36
* @run main/othervm -Duser.country=SA -Duser.language=ar MessageFormatting
37
*/
38
39
public class MessageFormatting {
40
41
private static final Object[] MSG_ARGS = new Integer[]{0, 1, 2};
42
43
public static void main(String[] args) throws Exception {
44
45
Resources resources = new Resources();
46
Enumeration<String> keys = resources.getKeys();
47
while (keys.hasMoreElements()) {
48
String curKey = keys.nextElement();
49
String formattedString =
50
LocalizedMessage.getNonlocalized(curKey, MSG_ARGS);
51
String msg = resources.getString(curKey);
52
String expectedString = formatIfNecessary(msg, MSG_ARGS);
53
if (!formattedString.equals(expectedString)) {
54
System.err.println("Expected string:");
55
System.err.println(expectedString);
56
System.err.println("Actual string:");
57
System.err.println(formattedString);
58
throw new Exception("Incorrect message string");
59
}
60
}
61
}
62
63
private static String formatIfNecessary(String str, Object[] args) {
64
// message formatting code only formats messages with arguments
65
if (str.indexOf('{') < 0) {
66
return str;
67
}
68
Locale loc = new Locale("en", "US");
69
MessageFormat format = new MessageFormat(str, loc);
70
return format.format(args);
71
}
72
}
73
74