jdk/test/java/beans/Introspector/4058433/TestBeanProperty.java
changeset 31162 b4c9194f282c
parent 25566 ba387c302edd
child 32482 45ff83ee1ee9
equal deleted inserted replaced
31161:a93cd7e29b8c 31162:b4c9194f282c
     1 /*
     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    18  *
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    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
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
       
    23 
    23 import java.beans.BeanProperty;
    24 import java.beans.BeanProperty;
    24 import java.beans.PropertyChangeListener;
    25 import java.beans.PropertyChangeListener;
    25 import java.beans.PropertyChangeSupport;
    26 import java.beans.PropertyChangeSupport;
    26 import java.beans.PropertyDescriptor;
    27 import java.beans.PropertyDescriptor;
    27 import java.util.Arrays;
    28 import java.util.Arrays;
    28 /*
    29 
       
    30 /**
    29  * @test
    31  * @test
    30  * @bug 4058433
    32  * @bug 4058433
    31  * @summary Tests the BeanProperty annotation
    33  * @summary Tests the BeanProperty annotation
    32  * @author Sergey Malenkov
    34  * @author Sergey Malenkov
    33  * @library ..
    35  * @library ..
    34  */
    36  */
    35 public class TestBeanProperty {
    37 public class TestBeanProperty {
    36     public static void main(String[] args) throws Exception {
    38     public static void main(String[] args) throws Exception {
    37         Class<?>[] types = {B.class, BL.class, BLF.class, E.class, H.class, P.class, VU.class, D.class, EV.class, EVL.class, EVX.class};
    39         Class<?>[] types =
       
    40                 {B.class, BL.class, BLF.class, E.class, H.class, P.class,
       
    41                  VU.class, D.class, EVD.class, EVE.class, EV.class, EVL.class,
       
    42                  EVX.class};
    38         for (Class<?> type : types) {
    43         for (Class<?> type : types) {
    39             PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "value");
    44             PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "value");
    40             if (((B.class == type) || (BLF.class == type)) && pd.isBound()) {
    45             if (((B.class == type) || (BLF.class == type)) && pd.isBound()) {
    41                 BeanUtils.reportPropertyDescriptor(pd);
    46                 BeanUtils.reportPropertyDescriptor(pd);
    42                 throw new Error("not bound");
    47                 throw new Error("not bound");
    75             }
    80             }
    76             if ((EVX.class == type) == !isEV(pd, "ZERO", 0, "X.ZERO", "ONE", 1, "X.ONE")) {
    81             if ((EVX.class == type) == !isEV(pd, "ZERO", 0, "X.ZERO", "ONE", 1, "X.ONE")) {
    77                 BeanUtils.reportPropertyDescriptor(pd);
    82                 BeanUtils.reportPropertyDescriptor(pd);
    78                 throw new Error("enumerationValues from another package");
    83                 throw new Error("enumerationValues from another package");
    79             }
    84             }
       
    85             if (EVD.class == type && !isEV(pd)) {
       
    86                 BeanUtils.reportPropertyDescriptor(pd);
       
    87                 throw new Error("EV:"+ pd.getValue("enumerationValues"));
       
    88             }
       
    89             if (EVE.class == type && !isEV(pd)) {
       
    90                 BeanUtils.reportPropertyDescriptor(pd);
       
    91                 throw new Error("EV:"+ pd.getValue("enumerationValues"));
       
    92             }
    80         }
    93         }
    81     }
    94     }
    82 
    95 
    83     private static boolean isEV(PropertyDescriptor pd, Object... expected) {
    96     private static boolean isEV(PropertyDescriptor pd, Object... expected) {
    84         Object value = pd.getValue("enumerationValues");
    97         Object value = pd.getValue("enumerationValues");
   217         public void setValue(int value) {
   230         public void setValue(int value) {
   218             this.value = value;
   231             this.value = value;
   219         }
   232         }
   220     }
   233     }
   221 
   234 
       
   235     public static class EVD {
       
   236 
       
   237         private int value;
       
   238 
       
   239         public int getValue() {
       
   240             return value;
       
   241         }
       
   242 
       
   243         @BeanProperty()
       
   244         public void setValue(int value) {
       
   245             this.value = value;
       
   246         }
       
   247     }
       
   248 
       
   249     public static class EVE {
       
   250 
       
   251         private int value;
       
   252 
       
   253         public int getValue() {
       
   254             return value;
       
   255         }
       
   256 
       
   257         @BeanProperty(enumerationValues = {})
       
   258         public void setValue(int value) {
       
   259             this.value = value;
       
   260         }
       
   261     }
       
   262 
   222     public static class EV {
   263     public static class EV {
   223         private int value;
   264         private int value;
   224 
   265 
   225         public int getValue() {
   266         public int getValue() {
   226             return this.value;
   267             return this.value;