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 * Test Case for {@link LocaleBeanUtils}.
29 *
30 * @version $Revision: 555476 $ $Date: 2007-07-12 04:08:37 +0100 (Thu, 12 Jul 2007) $
31 */
32 public class LocaleBeanUtilsTestCase extends TestCase {
33
34 private static Log log = LogFactory.getLog(LocaleBeanUtilsTestCase.class);
35
36 /***
37 * Construct a new instance of this test case.
38 *
39 * @param name Name of the test case
40 */
41 public LocaleBeanUtilsTestCase(String name) {
42 super(name);
43 }
44
45
46
47
48
49 /***
50 * Set up instance variables required by this test case.
51 */
52 public void setUp() {
53 }
54
55
56 /***
57 * Return the tests included in this test suite.
58 * @return Test Suite
59 */
60 public static Test suite() {
61 return (new TestSuite(LocaleBeanUtilsTestCase.class));
62 }
63
64
65 /***
66 * Tear down instance variables required by this test case.
67 */
68 public void tearDown() {
69 }
70
71
72
73
74 /***
75 * Test setting a nested simple property
76 */
77 public void testSetNestedPropertySimple() {
78 TestBean bean = new TestBean();
79 bean.getNested().setIntProperty(5);
80 assertEquals("Initial value 5", 5, bean.getNested().getIntProperty());
81 try {
82 LocaleBeanUtils.setProperty(bean, "nested.intProperty", "123", null);
83 } catch (Throwable t) {
84 log.error(t);
85 fail("Threw " + t);
86 }
87 assertEquals("Check Set Value", 123, bean.getNested().getIntProperty());
88 }
89
90 /***
91 * Test setting a nested indexed property
92 */
93 public void testSetNestedPropertyIndexed() {
94 TestBean bean = new TestBean();
95 bean.getNested().setIntIndexed(1, 51);
96 assertEquals("Initial value[1] 51", 51, bean.getNested().getIntIndexed(1));
97 try {
98 LocaleBeanUtils.setProperty(bean, "nested.intIndexed[1]", "123", null);
99 } catch (Throwable t) {
100 log.error(t);
101 fail("Threw " + t);
102 }
103 assertEquals("Check Set Value", 123, bean.getNested().getIntIndexed(1));
104 }
105 }
106