Path: blob/master/test/jdk/java/beans/Introspector/Test6194788.java
41149 views
/*1* Copyright (c) 2007, 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*/2223/*24* @test25* @bug 619478826* @summary Tests bound property in PropertyDescriptor/PropertyEditorSupport27* @author Sergey Malenkov28*/2930import java.beans.IndexedPropertyDescriptor;31import java.beans.IntrospectionException;32import java.beans.PropertyChangeListener;33import java.beans.PropertyDescriptor;3435public class Test6194788 {36public static void main(String[] args) throws IntrospectionException {37test(Grand.class, new PropertyDescriptor("index", Grand.class));38test(Grand.class, new IndexedPropertyDescriptor("name", Grand.class, null, null, "getName", "setName"));3940test(Parent.class, new PropertyDescriptor("parentIndex", Parent.class));41test(Parent.class, new IndexedPropertyDescriptor("parentName", Parent.class));4243test(Child.class, new PropertyDescriptor("childIndex", Child.class));44test(Child.class, new IndexedPropertyDescriptor("childName", Child.class));45}4647private static void test(Class type, PropertyDescriptor property) {48for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(type)) {49boolean forward = pd.equals(property);50boolean backward = property.equals(pd);51if (forward || backward) {52if (forward && backward)53return;5455throw new Error("illegal comparison of properties");56}57}58throw new Error("could not find property: " + property.getName());59}6061public static class Grand {62public int getIndex() {63return 0;64}6566public void setIndex(int index) {67}6869public String getName(int index) {70return null;71}7273public void setName(int index, String name) {74}75}7677public static class Parent {78public void addPropertyChangeListener(PropertyChangeListener listener) {79}8081public void removePropertyChangeListener(PropertyChangeListener listener) {82}8384public int getParentIndex() {85return 0;86}8788public void setParentIndex(int index) {89}9091public String[] getParentName() {92return null;93}9495public String getParentName(int index) {96return null;97}9899public void setParentName(String[] names) {100}101102public void setParentName(int index, String name) {103}104}105106public static class Child {107public int getChildIndex() {108return 0;109}110111public void setChildIndex(int index) {112}113114public String[] getChildName() {115return null;116}117118public String getChildName(int index) {119return null;120}121122public void setChildName(String[] names) {123}124125public void setChildName(int index, String name) {126}127}128}129130131