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