KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > TestConfigurationMap


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 JavaDoc[] properties = {
32             "booleanProperty",
33             "doubleProperty",
34             "floatProperty",
35             "intProperty",
36             "longProperty",
37             "shortProperty",
38             "stringProperty"
39     };
40     
41     Object JavaDoc[] values = {
42             Boolean.TRUE,
43             new Double JavaDoc(Double.MAX_VALUE),
44             new Float JavaDoc(Float.MAX_VALUE),
45             new Integer JavaDoc(Integer.MAX_VALUE),
46             new Long JavaDoc(Long.MAX_VALUE),
47             new Short JavaDoc(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 JavaDoc 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 JavaDoc
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 JavaDoc 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 }
103
Popular Tags