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  package org.apache.commons.configuration;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  
22  import org.junit.Test;
23  
24  /**
25   * Test if non-string properties are handled correctly.
26   *
27   * @version $Id: BaseNonStringProperties.java 1302002 2012-03-17 20:43:46Z sebb $
28   */
29  public abstract class BaseNonStringProperties
30  {
31  
32      protected NonStringTestHolder nonStringTestHolder = new NonStringTestHolder();
33  
34      protected Configuration conf;
35  
36      @Test
37      public void testBoolean() throws Exception
38      {
39          nonStringTestHolder.testBoolean();
40      }
41  
42      @Test
43      public void testBooleanDefaultValue() throws Exception
44      {
45          nonStringTestHolder.testBooleanDefaultValue();
46      }
47  
48      @Test
49      public void testBooleanArrayValue() throws Exception
50      {
51          boolean booleanValue = conf.getBoolean("test.boolean");
52          assertTrue(booleanValue);
53          assertEquals(2, conf.getList("test.boolean.array").size());
54      }
55  
56      @Test
57      public void testByte() throws Exception
58      {
59          nonStringTestHolder.testByte();
60      }
61  
62      @Test
63      public void testByteArrayValue() throws Exception
64      {
65          byte testValue = 10;
66          byte byteValue = conf.getByte("test.byte");
67          assertEquals(testValue, byteValue);
68          assertEquals(2, conf.getList("test.byte.array").size());
69      }
70  
71      @Test
72      public void testDouble() throws Exception
73      {
74          nonStringTestHolder.testDouble();
75      }
76  
77      @Test
78      public void testDoubleDefaultValue() throws Exception
79      {
80          nonStringTestHolder.testDoubleDefaultValue();
81      }
82  
83      @Test
84      public void testDoubleArrayValue() throws Exception
85      {
86          double testValue = 10.25;
87          double doubleValue = conf.getDouble("test.double");
88          assertEquals(testValue, doubleValue, 0.01);
89          assertEquals(2, conf.getList("test.double.array").size());
90      }
91  
92      @Test
93      public void testFloat() throws Exception
94      {
95          nonStringTestHolder.testFloat();
96      }
97  
98      @Test
99      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 }