Path: blob/master/test/jdk/java/beans/Introspector/Test4168833.java
41149 views
/*1* Copyright (c) 2003, 2014, 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 4168833 803408526* @summary Tests that Introspector does not create IndexedPropertyDescriptor27* from non-indexed PropertyDescriptor28* @author Mark Davidson29* @author Sergey Malenkov30*/3132import java.awt.Color;33import java.awt.Dimension;3435import java.beans.IndexedPropertyDescriptor;36import java.beans.PropertyDescriptor;3738/**39* The base class "color" property40* creates both an IndexedPropertyDescriptor which has a conflicting41* type for getColor.42*/43public class Test4168833 {44public static void main(String[] args) throws Exception {45// When the Sub class is introspected,46// the property type should be color.47// The complete "classic" set of properties48// has been completed accross the hierarchy.49test(Sub.class);50test(Sub2.class);51}5253private static void test(Class type) {54PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "prop");55if (pd instanceof IndexedPropertyDescriptor) {56error(pd, type.getSimpleName() + ".prop should not be an indexed property");57}58if (!pd.getPropertyType().equals(Color.class)) {59error(pd, type.getSimpleName() + ".prop type should be a Color");60}61if (null == pd.getReadMethod()) {62error(pd, type.getSimpleName() + ".prop should have classic read method");63}64if (null == pd.getWriteMethod()) {65error(pd, type.getSimpleName() + ".prop should have classic write method");66}67}6869private static void error(PropertyDescriptor pd, String message) {70BeanUtils.reportPropertyDescriptor(pd);71throw new Error(message);72}7374public static class Base {75public Color getProp() {76return null;77}7879public Dimension getProp(int i) {80return null;81}82}8384public static class Sub extends Base {85public void setProp(Color c) {86}87}8889public static class Base2 {90public void setProp(Color c) {91}9293public void setProp(int i, Dimension d) {94}95}9697public static class Sub2 extends Base2 {98public Color getProp() {99return null;100}101}102}103104105