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.configuration2;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  import static org.junit.jupiter.api.Assertions.assertNotNull;
22  import static org.junit.jupiter.api.Assertions.assertThrows;
23  
24  import org.junit.jupiter.api.AfterEach;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   */
30  public class TestConfigurationMap {
31  
32      ConfigurationMap map;
33  
34      String[] properties = {"booleanProperty", "doubleProperty", "floatProperty", "intProperty", "longProperty", "shortProperty", "stringProperty"};
35  
36      Object[] values = {Boolean.TRUE, Double.valueOf(Double.MAX_VALUE), Float.valueOf(Float.MAX_VALUE), Integer.valueOf(Integer.MAX_VALUE),
37          Long.valueOf(Long.MAX_VALUE), Short.valueOf(Short.MAX_VALUE), "This is a string"};
38  
39      /**
40       * Sets up instance variables required by this test case.
41       */
42      @BeforeEach
43      public void setUp() throws Exception {
44          final BaseConfiguration configuration = new BaseConfiguration();
45          for (int i = 0; i < properties.length; i++) {
46              configuration.setProperty(properties[i], values[i]);
47          }
48          map = new ConfigurationMap(configuration);
49      }
50  
51      /**
52       * Tear down instance variables required by this test case.
53       */
54      @AfterEach
55      public void tearDown() {
56          map = null;
57      }
58  
59      /**
60       * Attempts to create a ConfigurationMap with null configuration. This should cause an exception.
61       */
62      @Test
63      public void testNullConfig() {
64          assertThrows(NullPointerException.class, () -> new ConfigurationMap(null));
65      }
66  
67      /**
68       * Class under test for Object put(Object, Object)
69       */
70      @Test
71      public void testPut() {
72          for (int i = 0; i < properties.length; i++) {
73              Object object = map.put(properties[i], values[i]);
74              assertNotNull(object);
75              assertEquals(values[i], object);
76              object = map.get(properties[i]);
77              assertNotNull(object);
78              assertEquals(values[i], object);
79          }
80      }
81  
82  }