Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0778E10CED for ; Tue, 22 Oct 2013 18:04:24 +0000 (UTC) Received: (qmail 15965 invoked by uid 500); 22 Oct 2013 18:03:25 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 15800 invoked by uid 500); 22 Oct 2013 18:03:15 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 15757 invoked by uid 99); 22 Oct 2013 18:03:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Oct 2013 18:03:01 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sebbaz@gmail.com designates 209.85.212.181 as permitted sender) Received: from [209.85.212.181] (HELO mail-wi0-f181.google.com) (209.85.212.181) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Oct 2013 18:02:55 +0000 Received: by mail-wi0-f181.google.com with SMTP id l12so6210909wiv.14 for ; Tue, 22 Oct 2013 11:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=PbqtwC7Q11t+XEfDCH+hw6/3oJCMhPOur0FrP8zMCVM=; b=XUsK3dEACn+0e9xYWFsr32izk3bUEhNv+/mjJhKfCeoG+fUMtp5jrApYZBIQyA92Dz tYBolUO9WvnkwYJOFksmOY1kOBDCgUK1kVdYJrCVhVn83uPKtyxtizHFukDMCrAasnVZ p3buBOu0IqaA7t0YUB/ybzcQQdNSGzedKipNcUDFOqob2Jm77JnNwj2fst+Vt2iQ5rdU +9PIBxrHy15j6cTkQ00JsvQWKsR7wZp6z+I++nuOIyWdIO/wqHFw07xV0+Q1gePxxoo/ MzMyV/iYKOUvmLSYWpfHeheAyPCoaVGG8F5OI0MJkkGXwr9P9Mlco1K44Z8aeEd3ck6s grdg== MIME-Version: 1.0 X-Received: by 10.180.37.227 with SMTP id b3mr15650443wik.24.1382464954256; Tue, 22 Oct 2013 11:02:34 -0700 (PDT) Received: by 10.194.24.99 with HTTP; Tue, 22 Oct 2013 11:02:34 -0700 (PDT) In-Reply-To: <20131020202821.342502388868@eris.apache.org> References: <20131020202821.342502388868@eris.apache.org> Date: Tue, 22 Oct 2013 19:02:34 +0100 Message-ID: Subject: Re: svn commit: r1533967 - in /commons/proper/beanutils/branches/java5/src: main/java/org/apache/commons/beanutils/converters/ test/java/org/apache/commons/beanutils/converters/ From: sebb To: dev@commons.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org On 20 October 2013 21:28, wrote: > Author: oheger > Date: Sun Oct 20 20:28:19 2013 > New Revision: 1533967 > > URL: http://svn.apache.org/r1533967 > Log: > Generified all number converters. > > Modified: > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigDecimalConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigIntegerConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ByteConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/DoubleConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/FloatConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/IntegerConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/LongConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java > commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigDecimalConverterTestCase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigIntegerConverterTestCase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ByteConverterTestCase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/DoubleConverterTestCase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/FloatConverterTestCase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/IntegerConverterTestCase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/LongConverterTestCase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/NumberConverterTestBase.java > commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ShortConverterTestCase.java > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigDecimalConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigDecimalConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigDecimalConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigDecimalConverter.java Sun Oct 20 20:28:19 2013 > @@ -33,7 +33,7 @@ import java.math.BigDecimal; > * @version $Id$ > * @since 1.3 > */ > -public final class BigDecimalConverter extends NumberConverter { > +public final class BigDecimalConverter extends NumberConverter { > > /** > * Construct a java.math.BigDecimal Converter that throws > @@ -62,7 +62,7 @@ public final class BigDecimalConverter e > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return BigDecimal.class; Won't that change the method signature? AIUI, the erasure will now be BigDecimal rather than Object. This needs checking. > } > > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigIntegerConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigIntegerConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigIntegerConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/BigIntegerConverter.java Sun Oct 20 20:28:19 2013 > @@ -33,7 +33,7 @@ import java.math.BigInteger; > * @version $Id$ > * @since 1.3 > */ > -public final class BigIntegerConverter extends NumberConverter { > +public final class BigIntegerConverter extends NumberConverter { > > /** > * Construct a java.math.BigInteger Converter that throws > @@ -62,7 +62,7 @@ public final class BigIntegerConverter e > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return BigInteger.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ByteConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ByteConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ByteConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ByteConverter.java Sun Oct 20 20:28:19 2013 > @@ -31,7 +31,7 @@ package org.apache.commons.beanutils.con > * @version $Id$ > * @since 1.3 > */ > -public final class ByteConverter extends NumberConverter { > +public final class ByteConverter extends NumberConverter { > > /** > * Construct a java.lang.Byte Converter that throws > @@ -60,7 +60,7 @@ public final class ByteConverter extends > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return Byte.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/DoubleConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/DoubleConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/DoubleConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/DoubleConverter.java Sun Oct 20 20:28:19 2013 > @@ -31,7 +31,7 @@ package org.apache.commons.beanutils.con > * @version $Id$ > * @since 1.3 > */ > -public final class DoubleConverter extends NumberConverter { > +public final class DoubleConverter extends NumberConverter { > > /** > * Construct a java.lang.Double Converter that throws > @@ -60,7 +60,7 @@ public final class DoubleConverter exten > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return Double.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/FloatConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/FloatConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/FloatConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/FloatConverter.java Sun Oct 20 20:28:19 2013 > @@ -31,7 +31,7 @@ package org.apache.commons.beanutils.con > * @version $Id$ > * @since 1.3 > */ > -public final class FloatConverter extends NumberConverter { > +public final class FloatConverter extends NumberConverter { > > /** > * Construct a java.lang.Float Converter that throws > @@ -60,7 +60,7 @@ public final class FloatConverter extend > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return Float.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/IntegerConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/IntegerConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/IntegerConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/IntegerConverter.java Sun Oct 20 20:28:19 2013 > @@ -31,7 +31,7 @@ package org.apache.commons.beanutils.con > * @version $Id$ > * @since 1.3 > */ > -public final class IntegerConverter extends NumberConverter { > +public final class IntegerConverter extends NumberConverter { > > /** > * Construct a java.lang.Integer Converter that throws > @@ -60,7 +60,7 @@ public final class IntegerConverter exte > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return Integer.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/LongConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/LongConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/LongConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/LongConverter.java Sun Oct 20 20:28:19 2013 > @@ -31,7 +31,7 @@ package org.apache.commons.beanutils.con > * @version $Id$ > * @since 1.3 > */ > -public final class LongConverter extends NumberConverter { > +public final class LongConverter extends NumberConverter { > > /** > * Construct a java.lang.Long Converter that throws > @@ -60,7 +60,7 @@ public final class LongConverter extends > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return Long.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java Sun Oct 20 20:28:19 2013 > @@ -16,15 +16,15 @@ > */ > package org.apache.commons.beanutils.converters; > > -import java.util.Calendar; > -import java.util.Date; > -import java.util.Locale; > import java.math.BigDecimal; > import java.math.BigInteger; > -import java.text.NumberFormat; > import java.text.DecimalFormat; > import java.text.DecimalFormatSymbols; > +import java.text.NumberFormat; > import java.text.ParsePosition; > +import java.util.Calendar; > +import java.util.Date; > +import java.util.Locale; > > import org.apache.commons.beanutils.ConversionException; > > @@ -79,10 +79,11 @@ import org.apache.commons.beanutils.Conv > * For example to cater for number styles used in Germany such as 0.000,00 the pattern > * is specified in the normal form 0,000.00 and the locale set to Locale.GERMANY. > * > + * @param the default type of this converter > * @version $Id$ > * @since 1.8.0 > */ > -public abstract class NumberConverter extends AbstractConverter { > +public abstract class NumberConverter extends AbstractConverter { > > private static final Integer ZERO = new Integer(0); > private static final Integer ONE = new Integer(1); > @@ -229,9 +230,9 @@ public abstract class NumberConverter ex > * @throws Throwable if an error occurs converting to the specified type > */ > @Override > - protected Object convertToType(Class targetType, Object value) throws Throwable { > + protected T convertToType(Class targetType, Object value) throws Throwable { > > - Class sourceType = value.getClass(); > + Class sourceType = value.getClass(); > // Handle Number > if (value instanceof Number) { > return toNumber(sourceType, targetType, (Number)value); > @@ -244,12 +245,12 @@ public abstract class NumberConverter ex > > // Handle Date --> Long > if (value instanceof Date && Long.class.equals(targetType)) { > - return new Long(((Date)value).getTime()); > + return targetType.cast(new Long(((Date)value).getTime())); > } > > // Handle Calendar --> Long > if (value instanceof Calendar && Long.class.equals(targetType)) { > - return new Long(((Calendar)value).getTime().getTime()); > + return targetType.cast(new Long(((Calendar)value).getTime().getTime())); > } > > // Convert all other types to String & handle > @@ -296,11 +297,11 @@ public abstract class NumberConverter ex > * > * @return The converted value. > */ > - private Number toNumber(Class sourceType, Class targetType, Number value) { > + private T toNumber(Class sourceType, Class targetType, Number value) { > > // Correct Number type already > if (targetType.equals(value.getClass())) { > - return value; > + return targetType.cast(value); > } > > // Byte > @@ -314,7 +315,7 @@ public abstract class NumberConverter ex > throw new ConversionException(toString(sourceType) + " value '" + value > + "' is too small " + toString(targetType)); > } > - return new Byte(value.byteValue()); > + return targetType.cast(new Byte(value.byteValue())); > } > > // Short > @@ -328,7 +329,7 @@ public abstract class NumberConverter ex > throw new ConversionException(toString(sourceType) + " value '" + value > + "' is too small " + toString(targetType)); > } > - return new Short(value.shortValue()); > + return targetType.cast(new Short(value.shortValue())); > } > > // Integer > @@ -342,12 +343,12 @@ public abstract class NumberConverter ex > throw new ConversionException(toString(sourceType) + " value '" + value > + "' is too small " + toString(targetType)); > } > - return new Integer(value.intValue()); > + return targetType.cast(new Integer(value.intValue())); > } > > // Long > if (targetType.equals(Long.class)) { > - return new Long(value.longValue()); > + return targetType.cast(new Long(value.longValue())); > } > > // Float > @@ -356,31 +357,31 @@ public abstract class NumberConverter ex > throw new ConversionException(toString(sourceType) + " value '" + value > + "' is too large for " + toString(targetType)); > } > - return new Float(value.floatValue()); > + return targetType.cast(new Float(value.floatValue())); > } > > // Double > if (targetType.equals(Double.class)) { > - return new Double(value.doubleValue()); > + return targetType.cast(new Double(value.doubleValue())); > } > > // BigDecimal > if (targetType.equals(BigDecimal.class)) { > if (value instanceof Float || value instanceof Double) { > - return new BigDecimal(value.toString()); > + return targetType.cast(new BigDecimal(value.toString())); > } else if (value instanceof BigInteger) { > - return new BigDecimal((BigInteger)value); > + return targetType.cast(new BigDecimal((BigInteger)value)); > } else { > - return BigDecimal.valueOf(value.longValue()); > + return targetType.cast(BigDecimal.valueOf(value.longValue())); > } > } > > // BigInteger > if (targetType.equals(BigInteger.class)) { > if (value instanceof BigDecimal) { > - return ((BigDecimal)value).toBigInteger(); > + return targetType.cast(((BigDecimal)value).toBigInteger()); > } else { > - return BigInteger.valueOf(value.longValue()); > + return targetType.cast(BigInteger.valueOf(value.longValue())); > } > } > > @@ -413,7 +414,7 @@ public abstract class NumberConverter ex > * > * @return The converted Number value. > */ > - private Number toNumber(Class sourceType, Class targetType, String value) { > + private Number toNumber(Class sourceType, Class targetType, String value) { > > // Byte > if (targetType.equals(Byte.class)) { > @@ -530,7 +531,7 @@ public abstract class NumberConverter ex > > /** > * Convert a String into a Number object. > - * @param sourceType TODO > + * @param sourceType the source type of the conversion > * @param targetType The type to convert the value to > * @param value The String date value. > * @param format The NumberFormat to parse the String value. > @@ -538,7 +539,7 @@ public abstract class NumberConverter ex > * @return The converted Number object. > * @throws ConversionException if the String cannot be converted. > */ > - private Number parse(Class sourceType, Class targetType, String value, NumberFormat format) { > + private Number parse(Class sourceType, Class targetType, String value, NumberFormat format) { > ParsePosition pos = new ParsePosition(0); > Number parsedNumber = format.parse(value, pos); > if (pos.getErrorIndex() >= 0 || pos.getIndex() != value.length() || parsedNumber == null) { > > Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java (original) > +++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java Sun Oct 20 20:28:19 2013 > @@ -31,7 +31,7 @@ package org.apache.commons.beanutils.con > * @version $Id$ > * @since 1.3 > */ > -public final class ShortConverter extends NumberConverter { > +public final class ShortConverter extends NumberConverter { > > /** > * Construct a java.lang.Short Converter that throws > @@ -60,7 +60,7 @@ public final class ShortConverter extend > * @since 1.8.0 > */ > @Override > - protected Class getDefaultType() { > + protected Class getDefaultType() { > return Short.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigDecimalConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigDecimalConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigDecimalConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigDecimalConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -63,17 +63,17 @@ public class BigDecimalConverterTestCase > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new BigDecimalConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new BigDecimalConverter(defaultValue); > } > > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return BigDecimal.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigIntegerConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigIntegerConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigIntegerConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/BigIntegerConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -62,17 +62,17 @@ public class BigIntegerConverterTestCase > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new BigIntegerConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new BigIntegerConverter(defaultValue); > } > > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return BigInteger.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ByteConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ByteConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ByteConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ByteConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -61,16 +61,16 @@ public class ByteConverterTestCase exten > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new ByteConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new ByteConverter(defaultValue); > } > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return Byte.class; > } > > @@ -137,7 +137,7 @@ public class ByteConverterTestCase exten > */ > public void testInvalidAmount() { > Converter converter = makeConverter(); > - Class clazz = Byte.class; > + Class clazz = Byte.class; > > Long min = new Long(Byte.MIN_VALUE); > Long max = new Long(Byte.MAX_VALUE); > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/DoubleConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/DoubleConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/DoubleConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/DoubleConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -61,17 +61,17 @@ public class DoubleConverterTestCase ext > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new DoubleConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new DoubleConverter(defaultValue); > } > > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return Double.class; > } > > @@ -130,12 +130,12 @@ public class DoubleConverterTestCase ext > assertEquals( > message[i] + " to Double", > expected[i].doubleValue(), > - ((Double)(converter.convert(Double.class,input[i]))).doubleValue(), > + (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(), > + (converter.convert(Double.TYPE,input[i])).doubleValue(), > 0.00001D); > assertEquals( > message[i] + " to null type", > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/FloatConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/FloatConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/FloatConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/FloatConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -61,17 +61,17 @@ public class FloatConverterTestCase exte > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new FloatConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new FloatConverter(defaultValue); > } > > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return Float.class; > } > > @@ -130,12 +130,12 @@ public class FloatConverterTestCase exte > assertEquals( > message[i] + " to Float", > expected[i].floatValue(), > - ((Float)(converter.convert(Float.class,input[i]))).floatValue(), > + (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(), > + (converter.convert(Float.TYPE,input[i])).floatValue(), > 0.00001); > assertEquals( > message[i] + " to null type", > @@ -151,7 +151,7 @@ public class FloatConverterTestCase exte > */ > public void testInvalidAmount() { > Converter converter = makeConverter(); > - Class clazz = Float.class; > + Class clazz = Float.class; > > Double max = new Double(Float.MAX_VALUE); > Double tooBig = new Double(Double.MAX_VALUE); > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/IntegerConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/IntegerConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/IntegerConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/IntegerConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -19,6 +19,7 @@ package org.apache.commons.beanutils.con > > import junit.framework.TestSuite; > > +import org.apache.commons.beanutils.ConversionException; > import org.apache.commons.beanutils.Converter; > > > @@ -61,17 +62,17 @@ public class IntegerConverterTestCase ex > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new IntegerConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new IntegerConverter(defaultValue); > } > > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return Integer.class; > } > > @@ -138,7 +139,7 @@ public class IntegerConverterTestCase ex > */ > public void testInvalidAmount() { > Converter converter = makeConverter(); > - Class clazz = Integer.class; > + Class clazz = Integer.class; > > Long min = new Long(Integer.MIN_VALUE); > Long max = new Long(Integer.MAX_VALUE); > @@ -167,5 +168,18 @@ public class IntegerConverterTestCase ex > // expected result > } > } > + > + /** > + * Tests whether an invalid default object causes an exception. > + */ > + public void testInvalidDefaultObject() { > + NumberConverter converter = makeConverter(); > + try { > + converter.setDefaultValue("notANumber"); > + fail("Invalid default value not detected!"); > + } catch (ConversionException cex) { > + // expected result > + } > + } > } > > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/LongConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/LongConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/LongConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/LongConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -61,17 +61,17 @@ public class LongConverterTestCase exten > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new LongConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new LongConverter(defaultValue); > } > > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return Long.class; > } > > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/NumberConverterTestBase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/NumberConverterTestBase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/NumberConverterTestBase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/NumberConverterTestBase.java Sun Oct 20 20:28:19 2013 > @@ -47,9 +47,9 @@ public abstract class NumberConverterTes > > // ------------------------------------------------------------------------ > > - protected abstract NumberConverter makeConverter(); > - protected abstract NumberConverter makeConverter(Object defaultValue); > - protected abstract Class getExpectedType(); > + protected abstract NumberConverter makeConverter(); > + protected abstract NumberConverter makeConverter(Object defaultValue); > + protected abstract Class getExpectedType(); > > // ------------------------------------------------------------------------ > > @@ -111,7 +111,7 @@ public abstract class NumberConverterTes > Locale defaultLocale = Locale.getDefault(); > Locale.setDefault(Locale.US); > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > converter.setPattern("[0,0.0];(0,0.0)"); > > // Default Locale > @@ -136,7 +136,7 @@ public abstract class NumberConverterTes > Locale defaultLocale = Locale.getDefault(); > Locale.setDefault(Locale.US); > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > converter.setUseLocaleFormat(true); > > // Default Locale > @@ -158,7 +158,7 @@ public abstract class NumberConverterTes > public void testStringArrayToInteger() { > > Integer defaultValue = new Integer(-1); > - NumberConverter converter = makeConverter(defaultValue); > + NumberConverter converter = makeConverter(defaultValue); > > // Default Locale > assertEquals("Valid First", new Integer(5), converter.convert(Integer.class, new String[] {"5", "4", "3"})); > @@ -172,7 +172,7 @@ public abstract class NumberConverterTes > */ > public void testNumberToStringDefault() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > > // Default Number --> String conversion > assertEquals("Default Convert " + numbers[0], numbers[0].toString(), converter.convert(String.class, numbers[0])); > @@ -189,7 +189,7 @@ public abstract class NumberConverterTes > Locale defaultLocale = Locale.getDefault(); > Locale.setDefault(Locale.US); > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > converter.setPattern("[0,0];(0,0)"); > > // Default Locale > @@ -236,7 +236,7 @@ public abstract class NumberConverterTes > Locale defaultLocale = Locale.getDefault(); > Locale.setDefault(Locale.US); > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > converter.setUseLocaleFormat(true); > > // Default Locale > @@ -273,7 +273,7 @@ public abstract class NumberConverterTes > */ > public void testStringToNumberDefault() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > converter.setUseLocaleFormat(false); > > // Default String --> Number conversion > @@ -289,11 +289,22 @@ public abstract class NumberConverterTes > } > > /** > + * Convert String --> Number if the target type is not defined. Then the > + * default type should be used. > + */ > + public void testStringToNumberDefaultType() { > + NumberConverter converter = makeConverter(); > + converter.setUseLocaleFormat(false); > + > + assertEquals("Default Convert " + numbers[0], numbers[0], converter.convert(null, numbers[0].toString())); > + } > + > + /** > * Convert Boolean --> Number (default conversion) > */ > public void testBooleanToNumberDefault() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > > // Other type --> String conversion > assertEquals("Boolean.FALSE to Number ", 0, ((Number)converter.convert(getExpectedType(), Boolean.FALSE)).intValue()); > @@ -306,7 +317,7 @@ public abstract class NumberConverterTes > */ > public void testDateToNumber() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > > Date dateValue = new Date(); > long longValue = dateValue.getTime(); > @@ -329,7 +340,7 @@ public abstract class NumberConverterTes > */ > public void testCalendarToNumber() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > > Calendar calendarValue = Calendar.getInstance(); > long longValue = calendarValue.getTime().getTime(); > @@ -352,7 +363,7 @@ public abstract class NumberConverterTes > */ > public void testOtherToStringDefault() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > > // Other type --> String conversion > assertEquals("Default Convert ", "ABC", converter.convert(String.class, new StringBuffer("ABC"))); > @@ -365,7 +376,7 @@ public abstract class NumberConverterTes > public void testInvalidDefault() { > > Object defaultvalue = numbers[0]; > - NumberConverter converter = makeConverter(defaultvalue); > + NumberConverter converter = makeConverter(defaultvalue); > > // Default String --> Number conversion > assertEquals("Invalid null ", defaultvalue, converter.convert(getExpectedType(), null)); > @@ -377,7 +388,7 @@ public abstract class NumberConverterTes > */ > public void testInvalidException() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > > try { > converter.convert(getExpectedType(), null); > @@ -398,7 +409,7 @@ public abstract class NumberConverterTes > */ > public void testInvalidType() { > > - NumberConverter converter = makeConverter(); > + NumberConverter converter = makeConverter(); > > try { > converter.convert(Object.class, numbers[0]); > @@ -407,5 +418,21 @@ public abstract class NumberConverterTes > // expected result > } > } > + > + /** > + * Tests a conversion to an unsupported type if a default value is set. > + */ > + public void testInvalidTypeWithDefault() { > + > + NumberConverter converter = makeConverter(42); > + > + try { > + converter.convert(Object.class, numbers[0]); > + fail("Invalid type with default test, expected ConversionException"); > + } catch(ConversionException e) { > + // expected result > + } > + } > + > } > > > Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ShortConverterTestCase.java > URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ShortConverterTestCase.java?rev=1533967&r1=1533966&r2=1533967&view=diff > ============================================================================== > --- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ShortConverterTestCase.java (original) > +++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/converters/ShortConverterTestCase.java Sun Oct 20 20:28:19 2013 > @@ -61,17 +61,17 @@ public class ShortConverterTestCase exte > // ------------------------------------------------------------------------ > > @Override > - protected NumberConverter makeConverter() { > + protected NumberConverter makeConverter() { > return new ShortConverter(); > } > > @Override > - protected NumberConverter makeConverter(Object defaultValue) { > + protected NumberConverter makeConverter(Object defaultValue) { > return new ShortConverter(defaultValue); > } > > @Override > - protected Class getExpectedType() { > + protected Class getExpectedType() { > return Short.class; > } > > @@ -138,7 +138,7 @@ public class ShortConverterTestCase exte > */ > public void testInvalidAmount() { > Converter converter = makeConverter(); > - Class clazz = Short.class; > + Class clazz = Short.class; > > Long min = new Long(Short.MIN_VALUE); > Long max = new Long(Short.MAX_VALUE); > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org