blob: 93edd687b31e7f4d9281a0a5d4eb59bd5e19d67e [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4168833
27 * @summary Tests that Introspector does not create IndexedPropertyDescriptor
28 * from non-indexed PropertyDescriptor
29 * @author Mark Davidson
30 */
31
32import java.awt.Color;
33import java.awt.Dimension;
34
35import java.beans.IndexedPropertyDescriptor;
36import java.beans.PropertyDescriptor;
37
38/**
39 * The base class "color" property
40 * creates both an IndexedPropertyDescriptor which has a conflicting
41 * type for getColor.
42 */
43public class Test4168833 {
44 public static void main(String[] args) throws Exception {
45 IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(Base.class, "prop");
46 if (!ipd.getIndexedPropertyType().equals(Dimension.class)) {
47 error(ipd, "Base.prop property should a Dimension");
48 }
49 // When the Sub class is introspected,
50 // the property type should be color.
51 // The complete "classic" set of properties
52 // has been completed accross the hierarchy.
53 test(Sub.class);
54 test(Sub2.class);
55 }
56
57 private static void test(Class type) {
58 PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "prop");
59 if (pd instanceof IndexedPropertyDescriptor) {
60 error(pd, type.getSimpleName() + ".prop should not be an indexed property");
61 }
62 if (!pd.getPropertyType().equals(Color.class)) {
63 error(pd, type.getSimpleName() + ".prop type should be a Color");
64 }
65 if (null == pd.getReadMethod()) {
66 error(pd, type.getSimpleName() + ".prop should have classic read method");
67 }
68 if (null == pd.getWriteMethod()) {
69 error(pd, type.getSimpleName() + ".prop should have classic write method");
70 }
71 }
72
73 private static void error(PropertyDescriptor pd, String message) {
74 BeanUtils.reportPropertyDescriptor(pd);
75 throw new Error(message);
76 }
77
78 public static class Base {
79 public Color getProp() {
80 return null;
81 }
82
83 public Dimension getProp(int i) {
84 return null;
85 }
86 }
87
88 public static class Sub extends Base {
89 public void setProp(Color c) {
90 }
91 }
92
93 public static class Base2 {
94 public void setProp(Color c) {
95 }
96
97 public void setProp(int i, Dimension d) {
98 }
99 }
100
101 public static class Sub2 extends Base2 {
102 public Color getProp() {
103 return null;
104 }
105 }
106}