View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.configuration;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  
23  import org.junit.After;
24  import org.junit.Before;
25  import org.junit.Test;
26  
27  /**
28   * @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a>
29   */
30  public class TestConfigurationMap
31  {
32  
33      ConfigurationMap map;
34  
35      String[] properties = {
36              "booleanProperty",
37              "doubleProperty",
38              "floatProperty",
39              "intProperty",
40              "longProperty",
41              "shortProperty",
42              "stringProperty"
43      };
44  
45      Object[] values = {
46              Boolean.TRUE,
47              new Double(Double.MAX_VALUE),
48              new Float(Float.MAX_VALUE),
49              new Integer(Integer.MAX_VALUE),
50              new Long(Long.MAX_VALUE),
51              new Short(Short.MAX_VALUE),
52              "This is a string"
53      };
54  
55      /**
56       * Set up instance variables required by this test case.
57       */
58      @Before
59      public void setUp() throws Exception
60      {
61          BaseConfiguration configuration = new BaseConfiguration();
62          for(int i = 0; i < properties.length ; i++)
63              configuration.setProperty(properties[i], values[i]);
64          map = new ConfigurationMap(configuration);
65      }
66  
67      /**
68       * Tear down instance variables required by this test case.
69       */
70      @After
71      public void tearDown()
72      {
73          map = null;
74      }
75  
76      /**
77       * Class under test for Object put(Object, Object)
78       */
79      @Test
80      public void testPut()
81      {
82          for(int i = 0; i < properties.length; i++) {
83              Object object = map.put(properties[i], values[i]);
84              assertNotNull("Returned null from put.",object);
85              assertEquals("Returned wrong result.",values[i],object);
86              object = map.get(properties[i]);
87              assertNotNull("Returned null from get.",object);
88              assertEquals("Returned wrong result.",values[i],object);
89          }
90      }
91  
92  }