Test4918902.java revision 2362
10139N/A/*
10139N/A * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
10139N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12147N/A *
10139N/A * This code is free software; you can redistribute it and/or modify it
10139N/A * under the terms of the GNU General Public License version 2 only, as
10139N/A * published by the Free Software Foundation.
17820N/A *
10139N/A * This code is distributed in the hope that it will be useful, but WITHOUT
17177N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17177N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17177N/A * version 2 for more details (a copy is included in the LICENSE file that
10139N/A * accompanied this code).
10139N/A *
10139N/A * You should have received a copy of the GNU General Public License version
10139N/A * 2 along with this work; if not, write to the Free Software Foundation,
18365N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10139N/A *
10139N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10139N/A * or visit www.oracle.com if you need additional information or have any
10139N/A * questions.
17882N/A */
10159N/A
12094N/A/*
12773N/A * @test
12773N/A * @bug 4918902
12773N/A * @summary Tests search the most specific methods for PropertyDescriptors
10139N/A * @author Mark Davidson
10139N/A */
10139N/A
10139N/Aimport java.beans.PropertyDescriptor;
10139N/Aimport java.beans.IndexedPropertyDescriptor;
10139N/A
10139N/Apublic class Test4918902 {
10139N/A public static void main(String[] args) {
10139N/A testPropertyDescriptor(Child1.class, Child1.class, Parent.class);
10139N/A testPropertyDescriptor(Child2.class, Parent.class, Child2.class);
10139N/A testPropertyDescriptor(Child3.class, Child3.class, Child3.class);
10139N/A testPropertyDescriptor(Child4.class, Parent.class, Parent.class);
10139N/A
10139N/A testPropertyDescriptor(Grandchild.class, Child3.class, Child3.class);
10139N/A
10139N/A testIndexedPropertyDescriptor(IChild1.class, IChild1.class, IChild1.class);
10139N/A testIndexedPropertyDescriptor(IChild2.class, IChild2.class, IParent.class);
10139N/A testIndexedPropertyDescriptor(IChild3.class, IParent.class, IChild3.class);
10139N/A testIndexedPropertyDescriptor(IChild4.class, IParent.class, IParent.class);
10139N/A }
10139N/A
10139N/A private static void testPropertyDescriptor(Class type, Class read, Class write) {
10139N/A PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "foo");
10139N/A if (!read.equals(pd.getReadMethod().getDeclaringClass())) {
10139N/A throw new Error("unexpected read method: " + pd.getReadMethod());
10139N/A }
10139N/A if (!write.equals(pd.getWriteMethod().getDeclaringClass())) {
10139N/A throw new Error("unexpected write method: " + pd.getWriteMethod());
10139N/A }
10139N/A }
10139N/A
10139N/A private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
10139N/A IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
10139N/A if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
10139N/A throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
10139N/A }
10139N/A if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
12094N/A throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
12754N/A }
10159N/A }
10139N/A
10139N/A // simple properties
10139N/A public static class Parent {
10139N/A public String getFoo() {
10139N/A return null;
10139N/A }
10139N/A
10139N/A public void setFoo(String str) {
10139N/A }
10139N/A }
10139N/A
10139N/A // getter has been overriden
10139N/A public static class Child1 extends Parent {
10139N/A public String getFoo() {
10139N/A return null;
10139N/A }
10139N/A }
10139N/A
10139N/A // setter has been overriden
10139N/A public static class Child2 extends Parent {
11149N/A public void setFoo(String str) {
12773N/A }
12773N/A }
12773N/A
12773N/A // both methods have been overriden
12773N/A public static class Child3 extends Parent {
10139N/A public void setFoo(String str) {
10139N/A }
10139N/A
10139N/A public String getFoo() {
10139N/A return null;
10139N/A }
10139N/A }
10139N/A
10139N/A // methods should be taken from superclass
10139N/A public static class Child4 extends Parent {
10139N/A }
17882N/A
10139N/A // methods should be taken from superclass
10139N/A public static class Grandchild extends Child3 {
10139N/A }
10139N/A
10139N/A // indexed properties
10139N/A public static class IParent {
10139N/A public String getFoo(int i) {
10139N/A return null;
10139N/A }
10139N/A
10139N/A public void setFoo(int i, String str) {
12184N/A }
10139N/A }
10139N/A
10139N/A // both methods have been overriden
10139N/A public static class IChild1 extends IParent {
10139N/A public void setFoo(int i, String str) {
10139N/A }
10139N/A
10139N/A public String getFoo(int i) {
10139N/A return null;
10139N/A }
10139N/A }
10139N/A
10139N/A // getter has been overriden
10139N/A public static class IChild2 extends IParent {
10139N/A public String getFoo(int i) {
10139N/A return null;
12184N/A }
10139N/A }
10139N/A
10139N/A // setter has been overriden
10139N/A public static class IChild3 extends IParent {
10139N/A public void setFoo(int i, String str) {
10139N/A }
10139N/A }
10139N/A
18365N/A // methods should be taken from superclass
18365N/A public static class IChild4 extends IParent {
18300N/A }
18300N/A}
18236N/A