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.util.Comparator;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26
27 import org.apache.commons.beanutils.BeanUtils;
28 import org.apache.commons.beanutils.PropertyUtils;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32
33
34
35
36 public class Jira339TestCase extends TestCase {
37
38 private final Log log = LogFactory.getLog(Jira339TestCase.class);
39
40
41
42
43
44
45 public Jira339TestCase(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(Jira339TestCase.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_339_BeanUtilsBean_setProperty() {
91
92 final TestBean bean = new TestBean();
93 try {
94 BeanUtils.setProperty(bean, "comparator", null);
95 } catch (final Throwable t) {
96 log.error("Failed: " + t.getMessage(), t);
97 fail("Threw exception: " + t);
98 }
99 assertNull("TestBean comparator should be null", bean.getComparator());
100 }
101
102
103
104
105 public void testIssue_BEANUTILS_331_BeanUtilsBean_populate() {
106
107 final TestBean bean = new TestBean();
108 try {
109 final Map<String, Object> properties = new HashMap<String, Object>();
110 properties.put("comparator", null);
111 BeanUtils.populate(bean, properties);
112 } catch (final Throwable t) {
113 log.error("Failed: " + t.getMessage(), t);
114 fail("Threw exception: " + t);
115 }
116 assertNull("TestBean comparator should be null", bean.getComparator());
117 }
118
119
120
121
122 public static class TestBean {
123 private Comparator<?> comparator;
124
125
126
127
128
129
130 public Comparator<?> getComparator() {
131 return comparator;
132 }
133
134
135
136
137
138
139 public void setComparator(final Comparator<?> comparator) {
140 this.comparator = comparator;
141 }
142
143 }
144 }