commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r555645 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/locale/converters/ test/org/apache/commons/beanutils/locale/converters/
Date Thu, 12 Jul 2007 14:40:38 GMT
Author: niallp
Date: Thu Jul 12 07:40:37 2007
New Revision: 555645

URL: http://svn.apache.org/viewvc?view=rev&rev=555645
Log:
BEANUTILS-288 Don't try parsing values that are already Dates/Numbers in Date/Number locale
Converters

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTestCase.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTestCase.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java?view=diff&rev=555645&r1=555644&r2=555645
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java
Thu Jul 12 07:40:37 2007
@@ -259,6 +259,16 @@
      */
     protected Object parse(Object value, String pattern) throws ParseException {
  
+        // Handle Date
+        if (value instanceof java.util.Date) {
+            return value;
+        }
+
+        // Handle Calendar
+        if (value instanceof java.util.Calendar) {
+            return ((java.util.Calendar)value).getTime();
+        }
+
          if (locPattern) {
              pattern = convertLocalizedPattern(pattern, locale);
          }

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.java?view=diff&rev=555645&r1=555644&r2=555645
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.java
Thu Jul 12 07:40:37 2007
@@ -225,6 +225,11 @@
      * cannot be performed successfully
      */
     protected Object parse(Object value, String pattern) throws ParseException {
+
+        if (value instanceof Number) {
+            return value;
+        }
+
         // Note that despite the ambiguous "getInstance" name, and despite the
         // fact that objects returned from this method have the same toString
         // representation, each call to getInstance actually returns a new

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTestCase.java?view=diff&rev=555645&r1=555644&r2=555645
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTestCase.java
Thu Jul 12 07:40:37 2007
@@ -430,5 +430,23 @@
 
     }
 
+    /**
+     * Test java.util.Date
+     */
+    public void testDateObject() {
+        converter = new DateLocaleConverter(defaultLocale);
+        assertEquals("java.util.Date", expectedValue, converter.convert(expectedValue));
+    }
+
+    /**
+     * Test Calendar
+     */
+    public void testCalendarObject() {
+        converter = new DateLocaleConverter(defaultLocale);
+        java.util.Calendar calendar = java.util.Calendar.getInstance();
+        calendar.setTime((java.util.Date)expectedValue);
+        assertEquals("java.util.Calendar", expectedValue, converter.convert(calendar));
+    }
+
 }
 

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTestCase.java?view=diff&rev=555645&r1=555644&r2=555645
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTestCase.java
Thu Jul 12 07:40:37 2007
@@ -258,6 +258,19 @@
     }
 
 
+    /**
+     * Test Converting a number
+     */
+    public void testNumber() {
+
+        // ------------- Construct using specified Locale --------
+        converter = new IntegerLocaleConverter(localizedLocale);
+
+        Integer value = new Integer(1234);
+        assertEquals("Convert Integer", value, converter.convert(value));
+        assertEquals("Convert Long",    value, converter.convert(new Long(value.intValue())));
+    }
+
 
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message