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