1
package org.apache.commons.configuration;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import junit.framework.TestCase;
23
* Test if non-string properties are handled correctly.
25
* @version $Id: BaseNonStringProperties.java 439648 2006-09-02 20:42:10Z oheger $
27
public abstract class BaseNonStringProperties extends TestCase
30
protected NonStringTestHolder nonStringTestHolder = new NonStringTestHolder();
31
public abstract void setUp() throws Exception;
33
public Configuration conf = null;
35
public void testBoolean() throws Exception
37
nonStringTestHolder.testBoolean();
40
public void testBooleanDefaultValue() throws Exception
42
nonStringTestHolder.testBooleanDefaultValue();
45
public void testBooleanArrayValue() throws Exception
47
boolean booleanValue = conf.getBoolean("test.boolean");
48
assertEquals(true, booleanValue);
49
assertEquals(2, conf.getList("test.boolean.array").size());
52
public void testByte() throws Exception
54
nonStringTestHolder.testByte();
57
public void testByteArrayValue() throws Exception
60
byte byteValue = conf.getByte("test.byte");
61
assertEquals(testValue, byteValue);
62
assertEquals(2, conf.getList("test.byte.array").size());
65
public void testDouble() throws Exception
67
nonStringTestHolder.testDouble();
70
public void testDoubleDefaultValue() throws Exception
72
nonStringTestHolder.testDoubleDefaultValue();
75
public void testDoubleArrayValue() throws Exception
77
double testValue = 10.25;
78
double doubleValue = conf.getDouble("test.double");
79
assertEquals(testValue, doubleValue, 0.01);
80
assertEquals(2, conf.getList("test.double.array").size());
83
public void testFloat() throws Exception
85
nonStringTestHolder.testFloat();
88
public void testFloatDefaultValue() throws Exception
90
nonStringTestHolder.testFloatDefaultValue();
94
public void testFloatArrayValue() throws Exception
96
float testValue = (float) 20.25;
97
float floatValue = conf.getFloat("test.float");
98
assertEquals(testValue, floatValue, 0.01);
99
assertEquals(2, conf.getList("test.float.array").size());
102
public void testInteger() throws Exception
104
nonStringTestHolder.testInteger();
107
public void testIntegerDefaultValue() throws Exception
109
nonStringTestHolder.testIntegerDefaultValue();
112
public void testIntegerArrayValue() throws Exception
114
int intValue = conf.getInt("test.integer");
115
assertEquals(10, intValue);
116
assertEquals(2, conf.getList("test.integer.array").size());
119
public void testLong() throws Exception
121
nonStringTestHolder.testLong();
123
public void testLongDefaultValue() throws Exception
125
nonStringTestHolder.testLongDefaultValue();
127
public void testLongArrayValue() throws Exception
129
long longValue = conf.getLong("test.long");
130
assertEquals(1000000, longValue);
131
assertEquals(2, conf.getList("test.long.array").size());
134
public void testShort() throws Exception
136
nonStringTestHolder.testShort();
139
public void testShortDefaultValue() throws Exception
141
nonStringTestHolder.testShortDefaultValue();
143
public void testShortArrayValue() throws Exception
145
short shortValue = conf.getShort("test.short");
146
assertEquals(1, shortValue);
147
assertEquals(2, conf.getList("test.short.array").size());
150
public void testListMissing() throws Exception
152
nonStringTestHolder.testListMissing();
155
public void testSubset() throws Exception
157
nonStringTestHolder.testSubset();
159
public void testIsEmpty() throws Exception
161
nonStringTestHolder.testIsEmpty();