--- /dev/null 2015-07-27 12:59:03.558602608 +0400 +++ new/test/java/beans/Introspector/4058433/TwoPropertiesTest.java 2015-07-29 18:54:06.693885653 +0400 @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.beans.BeanInfo; +import java.beans.BeanProperty; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.beans.PropertyChangeListener; +import java.util.Arrays; + +/** + * @test + * @bug 8131342 8131939 4058433 + * @summary Check if BeanProperty annotation works correctly + * in case of multiple (two) properties. Also check work of + * BeanProperty "required" element. + * @author a.stepanov + */ + +public class TwoPropertiesTest { + + public static class C { + + private int x, y; + + @BeanProperty( + bound = false, + expert = false, + hidden = false, + preferred = false, + required = false, + visualUpdate = false, + description = "XX", + enumerationValues = {"javax.swing.SwingConstants.TOP"} + ) + + public void setX(int i) { x = i; } + public int getX() { return x; } + + + @BeanProperty( + bound = true, + expert = true, + hidden = true, + preferred = true, + required = true, + visualUpdate = true, + description = "YY", + enumerationValues = {"javax.swing.SwingConstants.EAST"} + ) + public void setY(int i) { y = i; } + public double getY() { return y; } + + public void addPropertyChangeListener(PropertyChangeListener l) {} + public void removePropertyChangeListener(PropertyChangeListener l) {} + } + + static void checkEq(String what, Object v, Object ref) throws Exception { + + if ((v != null) && v.equals(ref)) { + System.out.println(what + ": ok (" + ref.toString() + ")"); + } else { + throw new Exception( + "invalid " + what + ", expected: \"" + ref + "\", got: \"" + v + "\""); + } + } + + static void checkEnumEq(String what, Object v, Object ref[]) throws Exception { + + what = "\"" + what + "\""; + if (v == null) { + throw new Exception("null " + what + " enumeration values"); + } + + String msg = "invalid " + what + " enumeration values"; + if (!(v instanceof Object[])) { throw new Exception(msg); } + + if (Arrays.equals((Object []) v, ref)) { + System.out.println(what + " enumeration values: ok"); + } else { throw new Exception(msg); } + } + + + public static void main(String[] args) throws Exception { + + BeanInfo i = Introspector.getBeanInfo(C.class, Object.class); + + PropertyDescriptor[] pds = i.getPropertyDescriptors(); + for (PropertyDescriptor pd: pds) { + String name = pd.getName(); + System.out.println(name); + switch (name) { + case "x": + checkEq(name + " isBound", pd.isBound(), false); + checkEq(name + " isConstrained", pd.isConstrained(), false); + checkEq(name + " isExpert", pd.isExpert(), false); + checkEq(name + " isHidden", pd.isHidden(), false); + checkEq(name + " isPreferred", pd.isPreferred(), false); + checkEq(name + " required", pd.getValue("required"), false); + checkEq(name + " visualUpdate", pd.getValue("visualUpdate"), false); + + checkEq(name + " description", pd.getShortDescription(), "XX"); + + checkEnumEq(pd.getName(), pd.getValue("enumerationValues"), + new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"}); + System.out.println(""); + break; + + case "y": + + checkEq(name + " isBound", pd.isBound(), true); + checkEq(name + " isExpert", pd.isExpert(), true); + checkEq(name + " isHidden", pd.isHidden(), true); + checkEq(name + " isPreferred", pd.isPreferred(), true); + checkEq(name + " required", pd.getValue("required"), true); + checkEq(name + " visualUpdate", pd.getValue("visualUpdate"), true); + + checkEq(name + " description", pd.getShortDescription(), "YY"); + + checkEnumEq(pd.getName(), pd.getValue("enumerationValues"), + new Object[]{ + "EAST", 3, "javax.swing.SwingConstants.EAST"}); + System.out.println(""); + break; + default: + throw new Exception("invalid property descriptor: " + name); + } + } + } +}