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    package org.apache.commons.configuration;
018    
019    import static org.junit.Assert.assertEquals;
020    import static org.junit.Assert.assertTrue;
021    
022    import org.junit.Test;
023    
024    /**
025     * Test if non-string properties are handled correctly.
026     *
027     * @version $Id: BaseNonStringProperties.java 1302002 2012-03-17 20:43:46Z sebb $
028     */
029    public abstract class BaseNonStringProperties
030    {
031    
032        protected NonStringTestHolder nonStringTestHolder = new NonStringTestHolder();
033    
034        protected Configuration conf;
035    
036        @Test
037        public void testBoolean() throws Exception
038        {
039            nonStringTestHolder.testBoolean();
040        }
041    
042        @Test
043        public void testBooleanDefaultValue() throws Exception
044        {
045            nonStringTestHolder.testBooleanDefaultValue();
046        }
047    
048        @Test
049        public void testBooleanArrayValue() throws Exception
050        {
051            boolean booleanValue = conf.getBoolean("test.boolean");
052            assertTrue(booleanValue);
053            assertEquals(2, conf.getList("test.boolean.array").size());
054        }
055    
056        @Test
057        public void testByte() throws Exception
058        {
059            nonStringTestHolder.testByte();
060        }
061    
062        @Test
063        public void testByteArrayValue() throws Exception
064        {
065            byte testValue = 10;
066            byte byteValue = conf.getByte("test.byte");
067            assertEquals(testValue, byteValue);
068            assertEquals(2, conf.getList("test.byte.array").size());
069        }
070    
071        @Test
072        public void testDouble() throws Exception
073        {
074            nonStringTestHolder.testDouble();
075        }
076    
077        @Test
078        public void testDoubleDefaultValue() throws Exception
079        {
080            nonStringTestHolder.testDoubleDefaultValue();
081        }
082    
083        @Test
084        public void testDoubleArrayValue() throws Exception
085        {
086            double testValue = 10.25;
087            double doubleValue = conf.getDouble("test.double");
088            assertEquals(testValue, doubleValue, 0.01);
089            assertEquals(2, conf.getList("test.double.array").size());
090        }
091    
092        @Test
093        public void testFloat() throws Exception
094        {
095            nonStringTestHolder.testFloat();
096        }
097    
098        @Test
099        public void testFloatDefaultValue() throws Exception
100        {
101            nonStringTestHolder.testFloatDefaultValue();
102    
103        }
104    
105        @Test
106        public void testFloatArrayValue() throws Exception
107        {
108            float testValue = (float) 20.25;
109            float floatValue = conf.getFloat("test.float");
110            assertEquals(testValue, floatValue, 0.01);
111            assertEquals(2, conf.getList("test.float.array").size());
112        }
113    
114        @Test
115        public void testInteger() throws Exception
116        {
117            nonStringTestHolder.testInteger();
118        }
119    
120        @Test
121        public void testIntegerDefaultValue() throws Exception
122        {
123            nonStringTestHolder.testIntegerDefaultValue();
124        }
125    
126        @Test
127        public void testIntegerArrayValue() throws Exception
128        {
129            int intValue = conf.getInt("test.integer");
130            assertEquals(10, intValue);
131            assertEquals(2, conf.getList("test.integer.array").size());
132        }
133    
134        @Test
135        public void testLong() throws Exception
136        {
137            nonStringTestHolder.testLong();
138        }
139    
140        @Test
141        public void testLongDefaultValue() throws Exception
142        {
143            nonStringTestHolder.testLongDefaultValue();
144        }
145    
146        @Test
147        public void testLongArrayValue() throws Exception
148        {
149            long longValue = conf.getLong("test.long");
150            assertEquals(1000000, longValue);
151            assertEquals(2, conf.getList("test.long.array").size());
152        }
153    
154        @Test
155        public void testShort() throws Exception
156        {
157            nonStringTestHolder.testShort();
158        }
159    
160        @Test
161        public void testShortDefaultValue() throws Exception
162        {
163            nonStringTestHolder.testShortDefaultValue();
164        }
165    
166        @Test
167        public void testShortArrayValue() throws Exception
168        {
169            short shortValue = conf.getShort("test.short");
170            assertEquals(1, shortValue);
171            assertEquals(2, conf.getList("test.short.array").size());
172        }
173    
174        @Test
175        public void testListMissing() throws Exception
176        {
177            nonStringTestHolder.testListMissing();
178        }
179    
180        @Test
181        public void testSubset() throws Exception
182        {
183            nonStringTestHolder.testSubset();
184        }
185    
186        @Test
187        public void testIsEmpty() throws Exception
188        {
189            nonStringTestHolder.testIsEmpty();
190        }
191    }