You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/11/08 22:08:33 UTC
svn commit: r1540186 [4/6] - in /commons/proper/beanutils/trunk: ./
src/changes/ src/main/java/org/apache/commons/beanutils/
src/main/java/org/apache/commons/beanutils/converters/
src/main/java/org/apache/commons/beanutils/locale/ src/test/java/org/apa...
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/NumberConverter.java Fri Nov 8 21:08:30 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;
@@ -229,9 +229,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> T convertToType(Class<T> 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 +244,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 +296,11 @@ public abstract class NumberConverter ex
*
* @return The converted value.
*/
- private Number toNumber(Class sourceType, Class targetType, Number value) {
+ private <T> T toNumber(Class<?> sourceType, Class<T> targetType, Number value) {
// Correct Number type already
if (targetType.equals(value.getClass())) {
- return value;
+ return targetType.cast(value);
}
// Byte
@@ -314,7 +314,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 +328,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 +342,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 +356,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 +413,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 +530,7 @@ public abstract class NumberConverter ex
/**
* Convert a String into a <code>Number</code> 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 +538,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/trunk/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/ShortConverter.java Fri Nov 8 21:08:30 2013
@@ -60,7 +60,7 @@ public final class ShortConverter extend
* @since 1.8.0
*/
@Override
- protected Class getDefaultType() {
+ protected Class<Short> getDefaultType() {
return Short.class;
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlDateConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlDateConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlDateConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlDateConverter.java Fri Nov 8 21:08:30 2013
@@ -62,7 +62,7 @@ public final class SqlDateConverter exte
* @since 1.8.0
*/
@Override
- protected Class getDefaultType() {
+ protected Class<?> getDefaultType() {
return Date.class;
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java Fri Nov 8 21:08:30 2013
@@ -65,7 +65,7 @@ public final class SqlTimeConverter exte
* @since 1.8.0
*/
@Override
- protected Class getDefaultType() {
+ protected Class<?> getDefaultType() {
return Time.class;
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java Fri Nov 8 21:08:30 2013
@@ -65,7 +65,7 @@ public final class SqlTimestampConverter
* @since 1.8.0
*/
@Override
- protected Class getDefaultType() {
+ protected Class<?> getDefaultType() {
return Timestamp.class;
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/StringConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/StringConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/StringConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/StringConverter.java Fri Nov 8 21:08:30 2013
@@ -71,7 +71,7 @@ public final class StringConverter exten
* @since 1.8.0
*/
@Override
- protected Class getDefaultType() {
+ protected Class<?> getDefaultType() {
return String.class;
}
@@ -86,8 +86,13 @@ public final class StringConverter exten
* @since 1.8.0
*/
@Override
- protected Object convertToType(Class type, Object value) throws Throwable {
- return value.toString();
+ protected <T> T convertToType(Class<T> type, Object value) throws Throwable {
+ // We have to support Object, too, because this class is sometimes
+ // used for a standard to Object conversion
+ if (String.class.equals(type) || Object.class.equals(type)) {
+ return type.cast(value.toString());
+ }
+ throw conversionException(type, value);
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/URLConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/URLConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/URLConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/converters/URLConverter.java Fri Nov 8 21:08:30 2013
@@ -57,7 +57,7 @@ public final class URLConverter extends
* @since 1.8.0
*/
@Override
- protected Class getDefaultType() {
+ protected Class<?> getDefaultType() {
return URL.class;
}
@@ -71,8 +71,12 @@ public final class URLConverter extends
* @since 1.8.0
*/
@Override
- protected Object convertToType(Class type, Object value) throws Throwable {
- return new URL(value.toString());
+ protected <T> T convertToType(Class<T> type, Object value) throws Throwable {
+ if (URL.class.equals(type)) {
+ return type.cast(new URL(value.toString()));
+ }
+
+ throw conversionException(type, value);
}
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/BaseLocaleConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/BaseLocaleConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/BaseLocaleConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/BaseLocaleConverter.java Fri Nov 8 21:08:30 2013
@@ -17,13 +17,14 @@
package org.apache.commons.beanutils.locale;
+import java.text.ParseException;
+import java.util.Locale;
+
import org.apache.commons.beanutils.ConversionException;
+import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.text.ParseException;
-import java.util.Locale;
-
/**
* <p>The base class for all standart type locale-sensitive converters.
@@ -158,7 +159,7 @@ public abstract class BaseLocaleConverte
/**
* Convert the specified locale-sensitive input object into an output object.
- * The default pattern is used for the convertion.
+ * The default pattern is used for the conversion.
*
* @param value The input object to be converted
* @return The converted value
@@ -174,7 +175,7 @@ public abstract class BaseLocaleConverte
* Convert the specified locale-sensitive input object into an output object.
*
* @param value The input object to be converted
- * @param pattern The pattern is used for the convertion
+ * @param pattern The pattern is used for the conversion
* @return The converted value
*
* @exception ConversionException if conversion cannot be performed
@@ -188,6 +189,7 @@ public abstract class BaseLocaleConverte
* Convert the specified locale-sensitive input object into an output object of the
* specified type. The default pattern is used for the convertion.
*
+ * @param <T> The desired target type of the conversion
* @param type Data type to which this value should be converted
* @param value The input object to be converted
* @return The converted value
@@ -195,7 +197,7 @@ public abstract class BaseLocaleConverte
* @exception ConversionException if conversion cannot be performed
* successfully
*/
- public Object convert(Class type, Object value) {
+ public <T> T convert(Class<T> type, Object value) {
return convert(type, value, null);
}
@@ -203,6 +205,7 @@ public abstract class BaseLocaleConverte
* Convert the specified locale-sensitive input object into an output object of the
* specified type.
*
+ * @param <T> The desired target type of the conversion
* @param type Data is type to which this value should be converted
* @param value is the input object to be converted
* @param pattern is the pattern is used for the conversion; if null is
@@ -213,10 +216,11 @@ public abstract class BaseLocaleConverte
* @exception ConversionException if conversion cannot be performed
* successfully
*/
- public Object convert(Class type, Object value, String pattern) {
+ public <T> T convert(Class<T> type, Object value, String pattern) {
+ Class<T> targetType = ConvertUtils.primitiveToWrapper(type);
if (value == null) {
if (useDefault) {
- return (defaultValue);
+ return getDefaultAs(targetType);
} else {
// symmetric beanutils function allows null
// so do not: throw new ConversionException("No value specified");
@@ -227,13 +231,13 @@ public abstract class BaseLocaleConverte
try {
if (pattern != null) {
- return parse(value, pattern);
+ return checkConversionResult(targetType, parse(value, pattern));
} else {
- return parse(value, this.pattern);
+ return checkConversionResult(targetType, parse(value, this.pattern));
}
} catch (Exception e) {
if (useDefault) {
- return (defaultValue);
+ return getDefaultAs(targetType);
} else {
if (e instanceof ConversionException) {
throw (ConversionException)e;
@@ -242,4 +246,44 @@ public abstract class BaseLocaleConverte
}
}
}
+
+ /**
+ * Returns the default object specified for this converter cast for the
+ * given target type. If the default value is not conform to the given type,
+ * an exception is thrown.
+ *
+ * @param <T> the desired target type
+ * @param type the target class of the conversion
+ * @return the default value in the given target type
+ * @throws ConversionException if the default object is not compatible with
+ * the target type
+ */
+ private <T> T getDefaultAs(Class<T> type) {
+ return checkConversionResult(type, defaultValue);
+ }
+
+ /**
+ * Checks whether the result of a conversion is conform to the specified
+ * target type. If this is the case, the passed in result object is cast to
+ * the correct target type. Otherwise, an exception is thrown.
+ *
+ * @param <T> the desired result type
+ * @param type the target class of the conversion
+ * @param result the conversion result object
+ * @return the result cast to the target class
+ * @throws ConversionException if the result object is not compatible with
+ * the target type
+ */
+ private static <T> T checkConversionResult(Class<T> type, Object result) {
+ if (type == null) {
+ // in this case we cannot do much; the result object is returned
+ @SuppressWarnings("unchecked")
+ T temp = (T) result;
+ return temp;
+ }
+ if (type.isInstance(result)) {
+ return type.cast(result);
+ }
+ throw new ConversionException("Unsupported target type: " + type);
+ }
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtils.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtils.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtils.java Fri Nov 8 21:08:30 2013
@@ -18,11 +18,11 @@
package org.apache.commons.beanutils.locale;
-import org.apache.commons.beanutils.BeanUtils;
-
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
+import org.apache.commons.beanutils.BeanUtils;
+
/**
@@ -558,7 +558,7 @@ public class LocaleBeanUtils extends Bea
*
* @see LocaleBeanUtilsBean#definePropertyType(Object, String, String)
*/
- protected static Class definePropertyType(Object target, String name, String propName)
+ protected static Class<?> definePropertyType(Object target, String name, String propName)
throws IllegalAccessException, InvocationTargetException {
return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().definePropertyType(target, name, propName);
@@ -577,7 +577,7 @@ public class LocaleBeanUtils extends Bea
* @return The converted value
* @see LocaleBeanUtilsBean#convert(Class, int, Object, String)
*/
- protected static Object convert(Class type, int index, Object value, String pattern) {
+ protected static Object convert(Class<?> type, int index, Object value, String pattern) {
return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().convert(type, index, value, pattern);
}
@@ -593,7 +593,7 @@ public class LocaleBeanUtils extends Bea
* @return The converted value
* @see LocaleBeanUtilsBean#convert(Class, int, Object)
*/
- protected static Object convert(Class type, int index, Object value) {
+ protected static Object convert(Class<?> type, int index, Object value) {
return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().convert(type, index, value);
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsBean.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsBean.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsBean.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsBean.java Fri Nov 8 21:08:30 2013
@@ -18,7 +18,13 @@
package org.apache.commons.beanutils.locale;
+import java.beans.IndexedPropertyDescriptor;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Locale;
+
import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.ContextClassLoaderLocal;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.ConvertUtilsBean;
import org.apache.commons.beanutils.DynaBean;
@@ -26,16 +32,10 @@ import org.apache.commons.beanutils.Dyna
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.MappedPropertyDescriptor;
import org.apache.commons.beanutils.PropertyUtilsBean;
-import org.apache.commons.beanutils.ContextClassLoaderLocal;
import org.apache.commons.beanutils.expression.Resolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.beans.IndexedPropertyDescriptor;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Locale;
-
/**
* <p>Utility methods for populating JavaBeans properties
@@ -50,11 +50,11 @@ public class LocaleBeanUtilsBean extends
/**
* Contains <code>LocaleBeanUtilsBean</code> instances indexed by context classloader.
*/
- private static final ContextClassLoaderLocal
- LOCALE_BEANS_BY_CLASSLOADER = new ContextClassLoaderLocal() {
+ private static final ContextClassLoaderLocal<LocaleBeanUtilsBean>
+ LOCALE_BEANS_BY_CLASSLOADER = new ContextClassLoaderLocal<LocaleBeanUtilsBean>() {
// Creates the default instance used when the context classloader is unavailable
@Override
- protected Object initialValue() {
+ protected LocaleBeanUtilsBean initialValue() {
return new LocaleBeanUtilsBean();
}
};
@@ -65,7 +65,7 @@ public class LocaleBeanUtilsBean extends
* @return the singleton instance
*/
public static LocaleBeanUtilsBean getLocaleBeanUtilsInstance() {
- return (LocaleBeanUtilsBean)LOCALE_BEANS_BY_CLASSLOADER.get();
+ return LOCALE_BEANS_BY_CLASSLOADER.get();
}
/**
@@ -312,7 +312,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
public String getSimpleProperty(Object bean, String name, String pattern)
throws IllegalAccessException, InvocationTargetException,
@@ -336,7 +336,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
@Override
public String getSimpleProperty(Object bean, String name)
@@ -363,7 +363,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
public String getMappedProperty(
Object bean,
@@ -395,7 +395,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
@Override
public String getMappedProperty(Object bean,
@@ -426,7 +426,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
public String getMappedPropertyLocale(
Object bean,
@@ -461,7 +461,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
@Override
public String getMappedProperty(Object bean, String name)
@@ -490,7 +490,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
public String getNestedProperty(
Object bean,
@@ -521,7 +521,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
@Override
public String getNestedProperty(Object bean, String name)
@@ -549,7 +549,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
public String getProperty(Object bean, String name, String pattern)
throws
@@ -576,7 +576,7 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
- * propety cannot be found
+ * property cannot be found
*/
@Override
public String getProperty(Object bean, String name)
@@ -687,7 +687,7 @@ public class LocaleBeanUtilsBean extends
int index = resolver.getIndex(name); // Indexed subscript value (if any)
String key = resolver.getKey(name); // Mapped key value (if any)
- Class type = definePropertyType(target, name, propName);
+ Class<?> type = definePropertyType(target, name, propName);
if (type != null) {
Object newValue = convert(type, index, value, pattern);
invokeSetter(target, propName, key, index, newValue);
@@ -707,10 +707,10 @@ public class LocaleBeanUtilsBean extends
* @exception InvocationTargetException if the property accessor method
* throws an exception
*/
- protected Class definePropertyType(Object target, String name, String propName)
+ protected Class<?> definePropertyType(Object target, String name, String propName)
throws IllegalAccessException, InvocationTargetException {
- Class type = null; // Java type of target property
+ Class<?> type = null; // Java type of target property
if (target instanceof DynaBean) {
DynaClass dynaClass = ((DynaBean) target).getDynaClass();
@@ -757,7 +757,7 @@ public class LocaleBeanUtilsBean extends
* @param pattern The conversion pattern
* @return The converted value
*/
- protected Object convert(Class type, int index, Object value, String pattern) {
+ protected Object convert(Class<?> type, int index, Object value, String pattern) {
if (log.isTraceEnabled()) {
log.trace("Converting value '" + value + "' to type:" + type);
@@ -814,7 +814,7 @@ public class LocaleBeanUtilsBean extends
* @param value The value to be converted
* @return The converted value
*/
- protected Object convert(Class type, int index, Object value) {
+ protected Object convert(Class<?> type, int index, Object value) {
Object newValue = null;
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtils.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtils.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtils.java Fri Nov 8 21:08:30 2013
@@ -17,10 +17,10 @@
package org.apache.commons.beanutils.locale;
-import org.apache.commons.collections.FastHashMap;
-
import java.util.Locale;
+import org.apache.commons.collections.FastHashMap;
+
/**
* <p>Utility methods for converting locale-sensitive String scalar values to objects of the
* specified Class, String arrays to arrays of the specified Class and
@@ -147,7 +147,7 @@ public class LocaleConvertUtils {
* @return the converted value
* @see LocaleConvertUtilsBean#convert(String, Class)
*/
- public static Object convert(String value, Class clazz) {
+ public static Object convert(String value, Class<?> clazz) {
return LocaleConvertUtilsBean.getInstance().convert(value, clazz);
}
@@ -165,7 +165,7 @@ public class LocaleConvertUtils {
* @return the converted value
* @see LocaleConvertUtilsBean#convert(String, Class, String)
*/
- public static Object convert(String value, Class clazz, String pattern) {
+ public static Object convert(String value, Class<?> clazz, String pattern) {
return LocaleConvertUtilsBean.getInstance().convert(value, clazz, pattern);
}
@@ -184,7 +184,7 @@ public class LocaleConvertUtils {
* @return the converted value
* @see LocaleConvertUtilsBean#convert(String, Class, Locale, String)
*/
- public static Object convert(String value, Class clazz, Locale locale, String pattern) {
+ public static Object convert(String value, Class<?> clazz, Locale locale, String pattern) {
return LocaleConvertUtilsBean.getInstance().convert(value, clazz, locale, pattern);
}
@@ -201,7 +201,7 @@ public class LocaleConvertUtils {
* @return the converted value
* @see LocaleConvertUtilsBean#convert(String[], Class, String)
*/
- public static Object convert(String[] values, Class clazz, String pattern) {
+ public static Object convert(String[] values, Class<?> clazz, String pattern) {
return LocaleConvertUtilsBean.getInstance().convert(values, clazz, pattern);
}
@@ -217,7 +217,7 @@ public class LocaleConvertUtils {
* @return the converted value
* @see LocaleConvertUtilsBean#convert(String[], Class)
*/
- public static Object convert(String[] values, Class clazz) {
+ public static Object convert(String[] values, Class<?> clazz) {
return LocaleConvertUtilsBean.getInstance().convert(values, clazz);
}
@@ -235,7 +235,7 @@ public class LocaleConvertUtils {
* @return the converted value
* @see LocaleConvertUtilsBean#convert(String[], Class, Locale, String)
*/
- public static Object convert(String[] values, Class clazz, Locale locale, String pattern) {
+ public static Object convert(String[] values, Class<?> clazz, Locale locale, String pattern) {
return LocaleConvertUtilsBean.getInstance().convert(values, clazz, locale, pattern);
}
@@ -252,7 +252,7 @@ public class LocaleConvertUtils {
* @param locale The locale
* @see LocaleConvertUtilsBean#register(LocaleConverter, Class, Locale)
*/
- public static void register(LocaleConverter converter, Class clazz, Locale locale) {
+ public static void register(LocaleConverter converter, Class<?> clazz, Locale locale) {
LocaleConvertUtilsBean.getInstance().register(converter, clazz, locale);
}
@@ -293,7 +293,7 @@ public class LocaleConvertUtils {
* @param locale The locale
* @see LocaleConvertUtilsBean#deregister(Class, Locale)
*/
- public static void deregister(Class clazz, Locale locale) {
+ public static void deregister(Class<?> clazz, Locale locale) {
LocaleConvertUtilsBean.getInstance().deregister(clazz, locale);
}
@@ -310,7 +310,7 @@ public class LocaleConvertUtils {
* @return The registered locale Converter, if any
* @see LocaleConvertUtilsBean#lookup(Class, Locale)
*/
- public static LocaleConverter lookup(Class clazz, Locale locale) {
+ public static LocaleConverter lookup(Class<?> clazz, Locale locale) {
return LocaleConvertUtilsBean.getInstance().lookup(clazz, locale);
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java Fri Nov 8 21:08:30 2013
@@ -17,6 +17,14 @@
package org.apache.commons.beanutils.locale;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.locale.converters.BigDecimalLocaleConverter;
import org.apache.commons.beanutils.locale.converters.BigIntegerLocaleConverter;
@@ -26,23 +34,14 @@ import org.apache.commons.beanutils.loca
import org.apache.commons.beanutils.locale.converters.IntegerLocaleConverter;
import org.apache.commons.beanutils.locale.converters.LongLocaleConverter;
import org.apache.commons.beanutils.locale.converters.ShortLocaleConverter;
-import org.apache.commons.beanutils.locale.converters.StringLocaleConverter;
import org.apache.commons.beanutils.locale.converters.SqlDateLocaleConverter;
import org.apache.commons.beanutils.locale.converters.SqlTimeLocaleConverter;
import org.apache.commons.beanutils.locale.converters.SqlTimestampLocaleConverter;
-
+import org.apache.commons.beanutils.locale.converters.StringLocaleConverter;
import org.apache.commons.collections.FastHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Collection;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
/**
* <p>Utility methods for converting locale-sensitive String scalar values to objects of the
* specified Class, String arrays to arrays of the specified Class and
@@ -214,7 +213,7 @@ public class LocaleConvertUtilsBean {
LocaleConverter converter = lookup(String.class, locale);
- return (String) converter.convert(String.class, value, pattern);
+ return converter.convert(String.class, value, pattern);
}
/**
@@ -228,7 +227,7 @@ public class LocaleConvertUtilsBean {
* @throws org.apache.commons.beanutils.ConversionException if thrown by an
* underlying Converter
*/
- public Object convert(String value, Class clazz) {
+ public Object convert(String value, Class<?> clazz) {
return convert(value, clazz, defaultLocale, null);
}
@@ -246,7 +245,7 @@ public class LocaleConvertUtilsBean {
* @throws org.apache.commons.beanutils.ConversionException if thrown by an
* underlying Converter
*/
- public Object convert(String value, Class clazz, String pattern) {
+ public Object convert(String value, Class<?> clazz, String pattern) {
return convert(value, clazz, defaultLocale, pattern);
}
@@ -265,7 +264,7 @@ public class LocaleConvertUtilsBean {
* @throws org.apache.commons.beanutils.ConversionException if thrown by an
* underlying Converter
*/
- public Object convert(String value, Class clazz, Locale locale, String pattern) {
+ public Object convert(String value, Class<?> clazz, Locale locale, String pattern) {
if (log.isDebugEnabled()) {
log.debug("Convert string " + value + " to class " +
@@ -273,16 +272,18 @@ public class LocaleConvertUtilsBean {
" locale and " + pattern + " pattern");
}
+ Class<?> targetClass = clazz;
LocaleConverter converter = lookup(clazz, locale);
if (converter == null) {
converter = lookup(String.class, locale);
+ targetClass = String.class;
}
if (log.isTraceEnabled()) {
log.trace(" Using converter " + converter);
}
- return (converter.convert(clazz, value, pattern));
+ return (converter.convert(targetClass, value, pattern));
}
/**
@@ -297,7 +298,7 @@ public class LocaleConvertUtilsBean {
* @throws org.apache.commons.beanutils.ConversionException if thrown by an
* underlying Converter
*/
- public Object convert(String[] values, Class clazz, String pattern) {
+ public Object convert(String[] values, Class<?> clazz, String pattern) {
return convert(values, clazz, getDefaultLocale(), pattern);
}
@@ -313,7 +314,7 @@ public class LocaleConvertUtilsBean {
* @throws org.apache.commons.beanutils.ConversionException if thrown by an
* underlying Converter
*/
- public Object convert(String[] values, Class clazz) {
+ public Object convert(String[] values, Class<?> clazz) {
return convert(values, clazz, getDefaultLocale(), null);
}
@@ -331,9 +332,9 @@ public class LocaleConvertUtilsBean {
* @throws org.apache.commons.beanutils.ConversionException if thrown by an
* underlying Converter
*/
- public Object convert(String[] values, Class clazz, Locale locale, String pattern) {
+ public Object convert(String[] values, Class<?> clazz, Locale locale, String pattern) {
- Class type = clazz;
+ Class<?> type = clazz;
if (clazz.isArray()) {
type = clazz.getComponentType();
}
@@ -360,7 +361,7 @@ public class LocaleConvertUtilsBean {
* Converter
* @param locale The locale
*/
- public void register(LocaleConverter converter, Class clazz, Locale locale) {
+ public void register(LocaleConverter converter, Class<?> clazz, Locale locale) {
lookup(locale).put(clazz, converter);
}
@@ -398,7 +399,7 @@ public class LocaleConvertUtilsBean {
* @param clazz Class for which to remove a registered Converter
* @param locale The locale
*/
- public void deregister(Class clazz, Locale locale) {
+ public void deregister(Class<?> clazz, Locale locale) {
lookup(locale).remove(clazz);
}
@@ -412,7 +413,7 @@ public class LocaleConvertUtilsBean {
* @param locale The Locale
* @return The registered locale Converter, if any
*/
- public LocaleConverter lookup(Class clazz, Locale locale) {
+ public LocaleConverter lookup(Class<?> clazz, Locale locale) {
LocaleConverter converter = (LocaleConverter) lookup(locale).get(clazz);
@@ -511,9 +512,9 @@ public class LocaleConvertUtilsBean {
*/
private static class DelegateFastHashMap extends FastHashMap {
- private final Map map;
+ private final Map<Object, Object> map;
- private DelegateFastHashMap(Map map) {
+ private DelegateFastHashMap(Map<Object, Object> map) {
this.map = map;
}
@Override
@@ -529,7 +530,7 @@ public class LocaleConvertUtilsBean {
return map.containsValue(value);
}
@Override
- public Set entrySet() {
+ public Set<Map.Entry<Object, Object>> entrySet() {
return map.entrySet();
}
@Override
@@ -549,13 +550,16 @@ public class LocaleConvertUtilsBean {
return map.isEmpty();
}
@Override
- public Set keySet() {
+ public Set<Object> keySet() {
return map.keySet();
}
@Override
public Object put(Object key, Object value) {
return map.put(key, value);
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ // we operate on very generic types (<Object, Object>), so there is
+ // no need for doing type checks
@Override
public void putAll(Map m) {
map.putAll(m);
@@ -569,7 +573,7 @@ public class LocaleConvertUtilsBean {
return map.size();
}
@Override
- public Collection values() {
+ public Collection<Object> values() {
return map.values();
}
@Override
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConverter.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConverter.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/locale/LocaleConverter.java Fri Nov 8 21:08:30 2013
@@ -35,13 +35,14 @@ public interface LocaleConverter extends
* Convert the specified locale-sensitive input object into an output object of the
* specified type.
*
+ * @param <T> The desired target type of the conversion
* @param type Data type to which this value should be converted
* @param value The input value to be converted
* @param pattern The user-defined pattern is used for the input object formatting.
* @return The converted value
*
* @exception org.apache.commons.beanutils.ConversionException if conversion
- * cannot be performed successfully
+ * cannot be performed successfully or if the target type is not supported
*/
- public Object convert(Class type, Object value, String pattern);
+ public <T> T convert(Class<T> type, Object value, String pattern);
}
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java Fri Nov 8 21:08:30 2013
@@ -41,12 +41,6 @@ public class BeanComparatorTestCase exte
protected AlphaBean alphaBean1 = null;
protected AlphaBean alphaBean2 = null;
- // The test BeanComparator
- protected BeanComparator beanComparator = null;
-
-
-
-
// ---------------------------------------------------------- Constructors
@@ -91,7 +85,6 @@ public class BeanComparatorTestCase exte
bean = null;
alphaBean1 = null;
alphaBean2 = null;
- beanComparator = null;
}
@@ -102,62 +95,46 @@ public class BeanComparatorTestCase exte
* tests comparing two beans via their name using the default Comparator
*/
public void testSimpleCompare() {
- try {
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean1, alphaBean2);
- assertTrue("Comparator did not sort properly. Result:" + result,result==-1);
-
- }
- catch (Exception e) {
- fail("Exception");
- }
+ BeanComparator<AlphaBean> beanComparator = new BeanComparator<AlphaBean>(
+ "name");
+ int result = beanComparator.compare(alphaBean1, alphaBean2);
+ assertTrue("Comparator did not sort properly. Result:" + result,
+ result == -1);
}
/**
* tests comparing two beans via their name using the default Comparator, but the inverse
*/
public void testSimpleCompareInverse() {
- try {
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean2, alphaBean1);
- assertTrue("Comparator did not sort properly. Result:" + result,result==1);
-
- }
- catch (Exception e) {
- fail("Exception" + e);
- }
+ BeanComparator<AlphaBean> beanComparator = new BeanComparator<AlphaBean>(
+ "name");
+ int result = beanComparator.compare(alphaBean2, alphaBean1);
+ assertTrue("Comparator did not sort properly. Result:" + result,
+ result == 1);
}
/**
* tests comparing two beans via their name using the default Comparator where they have the same value.
*/
public void testCompareIdentical() {
- try {
- alphaBean1 = new AlphaBean("alphabean");
- alphaBean2 = new AlphaBean("alphabean");
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean1, alphaBean2);
- assertTrue("Comparator did not sort properly. Result:" + result,result==0);
-
- }
- catch (Exception e) {
- fail("Exception");
- }
+ alphaBean1 = new AlphaBean("alphabean");
+ alphaBean2 = new AlphaBean("alphabean");
+ BeanComparator<AlphaBean> beanComparator = new BeanComparator<AlphaBean>(
+ "name");
+ int result = beanComparator.compare(alphaBean1, alphaBean2);
+ assertTrue("Comparator did not sort properly. Result:" + result,
+ result == 0);
}
/**
* tests comparing one bean against itself.
*/
public void testCompareBeanAgainstSelf() {
- try {
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean1, alphaBean1);
- assertTrue("Comparator did not sort properly. Result:" + result,result==0);
-
- }
- catch (Exception e) {
- fail("Exception");
- }
+ BeanComparator<AlphaBean> beanComparator = new BeanComparator<AlphaBean>(
+ "name");
+ int result = beanComparator.compare(alphaBean1, alphaBean1);
+ assertTrue("Comparator did not sort properly. Result:" + result,
+ result == 0);
}
/**
@@ -166,15 +143,13 @@ public class BeanComparatorTestCase exte
*/
public void testCompareWithNulls() {
try {
- beanComparator = new BeanComparator("name");
+ BeanComparator<AlphaBean> beanComparator = new BeanComparator<AlphaBean>("name");
beanComparator.compare(alphaBean2, null);
- // DEP not sure if this is the best way to test an exception?
fail("Should not be able to compare a null value.");
-
}
catch (Exception e) {
-
+ // expected result
}
}
@@ -183,7 +158,7 @@ public class BeanComparatorTestCase exte
*/
public void testCompareOnMissingProperty() {
try {
- beanComparator = new BeanComparator("bogusName");
+ BeanComparator<AlphaBean> beanComparator = new BeanComparator<AlphaBean>("bogusName");
beanComparator.compare(alphaBean2, alphaBean1);
fail("should not be able to compare");
@@ -205,7 +180,7 @@ public class BeanComparatorTestCase exte
testBeanA.setBooleanProperty(true);
testBeanB.setBooleanProperty(false);
- beanComparator = new BeanComparator("booleanProperty");
+ BeanComparator<TestBean> beanComparator = new BeanComparator<TestBean>("booleanProperty");
beanComparator.compare(testBeanA, testBeanB);
// **** java.lang.Boolean implements Comparable from JDK 1.5 onwards
@@ -216,44 +191,33 @@ public class BeanComparatorTestCase exte
catch (ClassCastException cce){
// Expected result
}
- catch (Exception e) {
- fail("Exception" + e);
- }
}
/**
* tests comparing two beans on a boolean property, then changing the property and testing
*/
public void testSetProperty() {
- try {
- TestBean testBeanA = new TestBean();
- TestBean testBeanB = new TestBean();
-
- testBeanA.setDoubleProperty(5.5);
- testBeanB.setDoubleProperty(1.0);
+ TestBean testBeanA = new TestBean();
+ TestBean testBeanB = new TestBean();
- beanComparator = new BeanComparator("doubleProperty");
- int result = beanComparator.compare(testBeanA, testBeanB);
+ testBeanA.setDoubleProperty(5.5);
+ testBeanB.setDoubleProperty(1.0);
- assertTrue("Comparator did not sort properly. Result:" + result,result==1);
+ BeanComparator<TestBean> beanComparator = new BeanComparator<TestBean>(
+ "doubleProperty");
+ int result = beanComparator.compare(testBeanA, testBeanB);
- testBeanA.setStringProperty("string 1");
- testBeanB.setStringProperty("string 2");
+ assertTrue("Comparator did not sort properly. Result:" + result,
+ result == 1);
- beanComparator.setProperty("stringProperty");
+ testBeanA.setStringProperty("string 1");
+ testBeanB.setStringProperty("string 2");
- result = beanComparator.compare(testBeanA, testBeanB);
+ beanComparator.setProperty("stringProperty");
- assertTrue("Comparator did not sort properly. Result:" + result,result==-1);
+ result = beanComparator.compare(testBeanA, testBeanB);
- }
- catch (ClassCastException cce){
- fail("ClassCaseException " + cce.toString());
- }
- catch (Exception e) {
- fail("Exception" + e);
- }
+ assertTrue("Comparator did not sort properly. Result:" + result,
+ result == -1);
}
}
-
-
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanMapTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanMapTestCase.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanMapTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanMapTestCase.java Fri Nov 8 21:08:30 2013
@@ -19,22 +19,23 @@ package org.apache.commons.beanutils;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
import junit.framework.Test;
import junit.textui.TestRunner;
import org.apache.commons.beanutils.bugs.other.Jira87BeanFactory;
-import org.apache.commons.collections.map.AbstractTestMap;
import org.apache.commons.collections.BulkTest;
import org.apache.commons.collections.Transformer;
+import org.apache.commons.collections.map.AbstractTestMap;
/**
* Test cases for BeanMap
*
* @version $Id$
*/
+@SuppressWarnings("deprecation")
public class BeanMapTestCase extends AbstractTestMap {
public BeanMapTestCase(String testName) {
@@ -271,7 +272,7 @@ public class BeanMapTestCase extends Abs
}
@Override
- public Map makeFullMap() {
+ public Map<Object, Object> makeFullMap() {
// note: These values must match (i.e. .equals() must return true)
// those returned from getSampleValues().
BeanWithProperties bean = new BeanWithProperties();
@@ -289,7 +290,7 @@ public class BeanMapTestCase extends Abs
}
@Override
- public Map makeEmptyMap() {
+ public Map<Object, Object> makeEmptyMap() {
return new BeanMap();
}
@@ -361,7 +362,7 @@ public class BeanMapTestCase extends Abs
public void testMethodAccessor() throws Exception {
BeanMap map = (BeanMap) makeFullMap();
- Method method = BeanWithProperties.class.getDeclaredMethod("getSomeIntegerValue", null);
+ Method method = BeanWithProperties.class.getDeclaredMethod("getSomeIntegerValue");
assertEquals(method, map.getReadMethod("someIntegerValue"));
}
@@ -390,7 +391,6 @@ public class BeanMapTestCase extends Abs
* Test the default transformers via the public static Map instance
*/
public void testGetDefaultTransformersMap() {
- BeanMap beanMap = new BeanMap();
assertEquals("Boolean.TYPE", Boolean.TRUE, ((Transformer)BeanMap.defaultTransformers.get(Boolean.TYPE)).transform("true"));
assertEquals("Character.TYPE", new Character('B'), ((Transformer)BeanMap.defaultTransformers.get(Character.TYPE)).transform("BCD"));
assertEquals("Byte.TYPE", new Byte((byte)1), ((Transformer)BeanMap.defaultTransformers.get(Byte.TYPE)).transform("1"));
@@ -428,7 +428,7 @@ public class BeanMapTestCase extends Abs
// expected result
}
try {
- BeanMap.defaultTransformers.putAll(new HashMap());
+ BeanMap.defaultTransformers.putAll(new HashMap<Object, Object>());
fail("putAll() - expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected result
@@ -513,7 +513,7 @@ public class BeanMapTestCase extends Abs
}
/**
- * Test that the cause of exception thrown by put() is initialised.
+ * Test that the cause of exception thrown by put() is initialized.
*/
public void testExceptionThrowFromPut() {
@@ -523,7 +523,7 @@ public class BeanMapTestCase extends Abs
}
try {
- Map map = new BeanMap(new BeanThrowingExceptions());
+ Map<Object, Object> map = new BeanMap(new BeanThrowingExceptions());
map.put("valueThrowingException", "value");
fail("Setter exception - expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsBenchCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsBenchCase.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsBenchCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsBenchCase.java Fri Nov 8 21:08:30 2013
@@ -22,8 +22,9 @@ package org.apache.commons.beanutils;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import junit.framework.TestCase;
+
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -63,8 +64,8 @@ public class BeanUtilsBenchCase extends
// Input objects that have identical sets of properties and values.
private BenchBean inBean = null;
private DynaBean inDyna = null;
- private Map inMap = null; // Map of Objects requiring no conversion
- private Map inStrs = null; // Map of Strings requiring conversion
+ private Map<String, Object> inMap = null; // Map of Objects requiring no conversion
+ private Map<String, String> inStrs = null; // Map of Strings requiring conversion
// Output objects that have identical sets of properties.
private BenchBean outBean = null;
@@ -105,7 +106,7 @@ public class BeanUtilsBenchCase extends
// Create input instances
inBean = new BenchBean();
- inMap = new HashMap();
+ inMap = new HashMap<String, Object>();
inMap.put("booleanProperty", new Boolean(inBean.getBooleanProperty()));
inMap.put("byteProperty", new Byte(inBean.getByteProperty()));
inMap.put("doubleProperty", new Double(inBean.getDoubleProperty()));
@@ -115,24 +116,24 @@ public class BeanUtilsBenchCase extends
inMap.put("shortProperty", new Short(inBean.getShortProperty()));
inMap.put("stringProperty", inBean.getStringProperty());
inDyna = dynaClass.newInstance();
- Iterator inKeys = inMap.keySet().iterator();
+ Iterator<String> inKeys = inMap.keySet().iterator();
while (inKeys.hasNext()) {
- String inKey = (String) inKeys.next();
+ String inKey = inKeys.next();
inDyna.set(inKey, inMap.get(inKey));
}
- inStrs = new HashMap();
+ inStrs = new HashMap<String, String>();
inKeys = inMap.keySet().iterator();
while (inKeys.hasNext()) {
- String inKey = (String) inKeys.next();
+ String inKey = inKeys.next();
inStrs.put(inKey, inMap.get(inKey).toString());
}
// Create output instances
outBean = new BenchBean();
outDyna = dynaClass.newInstance();
- Iterator outKeys = inMap.keySet().iterator();
+ Iterator<String> outKeys = inMap.keySet().iterator();
while (outKeys.hasNext()) {
- String outKey = (String) outKeys.next();
+ String outKey = outKeys.next();
outDyna.set(outKey, inMap.get(outKey));
}
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsTestCase.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanUtilsTestCase.java Fri Nov 8 21:08:30 2013
@@ -26,13 +26,13 @@ import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
-import org.apache.commons.beanutils.converters.ArrayConverter;
-import org.apache.commons.beanutils.converters.DateConverter;
-
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.commons.beanutils.converters.ArrayConverter;
+import org.apache.commons.beanutils.converters.DateConverter;
+
/**
* <p>
@@ -257,7 +257,7 @@ public class BeanUtilsTestCase extends T
*/
public void testCopyPropertiesMap() {
- Map map = new HashMap();
+ Map<String, Object> map = new HashMap<String, Object>();
map.put("booleanProperty", "false");
map.put("byteProperty", "111");
map.put("doubleProperty", "333.0");
@@ -386,7 +386,7 @@ public class BeanUtilsTestCase extends T
*/
public void testDescribe() {
- Map map = null;
+ Map<String, String> map = null;
try {
map = BeanUtils.describe(bean);
} catch (Exception e) {
@@ -404,28 +404,28 @@ public class BeanUtilsTestCase extends T
// Verify the values of scalar properties
assertEquals("Value of 'booleanProperty'",
"true",
- (String) map.get("booleanProperty"));
+ map.get("booleanProperty"));
assertEquals("Value of 'byteProperty'",
"121",
- (String) map.get("byteProperty"));
+ map.get("byteProperty"));
assertEquals("Value of 'doubleProperty'",
"321.0",
- (String) map.get("doubleProperty"));
+ map.get("doubleProperty"));
assertEquals("Value of 'floatProperty'",
"123.0",
- (String) map.get("floatProperty"));
+ map.get("floatProperty"));
assertEquals("Value of 'intProperty'",
"123",
- (String) map.get("intProperty"));
+ map.get("intProperty"));
assertEquals("Value of 'longProperty'",
"321",
- (String) map.get("longProperty"));
+ map.get("longProperty"));
assertEquals("Value of 'shortProperty'",
"987",
- (String) map.get("shortProperty"));
+ map.get("shortProperty"));
assertEquals("Value of 'stringProperty'",
"This is a string",
- (String) map.get("stringProperty"));
+ map.get("stringProperty"));
}
@@ -456,7 +456,6 @@ public class BeanUtilsTestCase extends T
// Test comma delimited list
- String value1 = "ABC";
bean.setStringProperty("ABC");
arr = BeanUtils.getArrayProperty(bean, "stringProperty");
assertEquals("Delimited List Test lth", 1, arr.length);
@@ -626,7 +625,7 @@ public class BeanUtilsTestCase extends T
try {
- HashMap map = new HashMap();
+ HashMap<String, Object> map = new HashMap<String, Object>();
map.put("intIndexed[0]", "100");
map.put("intIndexed[2]", "120");
map.put("intIndexed[4]", "140");
@@ -677,7 +676,7 @@ public class BeanUtilsTestCase extends T
try {
- HashMap map = new HashMap();
+ HashMap<String, Object> map = new HashMap<String, Object>();
int intArray[] = new int[] { 123, 456, 789 };
map.put("intArray", intArray);
String stringArray[] = new String[]
@@ -715,7 +714,7 @@ public class BeanUtilsTestCase extends T
try {
- HashMap map = new HashMap();
+ HashMap<String, Object> map = new HashMap<String, Object>();
map.put("mappedProperty(First Key)", "New First Value");
map.put("mappedProperty(Third Key)", "New Third Value");
@@ -749,7 +748,7 @@ public class BeanUtilsTestCase extends T
try {
- HashMap map = new HashMap();
+ HashMap<String, Object> map = new HashMap<String, Object>();
map.put("nested.booleanProperty", "false");
// booleanSecond is left at true
map.put("nested.doubleProperty", "432.0");
@@ -805,7 +804,7 @@ public class BeanUtilsTestCase extends T
bean.setNullProperty("Non-null value");
- HashMap map = new HashMap();
+ HashMap<String, Object> map = new HashMap<String, Object>();
map.put("booleanProperty", "false");
// booleanSecond is left at true
map.put("byteProperty", "111");
@@ -1370,10 +1369,10 @@ public class BeanUtilsTestCase extends T
*/
public void testCopyPropertyNestedMappedMap() throws Exception {
- Map origMap = new HashMap();
+ Map<String, Object> origMap = new HashMap<String, Object>();
origMap.put("First Key", "First Value");
origMap.put("Second Key", "Second Value");
- Map changedMap = new HashMap();
+ Map<String, Object> changedMap = new HashMap<String, Object>();
changedMap.put("First Key", "First Value");
changedMap.put("Second Key", "Second Value");
@@ -1477,19 +1476,19 @@ public class BeanUtilsTestCase extends T
*/
public void testSetMappedMap() {
TestBean bean = new TestBean();
- Map map = new HashMap();
+ Map<String, Object> map = new HashMap<String, Object>();
map.put("sub-key-1", "sub-value-1");
map.put("sub-key-2", "sub-value-2");
map.put("sub-key-3", "sub-value-3");
bean.getMapProperty().put("mappedMap", map);
- assertEquals("BEFORE", "sub-value-3", ((Map)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
+ assertEquals("BEFORE", "sub-value-3", ((Map<?, ?>)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
try {
BeanUtils.setProperty(bean, "mapProperty(mappedMap)(sub-key-3)", "SUB-KEY-3-UPDATED");
} catch (Throwable t) {
fail("Threw " + t + "");
}
- assertEquals("AFTER", "SUB-KEY-3-UPDATED", ((Map)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
+ assertEquals("AFTER", "SUB-KEY-3-UPDATED", ((Map<?, ?>)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
}
/** Tests that separate instances can register separate instances */
@@ -1569,10 +1568,10 @@ public class BeanUtilsTestCase extends T
// Ensure that the actual Map matches the expected Map
- protected void checkMap(Map actual, Map expected) {
+ protected void checkMap(Map<?, ?> actual, Map<?, ?> expected) {
assertNotNull("actual map not null", actual);
assertEquals("actual map size", expected.size(), actual.size());
- Iterator keys = expected.keySet().iterator();
+ Iterator<?> keys = expected.keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
assertEquals("actual map value(" + key + ")",
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java Fri Nov 8 21:08:30 2013
@@ -17,13 +17,13 @@
package org.apache.commons.beanutils;
-import java.lang.ref.WeakReference;
import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
import java.util.Map;
import java.util.WeakHashMap;
-import junit.framework.TestCase;
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.LogFactory;
@@ -97,8 +97,9 @@ public class BeanificationTestCase exten
// test methodology
// many thanks to Juozas Baliuka for suggesting this method
ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) {};
- WeakReference reference = new WeakReference(loader);
- Class myClass = loader.loadClass("org.apache.commons.beanutils.BetaBean");
+ WeakReference<ClassLoader> reference = new WeakReference<ClassLoader>(loader);
+ @SuppressWarnings("unused")
+ Class<?> myClass = loader.loadClass("org.apache.commons.beanutils.BetaBean");
assertNotNull("Weak reference released early", reference.get());
@@ -118,6 +119,7 @@ public class BeanificationTestCase exten
} else {
// create garbage:
+ @SuppressWarnings("unused")
byte[] b = new byte[bytz];
bytz = bytz * 2;
}
@@ -135,13 +137,13 @@ public class BeanificationTestCase exten
// many thanks to Juozas Baliuka for suggesting this methodology
TestClassLoader loader = new TestClassLoader();
- ReferenceQueue queue = new ReferenceQueue();
- WeakReference loaderReference = new WeakReference(loader, queue);
+ ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
+ WeakReference<ClassLoader> loaderReference = new WeakReference<ClassLoader>(loader, queue);
Integer test = new Integer(1);
- WeakReference testReference = new WeakReference(test, queue);
+ WeakReference<Integer> testReference = new WeakReference<Integer>(test, queue);
//Map map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
- Map map = new WeakHashMap();
+ Map<Object, Object> map = new WeakHashMap<Object, Object>();
map.put(loader, test);
assertEquals("In map", test, map.get(loader));
@@ -168,6 +170,7 @@ public class BeanificationTestCase exten
} else {
// create garbage:
+ @SuppressWarnings("unused")
byte[] b = new byte[bytz];
bytz = bytz * 2;
}
@@ -183,7 +186,7 @@ public class BeanificationTestCase exten
// many thanks to Juozas Baliuka for suggesting this methodology
TestClassLoader loader = new TestClassLoader();
- WeakReference loaderReference = new WeakReference(loader);
+ WeakReference<ClassLoader> loaderReference = new WeakReference<ClassLoader>(loader);
BeanUtilsBean.getInstance();
class GetBeanUtilsBeanThread extends Thread {
@@ -211,15 +214,16 @@ public class BeanificationTestCase exten
GetBeanUtilsBeanThread thread = new GetBeanUtilsBeanThread();
- WeakReference threadWeakReference = new WeakReference(thread);
+ @SuppressWarnings("unused")
+ WeakReference<Thread> threadWeakReference = new WeakReference<Thread>(thread);
thread.setContextClassLoader(loader);
thread.start();
thread.join();
- WeakReference beanUtilsReference = new WeakReference(thread.beanUtils);
- WeakReference propertyUtilsReference = new WeakReference(thread.propertyUtils);
- WeakReference convertUtilsReference = new WeakReference(thread.convertUtils);
+ WeakReference<BeanUtilsBean> beanUtilsReference = new WeakReference<BeanUtilsBean>(thread.beanUtils);
+ WeakReference<PropertyUtilsBean> propertyUtilsReference = new WeakReference<PropertyUtilsBean>(thread.propertyUtils);
+ WeakReference<ConvertUtilsBean> convertUtilsReference = new WeakReference<ConvertUtilsBean>(thread.convertUtils);
assertNotNull("Weak reference released early (1)", loaderReference.get());
assertNotNull("Weak reference released early (2)", beanUtilsReference.get());
@@ -249,6 +253,7 @@ public class BeanificationTestCase exten
} else {
// create garbage:
+ @SuppressWarnings("unused")
byte[] b = new byte[bytz];
bytz = bytz * 2;
}
@@ -314,9 +319,9 @@ public class BeanificationTestCase exten
class CCLLTesterThread extends Thread {
private final Signal signal;
- private final ContextClassLoaderLocal ccll;
+ private final ContextClassLoaderLocal<Integer> ccll;
- CCLLTesterThread(Signal signal, ContextClassLoaderLocal ccll) {
+ CCLLTesterThread(Signal signal, ContextClassLoaderLocal<Integer> ccll) {
this.signal = signal;
this.ccll = ccll;
}
@@ -334,7 +339,7 @@ public class BeanificationTestCase exten
}
}
- ContextClassLoaderLocal ccll = new ContextClassLoaderLocal();
+ ContextClassLoaderLocal<Integer> ccll = new ContextClassLoaderLocal<Integer>();
ccll.set(new Integer(1776));
assertEquals("Start thread sets value", new Integer(1776), ccll.get());
@@ -369,8 +374,8 @@ public class BeanificationTestCase exten
try {
signal.setSignal(3);
ConvertUtils.register(new Converter() {
- public Object convert(Class type, Object value) {
- return new Integer(9);
+ public <T> T convert(Class<T> type, Object value) {
+ return ConvertUtils.primitiveToWrapper(type).cast(new Integer(9));
}
}, Integer.TYPE);
BeanUtils.setProperty(bean, "int", new Integer(1));
@@ -391,8 +396,8 @@ public class BeanificationTestCase exten
assertEquals("Wrong property value (1)", 1, bean.getInt());
ConvertUtils.register(new Converter() {
- public Object convert(Class type, Object value) {
- return new Integer(5);
+ public <T> T convert(Class<T> type, Object value) {
+ return ConvertUtils.primitiveToWrapper(type).cast(new Integer(5));
}
}, Integer.TYPE);
BeanUtils.setProperty(bean, "int", new Integer(1));
@@ -461,7 +466,7 @@ public class BeanificationTestCase exten
/** Tests whether the unset method works*/
public void testContextClassLoaderUnset() throws Exception {
BeanUtilsBean beanOne = new BeanUtilsBean();
- ContextClassLoaderLocal ccll = new ContextClassLoaderLocal();
+ ContextClassLoaderLocal<BeanUtilsBean> ccll = new ContextClassLoaderLocal<BeanUtilsBean>();
ccll.set(beanOne);
assertEquals("Start thread gets right instance", beanOne, ccll.get());
ccll.unset();
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java Fri Nov 8 21:08:30 2013
@@ -109,7 +109,7 @@ public class ConstructorUtilsTestCase ex
public void testInvokeConstructorWithTypeArray() throws Exception {
{
Object[] args = { Boolean.TRUE, "TEST" };
- Class[] types = { Boolean.TYPE, String.class };
+ Class<?>[] types = { Boolean.TYPE, String.class };
Object obj = ConstructorUtils.invokeConstructor(TestBean.class,args,types);
assertNotNull(obj);
assertTrue(obj instanceof TestBean);
@@ -118,7 +118,7 @@ public class ConstructorUtilsTestCase ex
}
{
Object[] args = { Boolean.TRUE, "TEST" };
- Class[] types = { Boolean.class, String.class };
+ Class<?>[] types = { Boolean.class, String.class };
Object obj = ConstructorUtils.invokeConstructor(TestBean.class,args,types);
assertNotNull(obj);
assertTrue(obj instanceof TestBean);
@@ -179,7 +179,7 @@ public class ConstructorUtilsTestCase ex
public void testInvokeExactConstructorWithTypeArray() throws Exception {
{
Object[] args = { Boolean.TRUE, "TEST" };
- Class[] types = { Boolean.TYPE, String.class };
+ Class<?>[] types = { Boolean.TYPE, String.class };
Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
assertNotNull(obj);
assertTrue(obj instanceof TestBean);
@@ -188,7 +188,7 @@ public class ConstructorUtilsTestCase ex
}
{
Object[] args = { Boolean.TRUE, "TEST" };
- Class[] types = { Boolean.class, String.class };
+ Class<?>[] types = { Boolean.class, String.class };
Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
assertNotNull(obj);
assertTrue(obj instanceof TestBean);
@@ -197,7 +197,7 @@ public class ConstructorUtilsTestCase ex
}
{
Object[] args = { new Float(17.3f), "TEST" };
- Class[] types = { Float.TYPE, String.class };
+ Class<?>[] types = { Float.TYPE, String.class };
Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
assertNotNull(obj);
assertTrue(obj instanceof TestBean);
@@ -206,7 +206,7 @@ public class ConstructorUtilsTestCase ex
}
{
Object[] args = { new Float(17.3f), "TEST" };
- Class[] types = { Float.class, String.class };
+ Class<?>[] types = { Float.class, String.class };
try {
ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
fail("Expected NoSuchMethodException");
@@ -218,54 +218,54 @@ public class ConstructorUtilsTestCase ex
public void testGetAccessibleConstructor() throws Exception {
{
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,String.class);
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,String.class);
assertNotNull(ctor);
assertTrue(Modifier.isPublic(ctor.getModifiers()));
}
{
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,Integer.class);
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,Integer.class);
assertNotNull(ctor);
assertTrue(Modifier.isPublic(ctor.getModifiers()));
}
{
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,Integer.TYPE);
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,Integer.TYPE);
assertNull(ctor);
}
}
public void testGetAccessibleConstructorWithTypeArray() throws Exception {
{
- Class[] types = { Boolean.TYPE, String.class };
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,types);
+ Class<?>[] types = { Boolean.TYPE, String.class };
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,types);
assertNotNull(ctor);
assertTrue(Modifier.isPublic(ctor.getModifiers()));
}
{
- Class[] types = { Boolean.TYPE, Boolean.TYPE, String.class };
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,types);
+ Class<?>[] types = { Boolean.TYPE, Boolean.TYPE, String.class };
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,types);
assertNull(ctor);
}
}
public void testGetAccessibleConstructorWithConstructorArg() throws Exception {
{
- Class[] types = { Integer.class };
- Constructor c1 = TestBean.class.getConstructor(types);
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(c1);
+ Class<?>[] types = { Integer.class };
+ Constructor<?> c1 = TestBean.class.getConstructor(types);
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(c1);
assertNotNull(ctor);
assertTrue(Modifier.isPublic(ctor.getModifiers()));
}
{
- Class[] types = { Integer.class };
- Constructor c1 = TestBean.class.getDeclaredConstructor(types);
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(c1);
+ Class<?>[] types = { Integer.class };
+ Constructor<?> c1 = TestBean.class.getDeclaredConstructor(types);
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(c1);
assertNotNull(ctor);
assertTrue(Modifier.isPublic(ctor.getModifiers()));
}
{
- Class[] types = { Integer.TYPE };
- Constructor c1 = TestBean.class.getDeclaredConstructor(types);
- Constructor ctor = ConstructorUtils.getAccessibleConstructor(c1);
+ Class<?>[] types = { Integer.TYPE };
+ Constructor<?> c1 = TestBean.class.getDeclaredConstructor(types);
+ Constructor<?> ctor = ConstructorUtils.getAccessibleConstructor(c1);
assertNull(ctor);
}
}
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConvertUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConvertUtilsTestCase.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConvertUtilsTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConvertUtilsTestCase.java Fri Nov 8 21:08:30 2013
@@ -24,11 +24,13 @@ import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
-import org.apache.commons.beanutils.converters.DateConverter;
-import junit.framework.TestCase;
+
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.commons.beanutils.converters.DateConverter;
+
/**
* <p>
@@ -614,6 +616,8 @@ public class ConvertUtilsTestCase extend
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ // We need to use raw types in order to test legacy converters
public void testConvertToString() throws Exception {
Converter dummyConverter = new Converter() {
public Object convert(Class type, Object value) {
@@ -658,6 +662,16 @@ public class ConvertUtilsTestCase extend
}
+ /**
+ * Tests a conversion to an unsupported target type.
+ */
+ public void testConvertUnsupportedTargetType() {
+ ConvertUtilsBean utils = new ConvertUtilsBean();
+ Object value = "A test value";
+ assertSame("Got different object", value,
+ utils.convert(value, getClass()));
+ }
+
// -------------------------------------------------------- Private Methods