1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils.locale;
18
19 import junit.framework.TestCase;
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23 import org.apache.commons.beanutils.TestBean;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27
28
29
30
31
32 public class LocaleBeanUtilsTestCase extends TestCase {
33
34 private static Log log = LogFactory.getLog(LocaleBeanUtilsTestCase.class);
35
36
37
38
39
40
41 public LocaleBeanUtilsTestCase(final String name) {
42 super(name);
43 }
44
45
46
47
48
49
50
51
52 @Override
53 public void setUp() {
54 }
55
56
57
58
59
60
61 public static Test suite() {
62 return (new TestSuite(LocaleBeanUtilsTestCase.class));
63 }
64
65
66
67
68
69 @Override
70 public void tearDown() {
71 }
72
73
74
75
76
77
78
79 public void testSetNestedPropertySimple() {
80 final TestBean bean = new TestBean();
81 bean.getNested().setIntProperty(5);
82 assertEquals("Initial value 5", 5, bean.getNested().getIntProperty());
83 try {
84 LocaleBeanUtils.setProperty(bean, "nested.intProperty", "123", null);
85 } catch (final Throwable t) {
86 log.error(t);
87 fail("Threw " + t);
88 }
89 assertEquals("Check Set Value", 123, bean.getNested().getIntProperty());
90 }
91
92
93
94
95 public void testSetNestedPropertyIndexed() {
96 final TestBean bean = new TestBean();
97 bean.getNested().setIntIndexed(1, 51);
98 assertEquals("Initial value[1] 51", 51, bean.getNested().getIntIndexed(1));
99 try {
100 LocaleBeanUtils.setProperty(bean, "nested.intIndexed[1]", "123", null);
101 } catch (final Throwable t) {
102 log.error(t);
103 fail("Threw " + t);
104 }
105 assertEquals("Check Set Value", 123, bean.getNested().getIntIndexed(1));
106 }
107 }
108