1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23 /***
24 * @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a>
25 */
26 public class TestConfigurationMap extends TestCase
27 {
28
29 ConfigurationMap map;
30
31 String[] properties = {
32 "booleanProperty",
33 "doubleProperty",
34 "floatProperty",
35 "intProperty",
36 "longProperty",
37 "shortProperty",
38 "stringProperty"
39 };
40
41 Object[] values = {
42 Boolean.TRUE,
43 new Double(Double.MAX_VALUE),
44 new Float(Float.MAX_VALUE),
45 new Integer(Integer.MAX_VALUE),
46 new Long(Long.MAX_VALUE),
47 new Short(Short.MAX_VALUE),
48 "This is a string"
49 };
50
51 /***
52 * Construct a new instance of this test case.
53 * @param name Name of the test case
54 */
55 public TestConfigurationMap(String name)
56 {
57 super(name);
58 }
59
60 /***
61 * Set up instance variables required by this test case.
62 */
63 public void setUp() throws Exception
64 {
65 BaseConfiguration configuration = new BaseConfiguration();
66 for(int i = 0; i < properties.length ; i++)
67 configuration.setProperty(properties[i], values[i]);
68 map = new ConfigurationMap(configuration);
69 }
70
71 /***
72 * Return the tests included in this test suite.
73 */
74 public static Test suite()
75 {
76 return (new TestSuite(TestConfigurationMap.class));
77 }
78
79 /***
80 * Tear down instance variables required by this test case.
81 */
82 public void tearDown()
83 {
84 map = null;
85 }
86
87 /***
88 * Class under test for Object put(Object, Object)
89 */
90 public void testPut()
91 {
92 for(int i = 0; i < properties.length; i++) {
93 Object object = map.put(properties[i], values[i]);
94 assertNotNull("Returned null from put.",object);
95 assertEquals("Returned wrong result.",values[i],object);
96 object = map.get(properties[i]);
97 assertNotNull("Returned null from get.",object);
98 assertEquals("Returned wrong result.",values[i],object);
99 }
100 }
101
102 }