001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.configuration; 019 020 import static org.junit.Assert.assertEquals; 021 import static org.junit.Assert.assertNotNull; 022 023 import org.junit.After; 024 import org.junit.Before; 025 import org.junit.Test; 026 027 /** 028 * @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a> 029 */ 030 public class TestConfigurationMap 031 { 032 033 ConfigurationMap map; 034 035 String[] properties = { 036 "booleanProperty", 037 "doubleProperty", 038 "floatProperty", 039 "intProperty", 040 "longProperty", 041 "shortProperty", 042 "stringProperty" 043 }; 044 045 Object[] values = { 046 Boolean.TRUE, 047 new Double(Double.MAX_VALUE), 048 new Float(Float.MAX_VALUE), 049 new Integer(Integer.MAX_VALUE), 050 new Long(Long.MAX_VALUE), 051 new Short(Short.MAX_VALUE), 052 "This is a string" 053 }; 054 055 /** 056 * Set up instance variables required by this test case. 057 */ 058 @Before 059 public void setUp() throws Exception 060 { 061 BaseConfiguration configuration = new BaseConfiguration(); 062 for(int i = 0; i < properties.length ; i++) 063 configuration.setProperty(properties[i], values[i]); 064 map = new ConfigurationMap(configuration); 065 } 066 067 /** 068 * Tear down instance variables required by this test case. 069 */ 070 @After 071 public void tearDown() 072 { 073 map = null; 074 } 075 076 /** 077 * Class under test for Object put(Object, Object) 078 */ 079 @Test 080 public void testPut() 081 { 082 for(int i = 0; i < properties.length; i++) { 083 Object object = map.put(properties[i], values[i]); 084 assertNotNull("Returned null from put.",object); 085 assertEquals("Returned wrong result.",values[i],object); 086 object = map.get(properties[i]); 087 assertNotNull("Returned null from get.",object); 088 assertEquals("Returned wrong result.",values[i],object); 089 } 090 } 091 092 }