author | serb |
Wed, 21 Feb 2018 12:49:00 -0800 | |
changeset 49096 | eaef201ec301 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
import javax.swing.SwingUtilities; |
|
24 |
import javax.swing.UIDefaults; |
|
25 |
/* |
|
26 |
* @test |
|
27 |
* @bug 8080972 |
|
28 |
* @summary Audit Core Reflection in module java.desktop for places that will |
|
29 |
* require changes to work with modules |
|
30 |
* @author Alexander Scherbatiy |
|
49096
eaef201ec301
8198333: ProblemList should be updated for headless mode
serb
parents:
47216
diff
changeset
|
31 |
* @run main/othervm TestProxyLazyValue |
36511 | 32 |
*/ |
33 |
||
34 |
public class TestProxyLazyValue { |
|
35 |
||
36 |
public static void main(String[] args) throws Exception { |
|
37 |
SwingUtilities.invokeAndWait(TestProxyLazyValue::testUserProxyLazyValue); |
|
38 |
SwingUtilities.invokeAndWait(TestProxyLazyValue::testProxyLazyValue); |
|
39 |
System.setSecurityManager(new SecurityManager()); |
|
40 |
SwingUtilities.invokeAndWait(TestProxyLazyValue::testUserProxyLazyValue); |
|
41 |
SwingUtilities.invokeAndWait(TestProxyLazyValue::testProxyLazyValue); |
|
42 |
} |
|
43 |
||
44 |
private static void testUserProxyLazyValue() { |
|
45 |
||
46 |
Object obj = new UserProxyLazyValue( |
|
47 |
UserLazyClass.class.getName()).createValue(null); |
|
48 |
||
49 |
if (!(obj instanceof UserLazyClass)) { |
|
50 |
throw new RuntimeException("Object is not UserLazyClass!"); |
|
51 |
} |
|
52 |
||
53 |
obj = new UserProxyLazyValue(UserLazyClass.class.getName(), |
|
54 |
new Object[]{UserLazyClass.CONSTRUCTOR_ARG}).createValue(null); |
|
55 |
||
56 |
if (!(obj instanceof UserLazyClass)) { |
|
57 |
throw new RuntimeException("Object is not UserLazyClass!"); |
|
58 |
} |
|
59 |
||
60 |
if (((UserLazyClass) obj).arg != UserLazyClass.CONSTRUCTOR_ARG) { |
|
61 |
throw new RuntimeException("Constructt argument is wrong!"); |
|
62 |
} |
|
63 |
||
64 |
obj = new UserProxyLazyValue(UserLazyClass.class.getName(), |
|
65 |
"method1").createValue(null); |
|
66 |
||
67 |
if (!UserLazyClass.RESULT_1.equals(obj)) { |
|
68 |
throw new RuntimeException("Result is wrong!"); |
|
69 |
} |
|
70 |
||
71 |
obj = new UserProxyLazyValue(UserLazyClass.class.getName(), |
|
72 |
"method2", new Object[]{UserLazyClass.RESULT_2}).createValue(null); |
|
73 |
||
74 |
if (!UserLazyClass.RESULT_2.equals(obj)) { |
|
75 |
throw new RuntimeException("Result is wrong!"); |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
private static void testProxyLazyValue() { |
|
80 |
||
81 |
Object obj = new UIDefaults.ProxyLazyValue( |
|
82 |
UserLazyClass.class.getName()).createValue(null); |
|
83 |
||
84 |
if (!(obj instanceof UserLazyClass)) { |
|
85 |
throw new RuntimeException("Object is not UserLazyClass!"); |
|
86 |
} |
|
87 |
||
88 |
obj = new UIDefaults.ProxyLazyValue(UserLazyClass.class.getName(), |
|
89 |
new Object[]{UserLazyClass.CONSTRUCTOR_ARG}).createValue(null); |
|
90 |
||
91 |
if (!(obj instanceof UserLazyClass)) { |
|
92 |
throw new RuntimeException("Object is not UserLazyClass!"); |
|
93 |
} |
|
94 |
||
95 |
if (((UserLazyClass) obj).arg != UserLazyClass.CONSTRUCTOR_ARG) { |
|
96 |
throw new RuntimeException("Constructt argument is wrong!"); |
|
97 |
} |
|
98 |
||
99 |
obj = new UIDefaults.ProxyLazyValue(UserLazyClass.class.getName(), |
|
100 |
"method1").createValue(null); |
|
101 |
||
102 |
if (!UserLazyClass.RESULT_1.equals(obj)) { |
|
103 |
throw new RuntimeException("Result is wrong!"); |
|
104 |
} |
|
105 |
||
106 |
obj = new UIDefaults.ProxyLazyValue(UserLazyClass.class.getName(), |
|
107 |
"method2", new Object[]{UserLazyClass.RESULT_2}).createValue(null); |
|
108 |
||
109 |
if (!UserLazyClass.RESULT_2.equals(obj)) { |
|
110 |
throw new RuntimeException("Result is wrong!"); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
public static class UserLazyClass { |
|
115 |
||
116 |
static final int CONSTRUCTOR_ARG = 100; |
|
117 |
static final String RESULT_1 = "1"; |
|
118 |
static final String RESULT_2 = "2"; |
|
119 |
||
120 |
int arg; |
|
121 |
||
122 |
public UserLazyClass() { |
|
123 |
} |
|
124 |
||
125 |
public UserLazyClass(int arg) { |
|
126 |
this.arg = arg; |
|
127 |
} |
|
128 |
||
129 |
public static String method1() { |
|
130 |
return RESULT_1; |
|
131 |
} |
|
132 |
||
133 |
public static String method2(String arg) { |
|
134 |
return arg; |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
public static class UserProxyLazyValue extends UIDefaults.ProxyLazyValue { |
|
139 |
||
140 |
public UserProxyLazyValue(String className) { |
|
141 |
super(className); |
|
142 |
} |
|
143 |
||
144 |
public UserProxyLazyValue(String className, Object[] constructorArgs) { |
|
145 |
super(className, constructorArgs); |
|
146 |
} |
|
147 |
||
148 |
public UserProxyLazyValue(String className, String methodName) { |
|
149 |
super(className, methodName); |
|
150 |
} |
|
151 |
||
152 |
public UserProxyLazyValue(String className, String methodName, |
|
153 |
Object[] methodArgs) { |
|
154 |
super(className, methodName, methodArgs); |
|
155 |
} |
|
156 |
} |
|
157 |
} |