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
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
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);
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 }
80
81 private static boolean getValue(PropertyDescriptor pd, String value) {
82 return (boolean) pd.getValue(value);
83 }
84 ////////////////////////////////////////////////////////////////////////////
85
86 public static final class Empty {
87
88 private int value;
89
90 public int getValue() {
91 return value;
92 }
93
94 public void setValue(int value) {
95 this.value = value;
96 }
97 }
98
99 public static final class All {
100
101 private int value;
102
103 private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
104
105 public int getValue() {
106 return value;
107 }
108
109 @BeanProperty(bound = true, expert = true, hidden = true,
110 preferred = true, required = true, visualUpdate = true)
111 public void setValue(int value) {
112 this.value = value;
113 }
114
115 public void addPropertyChangeListener(PropertyChangeListener l) {
116 pcs.addPropertyChangeListener(l);
117 }
118
119 public void removePropertyChangeListener(PropertyChangeListener l) {
120 pcs.removePropertyChangeListener(l);
121 }
122 }
123 ////////////////////////////////////////////////////////////////////////////
124 // bound property
125 ////////////////////////////////////////////////////////////////////////////
126
127 public static final class BoundTrue {
128
129 private int value;
130
|
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);
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
|