Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Introspector/8130937/TestBooleanBeanProperties.java
41153 views
1
/*
2
* Copyright (c) 2015, 2016, 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.beans.BeanProperty;
25
import java.beans.PropertyChangeListener;
26
import java.beans.PropertyChangeSupport;
27
import java.beans.PropertyDescriptor;
28
29
/**
30
* @test
31
* @bug 8130937 8131347
32
* @summary Tests the booleans properties of the BeanProperty annotation
33
* @library ..
34
*/
35
public final class TestBooleanBeanProperties {
36
37
public static void main(final String[] args) {
38
test(Empty.class, false, false, false, false, false, false);
39
test(BoundTrue.class, false, false, false, false, false, false);
40
test(BoundFalse.class, false, false, false, false, false, false);
41
test(BoundListener.class, true, false, false, false, false, false);
42
test(BoundFalseListener.class, false, false, false, false, false, false);
43
test(BoundTrueListener.class, true, false, false, false, false, false);
44
test(ExpertTrue.class, false, true, false, false, false, false);
45
test(ExpertFalse.class, false, false, false, false, false, false);
46
test(HiddenTrue.class, false, false, true, false, false, false);
47
test(HiddenFalse.class, false, false, false, false, false, false);
48
test(PreferredTrue.class, false, false, false, true, false, false);
49
test(PreferredFalse.class, false, false, false, false, false, false);
50
test(RequiredTrue.class, false, false, false, false, true, false);
51
test(RequiredFalse.class, false, false, false, false, false, false);
52
test(VisualUpdateTrue.class, false, false, false, false, false, true);
53
test(VisualUpdateFalse.class, false, false, false, false, false, false);
54
test(All.class, true, true, true, true, true, true);
55
}
56
57
private static void test(Class<?> cls, boolean isBound, boolean isExpert,
58
boolean isHidden, boolean isPref, boolean isReq,
59
boolean isVS) {
60
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(cls, "value");
61
if (pd.isBound() != isBound) {
62
throw new RuntimeException("isBound should be: " + isBound);
63
}
64
if (pd.isExpert() != isExpert || getValue(pd, "expert") != isExpert) {
65
throw new RuntimeException("isExpert should be:" + isExpert);
66
}
67
if (pd.isHidden() != isHidden || getValue(pd, "hidden") != isHidden) {
68
throw new RuntimeException("isHidden should be: " + isHidden);
69
}
70
if (pd.isPreferred() != isPref) {
71
throw new RuntimeException("isPreferred should be: " + isPref);
72
}
73
if (getValue(pd, "required") != isReq) {
74
throw new RuntimeException("required should be: " + isReq);
75
}
76
if (getValue(pd, "visualUpdate") != isVS) {
77
throw new RuntimeException("required should be: " + isVS);
78
}
79
if (pd.getValue("enumerationValues") == null) {
80
throw new RuntimeException("enumerationValues should be empty array");
81
}
82
}
83
84
private static boolean getValue(PropertyDescriptor pd, String value) {
85
return (boolean) pd.getValue(value);
86
}
87
////////////////////////////////////////////////////////////////////////////
88
89
public static final class Empty {
90
91
private int value;
92
93
public int getValue() {
94
return value;
95
}
96
97
public void setValue(int value) {
98
this.value = value;
99
}
100
}
101
102
public static final class All {
103
104
private int value;
105
106
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
107
108
public int getValue() {
109
return value;
110
}
111
112
@BeanProperty(bound = true, expert = true, hidden = true,
113
preferred = true, required = true, visualUpdate = true,
114
enumerationValues = {})
115
public void setValue(int value) {
116
this.value = value;
117
}
118
119
public void addPropertyChangeListener(PropertyChangeListener l) {
120
pcs.addPropertyChangeListener(l);
121
}
122
123
public void removePropertyChangeListener(PropertyChangeListener l) {
124
pcs.removePropertyChangeListener(l);
125
}
126
}
127
////////////////////////////////////////////////////////////////////////////
128
// bound property
129
////////////////////////////////////////////////////////////////////////////
130
131
public static final class BoundTrue {
132
133
private int value;
134
135
public int getValue() {
136
return value;
137
}
138
139
@BeanProperty(bound = true)
140
public void setValue(int value) {
141
this.value = value;
142
}
143
}
144
145
public static final class BoundFalse {
146
147
private int value;
148
149
public int getValue() {
150
return value;
151
}
152
153
@BeanProperty(bound = false)
154
public void setValue(int value) {
155
this.value = value;
156
}
157
}
158
159
public static final class BoundListener {
160
161
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
162
163
private int value;
164
165
public int getValue() {
166
return value;
167
}
168
169
public void setValue(int value) {
170
this.value = value;
171
}
172
173
public void addPropertyChangeListener(PropertyChangeListener l) {
174
pcs.addPropertyChangeListener(l);
175
}
176
177
public void removePropertyChangeListener(PropertyChangeListener l) {
178
pcs.removePropertyChangeListener(l);
179
}
180
}
181
182
public static final class BoundFalseListener {
183
184
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
185
186
private int value;
187
188
public int getValue() {
189
return value;
190
}
191
192
@BeanProperty(bound = false)
193
public void setValue(int value) {
194
this.value = value;
195
}
196
197
public void addPropertyChangeListener(PropertyChangeListener l) {
198
pcs.addPropertyChangeListener(l);
199
}
200
201
public void removePropertyChangeListener(PropertyChangeListener l) {
202
pcs.removePropertyChangeListener(l);
203
}
204
}
205
206
public static final class BoundTrueListener {
207
208
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
209
210
private int value;
211
212
public int getValue() {
213
return value;
214
}
215
216
@BeanProperty(bound = true)
217
public void setValue(int value) {
218
this.value = value;
219
}
220
221
public void addPropertyChangeListener(PropertyChangeListener l) {
222
pcs.addPropertyChangeListener(l);
223
}
224
225
public void removePropertyChangeListener(PropertyChangeListener l) {
226
pcs.removePropertyChangeListener(l);
227
}
228
}
229
////////////////////////////////////////////////////////////////////////////
230
// expert property
231
////////////////////////////////////////////////////////////////////////////
232
233
public static final class ExpertTrue {
234
235
private int value;
236
237
public int getValue() {
238
return value;
239
}
240
241
@BeanProperty(expert = true)
242
public void setValue(int value) {
243
this.value = value;
244
}
245
}
246
247
public static final class ExpertFalse {
248
249
private int value;
250
251
public int getValue() {
252
return value;
253
}
254
255
@BeanProperty(expert = false)
256
public void setValue(int value) {
257
this.value = value;
258
}
259
}
260
////////////////////////////////////////////////////////////////////////////
261
// hidden property
262
////////////////////////////////////////////////////////////////////////////
263
264
public static final class HiddenTrue {
265
266
private int value;
267
268
public int getValue() {
269
return value;
270
}
271
272
@BeanProperty(hidden = true)
273
public void setValue(int value) {
274
this.value = value;
275
}
276
}
277
278
public static final class HiddenFalse {
279
280
private int value;
281
282
public int getValue() {
283
return value;
284
}
285
286
@BeanProperty(hidden = false)
287
public void setValue(int value) {
288
this.value = value;
289
}
290
}
291
////////////////////////////////////////////////////////////////////////////
292
// preferred property
293
////////////////////////////////////////////////////////////////////////////
294
295
public static final class PreferredTrue {
296
297
private int value;
298
299
public int getValue() {
300
return value;
301
}
302
303
@BeanProperty(preferred = true)
304
public void setValue(int value) {
305
this.value = value;
306
}
307
}
308
309
public static final class PreferredFalse {
310
311
private int value;
312
313
public int getValue() {
314
return value;
315
}
316
317
@BeanProperty(preferred = false)
318
public void setValue(int value) {
319
this.value = value;
320
}
321
}
322
////////////////////////////////////////////////////////////////////////////
323
// required property
324
////////////////////////////////////////////////////////////////////////////
325
326
public static final class RequiredTrue {
327
328
private int value;
329
330
public int getValue() {
331
return value;
332
}
333
334
@BeanProperty(required = true)
335
public void setValue(int value) {
336
this.value = value;
337
}
338
}
339
340
public static final class RequiredFalse {
341
342
private int value;
343
344
public int getValue() {
345
return value;
346
}
347
348
@BeanProperty(required = false)
349
public void setValue(int value) {
350
this.value = value;
351
}
352
}
353
////////////////////////////////////////////////////////////////////////////
354
// visualUpdate property
355
////////////////////////////////////////////////////////////////////////////
356
357
public static final class VisualUpdateTrue {
358
359
private int value;
360
361
public int getValue() {
362
return value;
363
}
364
365
@BeanProperty(visualUpdate = true)
366
public void setValue(int value) {
367
this.value = value;
368
}
369
}
370
371
public static final class VisualUpdateFalse {
372
373
private int value;
374
375
public int getValue() {
376
return value;
377
}
378
379
@BeanProperty(visualUpdate = false)
380
public void setValue(int value) {
381
this.value = value;
382
}
383
}
384
}
385
386