Path: blob/master/test/jdk/java/beans/Introspector/Test4918902.java
41149 views
/*1* Copyright (c) 2003, 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 491890226* @summary Tests search the most specific methods for PropertyDescriptors27* @author Mark Davidson28*/2930import java.beans.PropertyDescriptor;31import java.beans.IndexedPropertyDescriptor;3233public class Test4918902 {34public static void main(String[] args) {35testPropertyDescriptor(Child1.class, Child1.class, Parent.class);36testPropertyDescriptor(Child2.class, Parent.class, Child2.class);37testPropertyDescriptor(Child3.class, Child3.class, Child3.class);38testPropertyDescriptor(Child4.class, Parent.class, Parent.class);3940testPropertyDescriptor(Grandchild.class, Child3.class, Child3.class);4142testIndexedPropertyDescriptor(IChild1.class, IChild1.class, IChild1.class);43testIndexedPropertyDescriptor(IChild2.class, IChild2.class, IParent.class);44testIndexedPropertyDescriptor(IChild3.class, IParent.class, IChild3.class);45testIndexedPropertyDescriptor(IChild4.class, IParent.class, IParent.class);46}4748private static void testPropertyDescriptor(Class type, Class read, Class write) {49PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "foo");50if (!read.equals(pd.getReadMethod().getDeclaringClass())) {51throw new Error("unexpected read method: " + pd.getReadMethod());52}53if (!write.equals(pd.getWriteMethod().getDeclaringClass())) {54throw new Error("unexpected write method: " + pd.getWriteMethod());55}56}5758private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {59IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");60if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {61throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());62}63if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {64throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());65}66}6768// simple properties69public static class Parent {70public String getFoo() {71return null;72}7374public void setFoo(String str) {75}76}7778// getter has been overriden79public static class Child1 extends Parent {80public String getFoo() {81return null;82}83}8485// setter has been overriden86public static class Child2 extends Parent {87public void setFoo(String str) {88}89}9091// both methods have been overriden92public static class Child3 extends Parent {93public void setFoo(String str) {94}9596public String getFoo() {97return null;98}99}100101// methods should be taken from superclass102public static class Child4 extends Parent {103}104105// methods should be taken from superclass106public static class Grandchild extends Child3 {107}108109// indexed properties110public static class IParent {111public String getFoo(int i) {112return null;113}114115public void setFoo(int i, String str) {116}117}118119// both methods have been overriden120public static class IChild1 extends IParent {121public void setFoo(int i, String str) {122}123124public String getFoo(int i) {125return null;126}127}128129// getter has been overriden130public static class IChild2 extends IParent {131public String getFoo(int i) {132return null;133}134}135136// setter has been overriden137public static class IChild3 extends IParent {138public void setFoo(int i, String str) {139}140}141142// methods should be taken from superclass143public static class IChild4 extends IParent {144}145}146147148