    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 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 }