ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doo...@apache.org
Subject svn commit: r917623 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base: conversion/CollectionConverters.java util/test/ObjectTypeTests.java
Date Mon, 01 Mar 2010 18:12:35 GMT
Author: doogie
Date: Mon Mar  1 18:12:35 2010
New Revision: 917623

URL: http://svn.apache.org/viewvc?rev=917623&view=rev
Log:
BUG FIX: Actually implement proper simple array testing; the previously
added ArrayObjectToList converter was never actually used.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java?rev=917623&r1=917622&r2=917623&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java Mon
Mar  1 18:12:35 2010
@@ -27,7 +27,6 @@
 import javolution.util.FastList;
 import javolution.util.FastSet;
 
-import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilValidate;
@@ -40,7 +39,13 @@
         }
 
         public <S, T> Converter<S, T> createConverter(Class<S> sourceClass,
Class<T> targetClass) {
-            if (!sourceClass.isArray() || targetClass != List.class) {
+            if (!sourceClass.isArray()) {
+               return null;
+            }
+            if (targetClass != List.class) {
+               return null;
+            }
+            if (!(sourceClass.getComponentType() instanceof Object)) {
                 return null;
             }
             return UtilGenerics.cast(new ArrayClassToList<S, T>(sourceClass, targetClass));
@@ -52,6 +57,10 @@
             super(sourceClass, targetClass);
         }
 
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return sourceClass == this.getSourceClass() && targetClass == this.getTargetClass();
+        }
+
         public T convert(S obj) throws ConversionException {
             List<Object> list = FastList.newInstance();
             int len = Array.getLength(obj);
@@ -69,7 +78,16 @@
 
         @Override
         public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
-            return sourceClass.isArray() && ObjectType.instanceOf(targetClass, this.getTargetClass());
+            if (!sourceClass.isArray()) {
+                return false;
+            }
+            if (!List.class.isAssignableFrom(targetClass)) {
+                return false;
+            }
+            if (Object[].class.isAssignableFrom(sourceClass)) {
+                return true;
+            }
+            return false;
         }
 
         public List<T> convert(T[] obj) throws ConversionException {

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java?rev=917623&r1=917622&r2=917623&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java Mon Mar 
1 18:12:35 2010
@@ -192,7 +192,10 @@
     }
 
     public void testArray() throws GeneralException {
-        simpleTypeConvertTestSingleMulti("array->List", new Object[] {"one", "two", "three"},
new String[] {"List", "java.util.List"}, list);
+        simpleTypeConvertTestSingleMulti("Object[]->List", new Object[] {"one", "two",
"three"}, new String[] {"List", "java.util.List"}, list);
+        simpleTypeConvertTestSingleMulti("int[]->List", new int[] {1, 2, 3}, new String[]
{"List", "java.util.List"}, list(1, 2, 3));
+        simpleTypeConvertTestError("Object[]->error", new Object[] {"one", "two", "three"},
new String[] {"Map"});
+        simpleTypeConvertTestError("int[]->error", new int[] {1, 2, 3}, new String[] {"java.util.ArrayList",
"Map"});
     }
 
     public void testString() throws GeneralException, Exception {



Mime
View raw message