You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2002/12/09 23:03:12 UTC
cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters ByteConverterTestCase.java DoubleConverterTestCase.java FloatConverterTestCase.java IntegerConverterTestCase.java LongConverterTestCase.java NumberConverterTestBase.java ShortConverterTestCase.java
rwaldhoff 2002/12/09 14:03:12
Modified: beanutils/src/java/org/apache/commons/beanutils/converters
ByteConverter.java DoubleConverter.java
FloatConverter.java IntegerConverter.java
LongConverter.java ShortConverter.java
Added: beanutils/src/test/org/apache/commons/beanutils/converters
ByteConverterTestCase.java
DoubleConverterTestCase.java
FloatConverterTestCase.java
IntegerConverterTestCase.java
LongConverterTestCase.java
NumberConverterTestBase.java
ShortConverterTestCase.java
Log:
add support for Number types in <Number>Converter classes
add tests that demonstrate
Revision Changes Path
1.4 +6 -4 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/ByteConverter.java
Index: ByteConverter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/ByteConverter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ByteConverter.java 13 Jul 2002 02:22:08 -0000 1.3
+++ ByteConverter.java 9 Dec 2002 22:03:11 -0000 1.4
@@ -150,6 +150,8 @@
if (value instanceof Byte) {
return (value);
+ } else if (value instanceof Number) {
+ return new Byte(((Number)value).byteValue());
}
try {
1.4 +7 -4 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/DoubleConverter.java
Index: DoubleConverter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/DoubleConverter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DoubleConverter.java 13 Jul 2002 02:22:08 -0000 1.3
+++ DoubleConverter.java 9 Dec 2002 22:03:11 -0000 1.4
@@ -150,7 +150,10 @@
if (value instanceof Double) {
return (value);
+ } else if(value instanceof Number) {
+ return new Double(((Number)value).doubleValue());
}
+
try {
return (new Double(value.toString()));
1.4 +6 -4 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/FloatConverter.java
Index: FloatConverter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/FloatConverter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FloatConverter.java 13 Jul 2002 02:22:08 -0000 1.3
+++ FloatConverter.java 9 Dec 2002 22:03:11 -0000 1.4
@@ -150,6 +150,8 @@
if (value instanceof Float) {
return (value);
+ } else if(value instanceof Number) {
+ return new Float(((Number)value).floatValue());
}
try {
1.4 +6 -4 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/IntegerConverter.java
Index: IntegerConverter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/IntegerConverter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- IntegerConverter.java 13 Jul 2002 02:22:08 -0000 1.3
+++ IntegerConverter.java 9 Dec 2002 22:03:11 -0000 1.4
@@ -150,6 +150,8 @@
if (value instanceof Integer) {
return (value);
+ } else if(value instanceof Number) {
+ return new Integer(((Number)value).intValue());
}
try {
1.4 +6 -4 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/LongConverter.java
Index: LongConverter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/LongConverter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LongConverter.java 13 Jul 2002 02:22:08 -0000 1.3
+++ LongConverter.java 9 Dec 2002 22:03:11 -0000 1.4
@@ -150,6 +150,8 @@
if (value instanceof Long) {
return (value);
+ } else if(value instanceof Number) {
+ return new Long(((Number)value).longValue());
}
try {
1.4 +6 -4 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/ShortConverter.java
Index: ShortConverter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/ShortConverter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ShortConverter.java 13 Jul 2002 02:22:08 -0000 1.3
+++ ShortConverter.java 9 Dec 2002 22:03:11 -0000 1.4
@@ -150,6 +150,8 @@
if (value instanceof Short) {
return (value);
+ } else if (value instanceof Number) {
+ return new Short(((Number)value).shortValue());
}
try {
1.1 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/ByteConverterTestCase.java
Index: ByteConverterTestCase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/ByteConverterTestCase.java,v 1.1 2002/12/09 22:03:11 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/12/09 22:03:11 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.commons.beanutils.converters;
import junit.framework.TestSuite;
import org.apache.commons.beanutils.Converter;
/**
* Test Case for the ByteConverter class.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/12/09 22:03:11 $
*/
public class ByteConverterTestCase extends NumberConverterTestBase {
private Converter converter = null;
// ------------------------------------------------------------------------
public ByteConverterTestCase(String name) {
super(name);
}
// ------------------------------------------------------------------------
public void setUp() throws Exception {
converter = makeConverter();
}
public static TestSuite suite() {
return new TestSuite(ByteConverterTestCase.class);
}
public void tearDown() throws Exception {
converter = null;
}
// ------------------------------------------------------------------------
protected Converter makeConverter() {
return new ByteConverter();
}
protected Class getExpectedType() {
return Byte.class;
}
// ------------------------------------------------------------------------
public void testSimpleConversion() throws Exception {
String[] message= {
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from Byte",
"from Short",
"from Integer",
"from Long",
"from Float",
"from Double"
};
Object[] input = {
String.valueOf(Byte.MIN_VALUE),
"-17",
"-1",
"0",
"1",
"17",
String.valueOf(Byte.MAX_VALUE),
new Byte((byte)7),
new Short((short)8),
new Integer(9),
new Long(10),
new Float(11.1),
new Double(12.2)
};
Byte[] expected = {
new Byte(Byte.MIN_VALUE),
new Byte((byte)-17),
new Byte((byte)-1),
new Byte((byte)0),
new Byte((byte)1),
new Byte((byte)17),
new Byte(Byte.MAX_VALUE),
new Byte((byte)7),
new Byte((byte)8),
new Byte((byte)9),
new Byte((byte)10),
new Byte((byte)11),
new Byte((byte)12)
};
for(int i=0;i<expected.length;i++) {
assertEquals(message[i] + " to Byte",expected[i],converter.convert(Byte.class,input[i]));
assertEquals(message[i] + " to byte",expected[i],converter.convert(Byte.TYPE,input[i]));
assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
}
}
}
1.1 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/DoubleConverterTestCase.java
Index: DoubleConverterTestCase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/DoubleConverterTestCase.java,v 1.1 2002/12/09 22:03:11 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/12/09 22:03:11 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.commons.beanutils.converters;
import junit.framework.TestSuite;
import org.apache.commons.beanutils.Converter;
/**
* Test Case for the DoubleConverter class.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/12/09 22:03:11 $
*/
public class DoubleConverterTestCase extends NumberConverterTestBase {
private Converter converter = null;
// ------------------------------------------------------------------------
public DoubleConverterTestCase(String name) {
super(name);
}
// ------------------------------------------------------------------------
public void setUp() throws Exception {
converter = makeConverter();
}
public static TestSuite suite() {
return new TestSuite(DoubleConverterTestCase.class);
}
public void tearDown() throws Exception {
converter = null;
}
// ------------------------------------------------------------------------
protected Converter makeConverter() {
return new DoubleConverter();
}
protected Class getExpectedType() {
return Double.class;
}
// ------------------------------------------------------------------------
public void testSimpleConversion() throws Exception {
String[] message= {
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from Byte",
"from Short",
"from Integer",
"from Long",
"from Float",
"from Double"
};
Object[] input = {
String.valueOf(Double.MIN_VALUE),
"-17.2",
"-1.1",
"0.0",
"1.1",
"17.2",
String.valueOf(Double.MAX_VALUE),
new Byte((byte)7),
new Short((short)8),
new Integer(9),
new Long(10),
new Float(11.1),
new Double(12.2)
};
Double[] expected = {
new Double(Double.MIN_VALUE),
new Double(-17.2),
new Double(-1.1),
new Double(0.0),
new Double(1.1),
new Double(17.2),
new Double(Double.MAX_VALUE),
new Double(7),
new Double(8),
new Double(9),
new Double(10),
new Double(11.1),
new Double(12.2)
};
for(int i=0;i<expected.length;i++) {
assertEquals(
message[i] + " to Double",
expected[i].doubleValue(),
((Double)(converter.convert(Double.class,input[i]))).doubleValue(),
0.00001D);
assertEquals(
message[i] + " to double",
expected[i].doubleValue(),
((Double)(converter.convert(Double.TYPE,input[i]))).doubleValue(),
0.00001D);
assertEquals(
message[i] + " to null type",
expected[i].doubleValue(),
((Double)(converter.convert(null,input[i]))).doubleValue(),
0.00001D);
}
}
}
1.1 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/FloatConverterTestCase.java
Index: FloatConverterTestCase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/FloatConverterTestCase.java,v 1.1 2002/12/09 22:03:12 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/12/09 22:03:12 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.commons.beanutils.converters;
import junit.framework.TestSuite;
import org.apache.commons.beanutils.Converter;
/**
* Test Case for the FloatConverter class.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/12/09 22:03:12 $
*/
public class FloatConverterTestCase extends NumberConverterTestBase {
private Converter converter = null;
// ------------------------------------------------------------------------
public FloatConverterTestCase(String name) {
super(name);
}
// ------------------------------------------------------------------------
public void setUp() throws Exception {
converter = makeConverter();
}
public static TestSuite suite() {
return new TestSuite(FloatConverterTestCase.class);
}
public void tearDown() throws Exception {
converter = null;
}
// ------------------------------------------------------------------------
protected Converter makeConverter() {
return new FloatConverter();
}
protected Class getExpectedType() {
return Float.class;
}
// ------------------------------------------------------------------------
public void testSimpleConversion() throws Exception {
String[] message= {
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from Byte",
"from Short",
"from Integer",
"from Long",
"from Float",
"from Double"
};
Object[] input = {
String.valueOf(Float.MIN_VALUE),
"-17.2",
"-1.1",
"0.0",
"1.1",
"17.2",
String.valueOf(Float.MAX_VALUE),
new Byte((byte)7),
new Short((short)8),
new Integer(9),
new Long(10),
new Float(11.1),
new Double(12.2)
};
Float[] expected = {
new Float(Float.MIN_VALUE),
new Float(-17.2),
new Float(-1.1),
new Float(0.0),
new Float(1.1),
new Float(17.2),
new Float(Float.MAX_VALUE),
new Float(7),
new Float(8),
new Float(9),
new Float(10),
new Float(11.1),
new Float(12.2)
};
for(int i=0;i<expected.length;i++) {
assertEquals(
message[i] + " to Float",
expected[i].floatValue(),
((Float)(converter.convert(Float.class,input[i]))).floatValue(),
0.00001);
assertEquals(
message[i] + " to float",
expected[i].floatValue(),
((Float)(converter.convert(Float.TYPE,input[i]))).floatValue(),
0.00001);
assertEquals(
message[i] + " to null type",
expected[i].floatValue(),
((Float)(converter.convert(null,input[i]))).floatValue(),
0.00001);
}
}
}
1.1 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/IntegerConverterTestCase.java
Index: IntegerConverterTestCase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/IntegerConverterTestCase.java,v 1.1 2002/12/09 22:03:12 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/12/09 22:03:12 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.commons.beanutils.converters;
import junit.framework.TestSuite;
import org.apache.commons.beanutils.Converter;
/**
* Test Case for the IntegerConverter class.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/12/09 22:03:12 $
*/
public class IntegerConverterTestCase extends NumberConverterTestBase {
private Converter converter = null;
// ------------------------------------------------------------------------
public IntegerConverterTestCase(String name) {
super(name);
}
// ------------------------------------------------------------------------
public void setUp() throws Exception {
converter = makeConverter();
}
public static TestSuite suite() {
return new TestSuite(IntegerConverterTestCase.class);
}
public void tearDown() throws Exception {
converter = null;
}
// ------------------------------------------------------------------------
protected Converter makeConverter() {
return new IntegerConverter();
}
protected Class getExpectedType() {
return Integer.class;
}
// ------------------------------------------------------------------------
public void testSimpleConversion() throws Exception {
String[] message= {
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from Byte",
"from Short",
"from Integer",
"from Long",
"from Float",
"from Double"
};
Object[] input = {
String.valueOf(Integer.MIN_VALUE),
"-17",
"-1",
"0",
"1",
"17",
String.valueOf(Integer.MAX_VALUE),
new Byte((byte)7),
new Short((short)8),
new Integer(9),
new Long(10),
new Float(11.1),
new Double(12.2)
};
Integer[] expected = {
new Integer(Integer.MIN_VALUE),
new Integer(-17),
new Integer(-1),
new Integer(0),
new Integer(1),
new Integer(17),
new Integer(Integer.MAX_VALUE),
new Integer(7),
new Integer(8),
new Integer(9),
new Integer(10),
new Integer(11),
new Integer(12)
};
for(int i=0;i<expected.length;i++) {
assertEquals(message[i] + " to Integer",expected[i],converter.convert(Integer.class,input[i]));
assertEquals(message[i] + " to int",expected[i],converter.convert(Integer.TYPE,input[i]));
assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
}
}
}
1.1 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/LongConverterTestCase.java
Index: LongConverterTestCase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/LongConverterTestCase.java,v 1.1 2002/12/09 22:03:12 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/12/09 22:03:12 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.commons.beanutils.converters;
import junit.framework.TestSuite;
import org.apache.commons.beanutils.Converter;
/**
* Test Case for the LongConverter class.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/12/09 22:03:12 $
*/
public class LongConverterTestCase extends NumberConverterTestBase {
private Converter converter = null;
// ------------------------------------------------------------------------
public LongConverterTestCase(String name) {
super(name);
}
// ------------------------------------------------------------------------
public void setUp() throws Exception {
converter = makeConverter();
}
public static TestSuite suite() {
return new TestSuite(LongConverterTestCase.class);
}
public void tearDown() throws Exception {
converter = null;
}
// ------------------------------------------------------------------------
protected Converter makeConverter() {
return new LongConverter();
}
protected Class getExpectedType() {
return Long.class;
}
// ------------------------------------------------------------------------
public void testSimpleConversion() throws Exception {
String[] message= {
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from Byte",
"from Short",
"from Integer",
"from Long",
"from Float",
"from Double"
};
Object[] input = {
String.valueOf(Long.MIN_VALUE),
"-17",
"-1",
"0",
"1",
"17",
String.valueOf(Long.MAX_VALUE),
new Byte((byte)7),
new Short((short)8),
new Integer(9),
new Long(10),
new Float(11.1),
new Double(12.2)
};
Long[] expected = {
new Long(Long.MIN_VALUE),
new Long(-17),
new Long(-1),
new Long(0),
new Long(1),
new Long(17),
new Long(Long.MAX_VALUE),
new Long(7),
new Long(8),
new Long(9),
new Long(10),
new Long(11),
new Long(12)
};
for(int i=0;i<expected.length;i++) {
assertEquals(message[i] + " to Long",expected[i],converter.convert(Long.class,input[i]));
assertEquals(message[i] + " to long",expected[i],converter.convert(Long.TYPE,input[i]));
assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
}
}
}
1.1 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/NumberConverterTestBase.java
Index: NumberConverterTestBase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/NumberConverterTestBase.java,v 1.1 2002/12/09 22:03:12 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/12/09 22:03:12 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.commons.beanutils.converters;
import junit.framework.TestCase;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
/**
* Abstract base for <Number>Converter classes.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/12/09 22:03:12 $
*/
public abstract class NumberConverterTestBase extends TestCase {
// ------------------------------------------------------------------------
public NumberConverterTestBase(String name) {
super(name);
}
// ------------------------------------------------------------------------
protected abstract Converter makeConverter();
protected abstract Class getExpectedType();
// ------------------------------------------------------------------------
/**
* Assumes ConversionException in response to covert(getExpectedType(),null).
*/
public void testConvertNull() throws Exception {
try {
makeConverter().convert(getExpectedType(),null);
fail("Expected ConversionException");
} catch(ConversionException e) {
// expected
}
}
/**
* Assumes convert(getExpectedType(),Number) returns some non-null
* instance of getExpectedType().
*/
public void testConvertNumber() throws Exception {
String[] message= {
"from Byte",
"from Short",
"from Integer",
"from Long",
"from Float",
"from Double"
};
Object[] number = {
new Byte((byte)7),
new Short((short)8),
new Integer(9),
new Long(10),
new Float(11.1),
new Double(12.2)
};
for(int i=0;i<number.length;i++) {
Object val = makeConverter().convert(getExpectedType(),number[i]);
assertNotNull("Convert " + message[i] + " should not be null",val);
assertTrue(
"Convert " + message[i] + " should return a " + getExpectedType().getName(),
getExpectedType().isInstance(val));
}
}
}
1.1 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/ShortConverterTestCase.java
Index: ShortConverterTestCase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/ShortConverterTestCase.java,v 1.1 2002/12/09 22:03:12 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/12/09 22:03:12 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.commons.beanutils.converters;
import junit.framework.TestSuite;
import org.apache.commons.beanutils.Converter;
/**
* Test Case for the ShortConverter class.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/12/09 22:03:12 $
*/
public class ShortConverterTestCase extends NumberConverterTestBase {
private Converter converter = null;
// ------------------------------------------------------------------------
public ShortConverterTestCase(String name) {
super(name);
}
// ------------------------------------------------------------------------
public void setUp() throws Exception {
converter = makeConverter();
}
public static TestSuite suite() {
return new TestSuite(ShortConverterTestCase.class);
}
public void tearDown() throws Exception {
converter = null;
}
// ------------------------------------------------------------------------
protected Converter makeConverter() {
return new ShortConverter();
}
protected Class getExpectedType() {
return Short.class;
}
// ------------------------------------------------------------------------
public void testSimpleConversion() throws Exception {
String[] message= {
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from String",
"from Byte",
"from Short",
"from Integer",
"from Long",
"from Float",
"from Double"
};
Object[] input = {
String.valueOf(Short.MIN_VALUE),
"-17",
"-1",
"0",
"1",
"17",
String.valueOf(Short.MAX_VALUE),
new Byte((byte)7),
new Short((short)8),
new Integer(9),
new Long(10),
new Float(11.1),
new Double(12.2)
};
Short[] expected = {
new Short(Short.MIN_VALUE),
new Short((short)-17),
new Short((short)-1),
new Short((short)0),
new Short((short)1),
new Short((short)17),
new Short(Short.MAX_VALUE),
new Short((short)7),
new Short((short)8),
new Short((short)9),
new Short((short)10),
new Short((short)11),
new Short((short)12)
};
for(int i=0;i<expected.length;i++) {
assertEquals(message[i] + " to Short",expected[i],converter.convert(Short.class,input[i]));
assertEquals(message[i] + " to short",expected[i],converter.convert(Short.TYPE,input[i]));
assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>