commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1538226 - in /commons/proper/beanutils/branches/java5/src: main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java test/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java
Date Sat, 02 Nov 2013 17:10:15 GMT
Author: oheger
Date: Sat Nov  2 17:10:15 2013
New Revision: 1538226

URL: http://svn.apache.org/r1538226
Log:
Fixed a regression after the generification of converters.

If LocaleConverterUtilsBean cannot find a converter for the specified target
class, it uses the default string converter. This converter can now fail if
it does not support the target type.

Modified:
    commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java
    commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java

Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java?rev=1538226&r1=1538225&r2=1538226&view=diff
==============================================================================
--- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java
(original)
+++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java
Sat Nov  2 17:10:15 2013
@@ -272,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));
     }
 
     /**

Modified: commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java?rev=1538226&r1=1538225&r2=1538226&view=diff
==============================================================================
--- commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java
(original)
+++ commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java
Sat Nov  2 17:10:15 2013
@@ -628,6 +628,17 @@ public class LocaleConvertUtilsTestCase 
         assertEquals("Integer Array Value", new Integer(123), ((Integer[])result)[0]);
     }
 
+    /**
+     * Tests a conversion if there is no suitable converter registered. In this
+     * case, the string converter is used, and the passed in target type is
+     * ignored. (This test is added to prevent a regression after the locale
+     * converters have been generified.)
+     */
+    public void testDefaultToStringConversionUnsupportedType() {
+        Integer value = 20131101;
+        assertEquals("Wrong result", value.toString(),
+                LocaleConvertUtils.convert(value.toString(), getClass()));
+    }
 
     // -------------------------------------------------------- Private Methods
 



Mime
View raw message