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