jdk/test/java/beans/Introspector/8130937/TestBooleanBeanProperties.java
changeset 32109 b89c59200379
child 42934 cd1c9fab50ca
equal deleted inserted replaced
31898:6890dfde0ed1 32109:b89c59200379
       
     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);
       
    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     }
       
    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 
       
   131         public int getValue() {
       
   132             return value;
       
   133         }
       
   134 
       
   135         @BeanProperty(bound = true)
       
   136         public void setValue(int value) {
       
   137             this.value = value;
       
   138         }
       
   139     }
       
   140 
       
   141     public static final class BoundFalse {
       
   142 
       
   143         private int value;
       
   144 
       
   145         public int getValue() {
       
   146             return value;
       
   147         }
       
   148 
       
   149         @BeanProperty(bound = false)
       
   150         public void setValue(int value) {
       
   151             this.value = value;
       
   152         }
       
   153     }
       
   154 
       
   155     public static final class BoundListener {
       
   156 
       
   157         private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
       
   158 
       
   159         private int value;
       
   160 
       
   161         public int getValue() {
       
   162             return value;
       
   163         }
       
   164 
       
   165         public void setValue(int value) {
       
   166             this.value = value;
       
   167         }
       
   168 
       
   169         public void addPropertyChangeListener(PropertyChangeListener l) {
       
   170             pcs.addPropertyChangeListener(l);
       
   171         }
       
   172 
       
   173         public void removePropertyChangeListener(PropertyChangeListener l) {
       
   174             pcs.removePropertyChangeListener(l);
       
   175         }
       
   176     }
       
   177 
       
   178     public static final class BoundFalseListener {
       
   179 
       
   180         private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
       
   181 
       
   182         private int value;
       
   183 
       
   184         public int getValue() {
       
   185             return value;
       
   186         }
       
   187 
       
   188         @BeanProperty(bound = false)
       
   189         public void setValue(int value) {
       
   190             this.value = value;
       
   191         }
       
   192 
       
   193         public void addPropertyChangeListener(PropertyChangeListener l) {
       
   194             pcs.addPropertyChangeListener(l);
       
   195         }
       
   196 
       
   197         public void removePropertyChangeListener(PropertyChangeListener l) {
       
   198             pcs.removePropertyChangeListener(l);
       
   199         }
       
   200     }
       
   201 
       
   202     public static final class BoundTrueListener {
       
   203 
       
   204         private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
       
   205 
       
   206         private int value;
       
   207 
       
   208         public int getValue() {
       
   209             return value;
       
   210         }
       
   211 
       
   212         @BeanProperty(bound = true)
       
   213         public void setValue(int value) {
       
   214             this.value = value;
       
   215         }
       
   216 
       
   217         public void addPropertyChangeListener(PropertyChangeListener l) {
       
   218             pcs.addPropertyChangeListener(l);
       
   219         }
       
   220 
       
   221         public void removePropertyChangeListener(PropertyChangeListener l) {
       
   222             pcs.removePropertyChangeListener(l);
       
   223         }
       
   224     }
       
   225     ////////////////////////////////////////////////////////////////////////////
       
   226     // expert property
       
   227     ////////////////////////////////////////////////////////////////////////////
       
   228 
       
   229     public static final class ExpertTrue {
       
   230 
       
   231         private int value;
       
   232 
       
   233         public int getValue() {
       
   234             return value;
       
   235         }
       
   236 
       
   237         @BeanProperty(expert = true)
       
   238         public void setValue(int value) {
       
   239             this.value = value;
       
   240         }
       
   241     }
       
   242 
       
   243     public static final class ExpertFalse {
       
   244 
       
   245         private int value;
       
   246 
       
   247         public int getValue() {
       
   248             return value;
       
   249         }
       
   250 
       
   251         @BeanProperty(expert = false)
       
   252         public void setValue(int value) {
       
   253             this.value = value;
       
   254         }
       
   255     }
       
   256     ////////////////////////////////////////////////////////////////////////////
       
   257     // hidden property
       
   258     ////////////////////////////////////////////////////////////////////////////
       
   259 
       
   260     public static final class HiddenTrue {
       
   261 
       
   262         private int value;
       
   263 
       
   264         public int getValue() {
       
   265             return value;
       
   266         }
       
   267 
       
   268         @BeanProperty(hidden = true)
       
   269         public void setValue(int value) {
       
   270             this.value = value;
       
   271         }
       
   272     }
       
   273 
       
   274     public static final class HiddenFalse {
       
   275 
       
   276         private int value;
       
   277 
       
   278         public int getValue() {
       
   279             return value;
       
   280         }
       
   281 
       
   282         @BeanProperty(hidden = false)
       
   283         public void setValue(int value) {
       
   284             this.value = value;
       
   285         }
       
   286     }
       
   287     ////////////////////////////////////////////////////////////////////////////
       
   288     // preferred property
       
   289     ////////////////////////////////////////////////////////////////////////////
       
   290 
       
   291     public static final class PreferredTrue {
       
   292 
       
   293         private int value;
       
   294 
       
   295         public int getValue() {
       
   296             return value;
       
   297         }
       
   298 
       
   299         @BeanProperty(preferred = true)
       
   300         public void setValue(int value) {
       
   301             this.value = value;
       
   302         }
       
   303     }
       
   304 
       
   305     public static final class PreferredFalse {
       
   306 
       
   307         private int value;
       
   308 
       
   309         public int getValue() {
       
   310             return value;
       
   311         }
       
   312 
       
   313         @BeanProperty(preferred = false)
       
   314         public void setValue(int value) {
       
   315             this.value = value;
       
   316         }
       
   317     }
       
   318     ////////////////////////////////////////////////////////////////////////////
       
   319     // required property
       
   320     ////////////////////////////////////////////////////////////////////////////
       
   321 
       
   322     public static final class RequiredTrue {
       
   323 
       
   324         private int value;
       
   325 
       
   326         public int getValue() {
       
   327             return value;
       
   328         }
       
   329 
       
   330         @BeanProperty(required = true)
       
   331         public void setValue(int value) {
       
   332             this.value = value;
       
   333         }
       
   334     }
       
   335 
       
   336     public static final class RequiredFalse {
       
   337 
       
   338         private int value;
       
   339 
       
   340         public int getValue() {
       
   341             return value;
       
   342         }
       
   343 
       
   344         @BeanProperty(required = false)
       
   345         public void setValue(int value) {
       
   346             this.value = value;
       
   347         }
       
   348     }
       
   349     ////////////////////////////////////////////////////////////////////////////
       
   350     // visualUpdate property
       
   351     ////////////////////////////////////////////////////////////////////////////
       
   352 
       
   353     public static final class VisualUpdateTrue {
       
   354 
       
   355         private int value;
       
   356 
       
   357         public int getValue() {
       
   358             return value;
       
   359         }
       
   360 
       
   361         @BeanProperty(visualUpdate = true)
       
   362         public void setValue(int value) {
       
   363             this.value = value;
       
   364         }
       
   365     }
       
   366 
       
   367     public static final class VisualUpdateFalse {
       
   368 
       
   369         private int value;
       
   370 
       
   371         public int getValue() {
       
   372             return value;
       
   373         }
       
   374 
       
   375         @BeanProperty(visualUpdate = false)
       
   376         public void setValue(int value) {
       
   377             this.value = value;
       
   378         }
       
   379     }
       
   380 }