henning 2002/12/21 09:12:06
Modified: configuration/conf test.properties
Added: configuration/src/test/org/apache/commons/configuration
TestNonStringProperties.java
Log:
Added a test case for the non-string properties.
Revision Changes Path
1.3 +30 -0 jakarta-commons-sandbox/configuration/conf/test.properties
Index: test.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/configuration/conf/test.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- test.properties 14 Dec 2002 12:07:01 -0000 1.2
+++ test.properties 21 Dec 2002 17:12:06 -0000 1.3
@@ -10,4 +10,34 @@
test.equals = value=one
+#
+# Non String Properties
+#
+test.boolean = true
+test.boolean.array = false
+test.boolean.array = true
+
+test.byte = 10
+test.byte.array = 20
+test.byte.array = 30
+
+test.double = 10.25
+test.double.array = 20.35
+test.double.array = 30.45
+
+test.float = 20.25
+test.float.array = 30.35
+test.float.array = 40.45
+
+test.integer = 10
+test.integer.array = 20
+test.integer.array = 30
+
+test.long = 1000000
+test.long.array = 2000000
+test.long.array = 3000000
+
+test.short = 1
+test.short.array = 2
+test.short.array = 3
1.1
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestNonStringProperties.java
Index: TestNonStringProperties.java
===================================================================
package org.apache.commons.configuration;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.InputStream;
import java.util.Vector;
import junit.framework.TestCase;
/**
* test if non-string properties are handled correctly
*
* @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @version $Id: TestNonStringProperties.java,v 1.1 2002/12/21 17:12:06 henning Exp $
*/
public class TestNonStringProperties
extends TestCase
{
/** The File that we test with */
private String testProperties =
new File("conf/test.properties").getAbsolutePath();
/** Our Properties configuration */
private PropertiesConfiguration conf = null;
public TestNonStringProperties(String s)
throws Exception
{
super(s);
conf = new PropertiesConfiguration(testProperties);
}
public void testBoolean()
throws Exception
{
boolean booleanValue = conf.getBoolean("test.boolean");
assertEquals(true, booleanValue);
assertEquals(1, conf.getVector("test.boolean").size());
}
public void testBooleanArrayValue()
throws Exception
{
boolean booleanValue = conf.getBoolean("test.boolean.array");
assertEquals(false, booleanValue);
assertEquals(2, conf.getVector("test.boolean.array").size());
}
public void testByte()
throws Exception
{
byte testValue = 10;
byte byteValue = conf.getByte("test.byte");
assertEquals(testValue, byteValue);
assertEquals(1, conf.getVector("test.byte").size());
}
public void testByteArrayValue()
throws Exception
{
byte testValue = 20;
byte byteValue = conf.getByte("test.byte.array");
assertEquals(testValue, byteValue);
assertEquals(2, conf.getVector("test.byte.array").size());
}
public void testDouble()
throws Exception
{
double testValue = 10.25;
double doubleValue = conf.getDouble("test.double");
assertEquals(testValue, doubleValue, 0.01);
assertEquals(1, conf.getVector("test.double").size());
}
public void testDoubleArrayValue()
throws Exception
{
double testValue = 20.35;
double doubleValue = conf.getDouble("test.double.array");
assertEquals(testValue, doubleValue, 0.01);
assertEquals(2, conf.getVector("test.double.array").size());
}
public void testFloat()
throws Exception
{
float testValue = (float) 20.25;
float floatValue = conf.getFloat("test.float");
assertEquals(testValue, floatValue, 0.01);
assertEquals(1, conf.getVector("test.float").size());
}
public void testFloatArrayValue()
throws Exception
{
float testValue = (float) 30.35;
float floatValue = conf.getFloat("test.float.array");
assertEquals(testValue, floatValue, 0.01);
assertEquals(2, conf.getVector("test.float.array").size());
}
public void testInteger()
throws Exception
{
int intValue = conf.getInt("test.integer");
assertEquals(10, intValue);
assertEquals(1, conf.getVector("test.integer").size());
}
public void testIntegerArrayValue()
throws Exception
{
int intValue = conf.getInt("test.integer.array");
assertEquals(20, intValue);
assertEquals(2, conf.getVector("test.integer.array").size());
}
public void testLong()
throws Exception
{
long longValue = conf.getLong("test.long");
assertEquals(1000000, longValue);
assertEquals(1, conf.getVector("test.long").size());
}
public void testLongArrayValue()
throws Exception
{
long longValue = conf.getLong("test.long.array");
assertEquals(2000000, longValue);
assertEquals(2, conf.getVector("test.long.array").size());
}
public void testShort()
throws Exception
{
short shortValue = conf.getShort("test.short");
assertEquals(1, shortValue);
assertEquals(1, conf.getVector("test.short").size());
}
public void testShortArrayValue()
throws Exception
{
short shortValue = conf.getShort("test.short.array");
assertEquals(2, shortValue);
assertEquals(2, conf.getVector("test.short.array").size());
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>