commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r907121 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/ClassUtils.java test/java/org/apache/commons/lang/ClassUtilsTest.java
Date Fri, 05 Feb 2010 22:53:22 GMT
Author: mbenson
Date: Fri Feb  5 22:53:21 2010
New Revision: 907121

URL: http://svn.apache.org/viewvc?rev=907121&view=rev
Log:
[LANG-587] merge from trunk

Modified:
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ClassUtilsTest.java

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java?rev=907121&r1=907120&r2=907121&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
Fri Feb  5 22:53:21 2010
@@ -886,7 +886,8 @@
     }
 
     /**
-     * <p>Converts an array of <code>Object</code> in to an array of <code>Class</code>
objects.</p>
+     * <p>Converts an array of <code>Object</code> in to an array of <code>Class</code>
objects.
+     * If any of these objects is null, a null element will be inserted into the array.</p>
      *
      * <p>This method returns <code>null</code> for a <code>null</code>
input array.</p>
      *
@@ -902,7 +903,7 @@
         }
         Class[] classes = new Class[array.length];
         for (int i = 0; i < array.length; i++) {
-            classes[i] = array[i].getClass();
+            classes[i] = array[i] == null ? null : array[i].getClass();
         }
         return classes;
     }

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ClassUtilsTest.java?rev=907121&r1=907120&r2=907121&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ClassUtilsTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ClassUtilsTest.java
Fri Feb  5 22:53:21 2010
@@ -20,6 +20,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -715,21 +716,15 @@
     }
  
     public void testToClass_object() {
-        assertEquals(null, ClassUtils.toClass(null));
+        assertNull(ClassUtils.toClass(null));
 
-        assertSame(
-            ArrayUtils.EMPTY_CLASS_ARRAY,
-            ClassUtils.toClass(new Class[0]));
-
-        Object[] array = new Object[3];
-        array[0] = new String("Test");
-        array[1] = new Integer(1);
-        array[2] = new Double(99);
-
-        Class[] results = ClassUtils.toClass(array);
-        assertEquals("String", ClassUtils.getShortClassName(results[0]));
-        assertEquals("Integer", ClassUtils.getShortClassName(results[1]));
-        assertEquals("Double", ClassUtils.getShortClassName(results[2]));
+        assertSame(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass(ArrayUtils.EMPTY_OBJECT_ARRAY));
+
+        assertTrue(Arrays.equals(new Class[] { String.class, Integer.class, Double.class
},
+                ClassUtils.toClass(new Object[] { "Test", new Integer(1), new Double(99d)
})));
+
+        assertTrue(Arrays.equals(new Class[] { String.class, null, Double.class },
+                ClassUtils.toClass(new Object[] { "Test", null, new Double(99d) })));
     }
 
     public void test_getShortCanonicalName_Object() {



Mime
View raw message