1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils.bugs;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.beans.BeanInfo;
22 import java.beans.IndexedPropertyDescriptor;
23 import java.beans.IntrospectionException;
24 import java.beans.Introspector;
25 import java.beans.PropertyDescriptor;
26 import java.util.List;
27
28 import org.apache.commons.beanutils.PropertyUtils;
29 import org.junit.Assert;
30 import org.junit.Assume;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34
35
36
37
38
39
40
41
42
43
44
45 public class Jira422TestCase {
46
47
48
49
50
51
52 @BeforeClass
53 public static void assumeSupportsIndexedLists() throws IntrospectionException {
54 BeanInfo beanInfo = Introspector.getBeanInfo(RootBean.class);
55 for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
56 if (pd.getName().equals("file")) {
57 Assume.assumeTrue("BEANUTILS-492: IndexedPropertyDescriptor no longer supported for java.util.List",
58 pd instanceof IndexedPropertyDescriptor);
59 return;
60 }
61 }
62 Assert.fail("Could not find PropertyDescriptor for 'file'");
63 }
64
65 @Test
66 public void testRootBean() throws Exception {
67 final RootBean bean = new FirstChildBean();
68 final Class<?> propertyType = PropertyUtils.getPropertyType(bean, "file[0]");
69 assertEquals(String.class.getName(), propertyType.getName());
70 }
71
72 @Test
73 public void testSecondChildBean() throws Exception {
74 final RootBean bean = new SecondChildBean();
75 final Class<?> propertyType = PropertyUtils.getPropertyType(bean, "file[0]");
76 assertEquals(String.class.getName(), propertyType.getName());
77 }
78
79 }
80
81 @SuppressWarnings("rawtypes")
82 class RootBean {
83
84 private List file;
85
86 public List getFile() {
87 return file;
88 }
89
90 public void setFile(final List file) {
91 this.file = file;
92 }
93
94 public String getFile(final int i) {
95 return (String) file.get(i);
96 }
97
98 @SuppressWarnings("unchecked")
99 public void setFile(final int i, final String file) {
100 this.file.set(i, file);
101 }
102
103 }
104
105 class FirstChildBean extends RootBean {
106 }
107
108 class SecondChildBean extends RootBean {
109 }