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 java.lang.reflect.Method;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25 import org.apache.commons.beanutils.MethodUtils;
26 import org.apache.commons.beanutils.PropertyUtils;
27 import org.apache.commons.beanutils.bugs.other.Jira298BeanFactory;
28 import org.apache.commons.beanutils.bugs.other.Jira298BeanFactory.IX;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32
33
34
35
36 public class Jira298TestCase extends TestCase {
37
38 private final Log log = LogFactory.getLog(Jira298TestCase.class);
39
40
41
42
43
44
45 public Jira298TestCase(final String name) {
46 super(name);
47 }
48
49
50
51
52
53
54 public static void main(final String[] args) {
55 junit.textui.TestRunner.run(suite());
56 }
57
58
59
60
61
62
63 public static Test suite() {
64 return (new TestSuite(Jira298TestCase.class));
65 }
66
67
68
69
70
71
72 @Override
73 protected void setUp() throws Exception {
74 super.setUp();
75 }
76
77
78
79
80
81
82 @Override
83 protected void tearDown() throws Exception {
84 super.tearDown();
85 }
86
87
88
89
90 public void testIssue_BEANUTILS_298_PropertyUtils_getProperty() {
91 final Object bean = Jira298BeanFactory.createImplX();
92 Object result = null;
93 try {
94 result = PropertyUtils.getProperty(bean, "name");
95 } catch (final Throwable t) {
96 log.error("Failed: " + t.getMessage(), t);
97 fail("Threw exception: " + t);
98 }
99 assertEquals("BaseX name value", result);
100 }
101
102
103
104
105 public void testIssue_BEANUTILS_298_PropertyUtils_setProperty() {
106 final Object bean = Jira298BeanFactory.createImplX();
107 assertEquals("BaseX name value", ((IX)bean).getName());
108 try {
109 PropertyUtils.setProperty(bean, "name", "new name");
110 } catch (final Throwable t) {
111 log.error("Failed: " + t.getMessage(), t);
112 fail("Threw exception: " + t);
113 }
114 assertEquals("new name", ((IX)bean).getName());
115 }
116
117
118
119
120 public void testIssue_BEANUTILS_298_MethodUtils_getAccessibleMethod() {
121 final Object bean = Jira298BeanFactory.createImplX();
122 Object result = null;
123 try {
124 final Method m2 = MethodUtils.getAccessibleMethod(bean.getClass(), "getName", new Class[0]);
125 result = m2.invoke(bean);
126 } catch (final Throwable t) {
127 log.error("Failed: " + t.getMessage(), t);
128 fail("Threw exception: " + t);
129 }
130 assertEquals("BaseX name value", result);
131 }
132 }