Path: blob/master/test/jdk/java/beans/Introspector/8130937/TestBooleanBeanProperties.java
41153 views
/*1* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.beans.BeanProperty;24import java.beans.PropertyChangeListener;25import java.beans.PropertyChangeSupport;26import java.beans.PropertyDescriptor;2728/**29* @test30* @bug 8130937 813134731* @summary Tests the booleans properties of the BeanProperty annotation32* @library ..33*/34public final class TestBooleanBeanProperties {3536public static void main(final String[] args) {37test(Empty.class, false, false, false, false, false, false);38test(BoundTrue.class, false, false, false, false, false, false);39test(BoundFalse.class, false, false, false, false, false, false);40test(BoundListener.class, true, false, false, false, false, false);41test(BoundFalseListener.class, false, false, false, false, false, false);42test(BoundTrueListener.class, true, false, false, false, false, false);43test(ExpertTrue.class, false, true, false, false, false, false);44test(ExpertFalse.class, false, false, false, false, false, false);45test(HiddenTrue.class, false, false, true, false, false, false);46test(HiddenFalse.class, false, false, false, false, false, false);47test(PreferredTrue.class, false, false, false, true, false, false);48test(PreferredFalse.class, false, false, false, false, false, false);49test(RequiredTrue.class, false, false, false, false, true, false);50test(RequiredFalse.class, false, false, false, false, false, false);51test(VisualUpdateTrue.class, false, false, false, false, false, true);52test(VisualUpdateFalse.class, false, false, false, false, false, false);53test(All.class, true, true, true, true, true, true);54}5556private static void test(Class<?> cls, boolean isBound, boolean isExpert,57boolean isHidden, boolean isPref, boolean isReq,58boolean isVS) {59PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(cls, "value");60if (pd.isBound() != isBound) {61throw new RuntimeException("isBound should be: " + isBound);62}63if (pd.isExpert() != isExpert || getValue(pd, "expert") != isExpert) {64throw new RuntimeException("isExpert should be:" + isExpert);65}66if (pd.isHidden() != isHidden || getValue(pd, "hidden") != isHidden) {67throw new RuntimeException("isHidden should be: " + isHidden);68}69if (pd.isPreferred() != isPref) {70throw new RuntimeException("isPreferred should be: " + isPref);71}72if (getValue(pd, "required") != isReq) {73throw new RuntimeException("required should be: " + isReq);74}75if (getValue(pd, "visualUpdate") != isVS) {76throw new RuntimeException("required should be: " + isVS);77}78if (pd.getValue("enumerationValues") == null) {79throw new RuntimeException("enumerationValues should be empty array");80}81}8283private static boolean getValue(PropertyDescriptor pd, String value) {84return (boolean) pd.getValue(value);85}86////////////////////////////////////////////////////////////////////////////8788public static final class Empty {8990private int value;9192public int getValue() {93return value;94}9596public void setValue(int value) {97this.value = value;98}99}100101public static final class All {102103private int value;104105private PropertyChangeSupport pcs = new PropertyChangeSupport(this);106107public int getValue() {108return value;109}110111@BeanProperty(bound = true, expert = true, hidden = true,112preferred = true, required = true, visualUpdate = true,113enumerationValues = {})114public void setValue(int value) {115this.value = value;116}117118public void addPropertyChangeListener(PropertyChangeListener l) {119pcs.addPropertyChangeListener(l);120}121122public void removePropertyChangeListener(PropertyChangeListener l) {123pcs.removePropertyChangeListener(l);124}125}126////////////////////////////////////////////////////////////////////////////127// bound property128////////////////////////////////////////////////////////////////////////////129130public static final class BoundTrue {131132private int value;133134public int getValue() {135return value;136}137138@BeanProperty(bound = true)139public void setValue(int value) {140this.value = value;141}142}143144public static final class BoundFalse {145146private int value;147148public int getValue() {149return value;150}151152@BeanProperty(bound = false)153public void setValue(int value) {154this.value = value;155}156}157158public static final class BoundListener {159160private PropertyChangeSupport pcs = new PropertyChangeSupport(this);161162private int value;163164public int getValue() {165return value;166}167168public void setValue(int value) {169this.value = value;170}171172public void addPropertyChangeListener(PropertyChangeListener l) {173pcs.addPropertyChangeListener(l);174}175176public void removePropertyChangeListener(PropertyChangeListener l) {177pcs.removePropertyChangeListener(l);178}179}180181public static final class BoundFalseListener {182183private PropertyChangeSupport pcs = new PropertyChangeSupport(this);184185private int value;186187public int getValue() {188return value;189}190191@BeanProperty(bound = false)192public void setValue(int value) {193this.value = value;194}195196public void addPropertyChangeListener(PropertyChangeListener l) {197pcs.addPropertyChangeListener(l);198}199200public void removePropertyChangeListener(PropertyChangeListener l) {201pcs.removePropertyChangeListener(l);202}203}204205public static final class BoundTrueListener {206207private PropertyChangeSupport pcs = new PropertyChangeSupport(this);208209private int value;210211public int getValue() {212return value;213}214215@BeanProperty(bound = true)216public void setValue(int value) {217this.value = value;218}219220public void addPropertyChangeListener(PropertyChangeListener l) {221pcs.addPropertyChangeListener(l);222}223224public void removePropertyChangeListener(PropertyChangeListener l) {225pcs.removePropertyChangeListener(l);226}227}228////////////////////////////////////////////////////////////////////////////229// expert property230////////////////////////////////////////////////////////////////////////////231232public static final class ExpertTrue {233234private int value;235236public int getValue() {237return value;238}239240@BeanProperty(expert = true)241public void setValue(int value) {242this.value = value;243}244}245246public static final class ExpertFalse {247248private int value;249250public int getValue() {251return value;252}253254@BeanProperty(expert = false)255public void setValue(int value) {256this.value = value;257}258}259////////////////////////////////////////////////////////////////////////////260// hidden property261////////////////////////////////////////////////////////////////////////////262263public static final class HiddenTrue {264265private int value;266267public int getValue() {268return value;269}270271@BeanProperty(hidden = true)272public void setValue(int value) {273this.value = value;274}275}276277public static final class HiddenFalse {278279private int value;280281public int getValue() {282return value;283}284285@BeanProperty(hidden = false)286public void setValue(int value) {287this.value = value;288}289}290////////////////////////////////////////////////////////////////////////////291// preferred property292////////////////////////////////////////////////////////////////////////////293294public static final class PreferredTrue {295296private int value;297298public int getValue() {299return value;300}301302@BeanProperty(preferred = true)303public void setValue(int value) {304this.value = value;305}306}307308public static final class PreferredFalse {309310private int value;311312public int getValue() {313return value;314}315316@BeanProperty(preferred = false)317public void setValue(int value) {318this.value = value;319}320}321////////////////////////////////////////////////////////////////////////////322// required property323////////////////////////////////////////////////////////////////////////////324325public static final class RequiredTrue {326327private int value;328329public int getValue() {330return value;331}332333@BeanProperty(required = true)334public void setValue(int value) {335this.value = value;336}337}338339public static final class RequiredFalse {340341private int value;342343public int getValue() {344return value;345}346347@BeanProperty(required = false)348public void setValue(int value) {349this.value = value;350}351}352////////////////////////////////////////////////////////////////////////////353// visualUpdate property354////////////////////////////////////////////////////////////////////////////355356public static final class VisualUpdateTrue {357358private int value;359360public int getValue() {361return value;362}363364@BeanProperty(visualUpdate = true)365public void setValue(int value) {366this.value = value;367}368}369370public static final class VisualUpdateFalse {371372private int value;373374public int getValue() {375return value;376}377378@BeanProperty(visualUpdate = false)379public void setValue(int value) {380this.value = value;381}382}383}384385386