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