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.assertNull;
20
21 import java.util.Comparator;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.commons.beanutils2.BeanUtils;
26 import org.apache.commons.beanutils2.PropertyUtils;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.junit.jupiter.api.AfterEach;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32
33
34
35
36 public class Jira339Test {
37
38
39
40
41 public static class TestBean {
42 private Comparator<?> comparator;
43
44
45
46
47
48
49 public Comparator<?> getComparator() {
50 return comparator;
51 }
52
53
54
55
56
57
58 public void setComparator(final Comparator<?> comparator) {
59 this.comparator = comparator;
60 }
61
62 }
63
64 private static final Log LOG = LogFactory.getLog(Jira339Test.class);
65
66
67
68
69
70
71 @BeforeEach
72 protected void setUp() throws Exception {
73 }
74
75
76
77
78
79
80 @AfterEach
81 protected void tearDown() throws Exception {
82 }
83
84
85
86
87 @Test
88 public void testIssue_BEANUTILS_331_BeanUtilsBean_populate() throws Exception {
89 final TestBean bean = new TestBean();
90 final Map<String, Object> properties = new HashMap<>();
91 properties.put("comparator", null);
92 BeanUtils.populate(bean, properties);
93 assertNull(bean.getComparator(), "TestBean comparator should be null");
94 }
95
96
97
98
99 @Test
100 public void testIssue_BEANUTILS_339_BeanUtilsBean_setProperty() throws Exception {
101 final TestBean bean = new TestBean();
102 BeanUtils.setProperty(bean, "comparator", null);
103 assertNull(bean.getComparator(), "TestBean comparator should be null");
104 }
105 }