1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils2.bugs;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21
22 import java.beans.PropertyDescriptor;
23
24 import org.apache.commons.beanutils2.PropertyUtils;
25 import org.junit.jupiter.api.AfterEach;
26 import org.junit.jupiter.api.BeforeEach;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 public class Jira357Test {
33
34
35
36
37 public abstract static class AbstractTestBean {
38
39
40 public abstract static class InnerClass {
41 private String firstName;
42
43 public String getInnerName() {
44 return firstName;
45 }
46
47 public void setInnerName(final String firstName) {
48 this.firstName = firstName;
49 }
50 }
51
52 public abstract String getFoo();
53
54 public abstract AbstractTestBean.InnerClass getInnerClassProperty();
55
56 public abstract boolean isBar();
57
58 public abstract void setBar(boolean bar);
59
60 public abstract void setFoo(String foo);
61 }
62
63
64
65
66 public static class ConcreteTestBean extends AbstractTestBean {
67
68 private String foo;
69 private boolean bar;
70 private ConcreteTestBean.InnerClass innerClassProperty;
71
72 @Override
73 public String getFoo() {
74 return foo;
75 }
76
77 @Override
78 public ConcreteTestBean.InnerClass getInnerClassProperty() {
79 return innerClassProperty;
80 }
81
82 @Override
83 public boolean isBar() {
84 return bar;
85 }
86
87 @Override
88 public void setBar(final boolean bar) {
89 this.bar = bar;
90 }
91
92 @Override
93 public void setFoo(final String foo) {
94 this.foo = foo;
95 }
96
97 public void setInnerClassProperty(final ConcreteTestBean.InnerClass innerClassProperty) {
98 this.innerClassProperty = innerClassProperty;
99 }
100 }
101
102
103
104
105 private void checkReadMethod(final String propertyName, final Class<?> expectedDeclaringClass) throws Exception {
106
107 PropertyDescriptor[] descriptors = null;
108 descriptors = PropertyUtils.getPropertyDescriptors(ConcreteTestBean.class);
109
110
111 final PropertyDescriptor descriptor = findDescriptor(propertyName, descriptors);
112 assertNotNull(descriptor, propertyName + "descriptor");
113 assertEquals(expectedDeclaringClass, descriptor.getReadMethod().getDeclaringClass(), propertyName + " read method declaring class");
114 }
115
116
117
118
119 private PropertyDescriptor findDescriptor(final String propertyName, final PropertyDescriptor[] descriptors) {
120 if (descriptors != null) {
121 for (final PropertyDescriptor descriptor : descriptors) {
122 if (propertyName.equals(descriptor.getName())) {
123 return descriptor;
124 }
125 }
126 }
127 return null;
128 }
129
130
131
132
133
134
135 @BeforeEach
136 protected void setUp() throws Exception {
137 }
138
139
140
141
142
143
144 @AfterEach
145 protected void tearDown() throws Exception {
146 }
147
148
149
150
151 @Test
152 public void testPropertyUtils_getPropertyDescriptors_Bar() throws Exception {
153 checkReadMethod("bar", ConcreteTestBean.class);
154 }
155
156
157
158
159 @Test
160 public void testPropertyUtils_getPropertyDescriptors_Foo() throws Exception {
161 checkReadMethod("foo", ConcreteTestBean.class);
162 }
163
164
165
166
167 @Test
168 public void testPropertyUtils_getPropertyDescriptors_InnerClassProperty() throws Exception {
169 checkReadMethod("innerClassProperty", ConcreteTestBean.class);
170 }
171 }