From 184c0b4d2ebc90224deb6daaad9f41e592dc97ba Mon Sep 17 00:00:00 2001
From: Stephen Colebourne
Date: Sun, 15 Dec 2002 19:36:08 +0000
Subject: [PATCH] Test the ClassUtils class
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137187 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/commons/lang/ClassUtils.java | 148 +++----
.../apache/commons/lang/ClassUtilsTest.java | 388 ++++++++++++++++++
.../apache/commons/lang/LangTestSuite.java | 3 +-
3 files changed, 465 insertions(+), 74 deletions(-)
create mode 100644 src/test/org/apache/commons/lang/ClassUtilsTest.java
diff --git a/src/java/org/apache/commons/lang/ClassUtils.java b/src/java/org/apache/commons/lang/ClassUtils.java
index 12c1835ec..616cfff93 100644
--- a/src/java/org/apache/commons/lang/ClassUtils.java
+++ b/src/java/org/apache/commons/lang/ClassUtils.java
@@ -61,7 +61,7 @@ import java.util.List;
* classes without using reflection.
*
* @author Stephen Colebourne
- * @version $Id: ClassUtils.java,v 1.5 2002/11/16 10:41:03 scolebourne Exp $
+ * @version $Id: ClassUtils.java,v 1.6 2002/12/15 19:36:08 scolebourne Exp $
*/
public class ClassUtils {
@@ -79,8 +79,21 @@ public class ClassUtils {
// -------------------------------------------------------------------------
/**
- * Gets the class name minus the package name from a
- * Class
.
+ * Gets the class name minus the package name for an Object
.
+ *
+ * @param object the class to get the short name for
+ * @param valueIfNull the value to return if null
+ * @return the class name of the object without the package name, or the null value
+ */
+ public static String getShortClassName(Object object, String valueIfNull) {
+ if (object == null) {
+ return valueIfNull;
+ }
+ return getShortClassName(object.getClass().getName());
+ }
+
+ /**
+ * Gets the class name minus the package name from a Class
.
*
* @param cls the class to get the short name for, must not be
* null
@@ -94,22 +107,6 @@ public class ClassUtils {
return getShortClassName(cls.getName());
}
- /**
- * Gets the class name minus the package name for an
- * Object
.
- *
- * @param object the class to get the short name for, must not be
- * null
- * @return the class name of the object without the package name
- * @throws IllegalArgumentException if the object is null
- */
- public static String getShortClassName(Object object) {
- if (object == null) {
- throw new IllegalArgumentException("The object must not be null");
- }
- return getShortClassName(object.getClass().getName());
- }
-
/**
* Gets the class name minus the package name from a String.
*
@@ -137,6 +134,20 @@ public class ClassUtils {
// -------------------------------------------------------------------------
+ /**
+ * Gets the package name of an Object
.
+ *
+ * @param object the class to get the package name for
+ * @param valueIfNull the value to return if null
+ * @return the package name of the object, or the null value
+ */
+ public static String getPackageName(Object object, String valueIfNull) {
+ if (object == null) {
+ return valueIfNull;
+ }
+ return getPackageName(object.getClass().getName());
+ }
+
/**
* Gets the package name of a Class
.
*
@@ -152,21 +163,6 @@ public class ClassUtils {
return getPackageName(cls.getName());
}
- /**
- * Gets the package name of an Object
.
- *
- * @param object the class to get the package name for, must not be
- * null
- * @return the package name
- * @throws IllegalArgumentException if the object is null
- */
- public static String getPackageName(Object object) {
- if (object == null) {
- throw new IllegalArgumentException("The object must not be null");
- }
- return getPackageName(object.getClass().getName());
- }
-
/**
* Gets the package name from a String
.
*
@@ -211,11 +207,12 @@ public class ClassUtils {
/**
* Gets a List
of all interfaces implemented by the given
- * class.
+ * class and its superclasses.
*
* The order is determined by looking through each interface in turn as
- * declared in the source file and following its hieracrchy up. Later
- * duplicates are ignored, so the order is maintained.
+ * declared in the source file and following its hieracrchy up. Then each
+ * superclass is considered in the same way. Later duplicates are ignored,
+ * so the order is maintained.
*
* @param cls the class to look up, must not be null
* @return the List
of interfaces in order
@@ -226,18 +223,21 @@ public class ClassUtils {
throw new IllegalArgumentException("The class must not be null");
}
List list = new ArrayList();
- Class[] interfaces = cls.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- if (list.contains(interfaces[i]) == false) {
- list.add(interfaces[i]);
- }
- List superInterfaces = getAllInterfaces(interfaces[i]);
- for (Iterator it = superInterfaces.iterator(); it.hasNext();) {
- Class intface = (Class) it.next();
- if (list.contains(intface) == false) {
- list.add(intface);
+ while (cls != null) {
+ Class[] interfaces = cls.getInterfaces();
+ for (int i = 0; i < interfaces.length; i++) {
+ if (list.contains(interfaces[i]) == false) {
+ list.add(interfaces[i]);
+ }
+ List superInterfaces = getAllInterfaces(interfaces[i]);
+ for (Iterator it = superInterfaces.iterator(); it.hasNext();) {
+ Class intface = (Class) it.next();
+ if (list.contains(intface) == false) {
+ list.add(intface);
+ }
}
}
+ cls = cls.getSuperclass();
}
return list;
}
@@ -295,17 +295,18 @@ public class ClassUtils {
// return null;
// }
+ // -------------------------------------------------------------------------
+
/**
* Given a List
of class names, this method converts them into classes. *
* A new List
is returned. If the class name cannot be found, null
* is stored in the List
. If the class name in the List
is
* null
, null
is stored in the output List
.
*
- * @param classNames the classNames to change, the class is stored back
- * into the List
. null
will be stored in the List
- * if no class is found.
- * @return the List
of Class objects corresponding to the class names
+ * @param classNames the classNames to change
+ * @return a List
of Class objects corresponding to the class names
* @throws IllegalArgumentException if the classNames is null
+ * @throws ClassCastException if classNames contains a non String entry
*/
public static List convertClassNamesToClasses(List classNames) {
if (classNames == null) {
@@ -324,40 +325,41 @@ public class ClassUtils {
}
/**
- * Given a List
of classes, this method finds all those which
- * are subclasses or implementations of a specified superclass.
+ * Given a List
of Class
objects, this method converts
+ * them into class names.
+ * A new List
is returned. null
objects will be copied into
+ * the returned list as null
.
*
- * @param classes the classes to check
- * @param superclass the superclass to check for
- * @return the list of subclasses or implementations
- * @throws IllegalArgumentException if the classes or superClass is null
+ * @param classes the classes to change
+ * @return a List
of Class objects corresponding to the class names
+ * @throws IllegalArgumentException if the classNames is null
+ * @throws ClassCastException if classNames contains a non Class or null entry
*/
- public static List getAssignableFrom(List classes, Class superclass) {
+ public static List convertClassesToClassNames(List classes) {
if (classes == null) {
- throw new IllegalArgumentException("The classes must not be null");
+ throw new IllegalArgumentException("The classes list must not be null");
}
- if (superclass == null) {
- throw new IllegalArgumentException("The superclass must not be null");
- }
- List subs = new ArrayList();
- Iterator it = classes.iterator();
- while (it.hasNext()) {
+ List classNames = new ArrayList(classes.size());
+ for (Iterator it = classes.iterator(); it.hasNext();) {
Class cls = (Class) it.next();
if (cls == null) {
- throw new IllegalArgumentException("The class list must not contain nulls");
- }
- if (isAssignable(cls, superclass)) {
- subs.add(cls);
+ classNames.add(null);
+ } else {
+ classNames.add(cls.getName());
}
}
- return subs;
+ return classNames;
}
-
+
+ // -------------------------------------------------------------------------
+
/**
* Checks if an array of Classes can be assigned to another array of Classes.
*
- * This can be used to check if parameter types are suitably compatable for
- * reflection invocation.
+ * This method calls {@link #isAssignable(Class, Class) isAssignable} for each
+ * Class pair in the input arrays. It can be used to check if a set of arguments
+ * (the first parameter) are suitably compatable with a set of method parameter types
+ * (the second parameter).
*
* Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, this
* method takes into account widenings of primitive classes and
diff --git a/src/test/org/apache/commons/lang/ClassUtilsTest.java b/src/test/org/apache/commons/lang/ClassUtilsTest.java
new file mode 100644
index 000000000..051577f97
--- /dev/null
+++ b/src/test/org/apache/commons/lang/ClassUtilsTest.java
@@ -0,0 +1,388 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+package org.apache.commons.lang;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+/**
+ * Unit tests {@link org.apache.commons.lang.ClassUtils}.
+ *
+ * @author Stephen Colebourne
+ * @version $Id: ClassUtilsTest.java,v 1.1 2002/12/15 19:36:08 scolebourne Exp $
+ */
+public class ClassUtilsTest extends TestCase {
+
+ public ClassUtilsTest(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ClassUtilsTest.class);
+ suite.setName("ClassUtils Tests");
+ return suite;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private static class Inner {
+ }
+
+ // -------------------------------------------------------------------------
+ public void test_getShortClassName_Object() {
+ assertEquals("ClassUtils", ClassUtils.getShortClassName(new ClassUtils(), ""));
+ assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(new Inner(), ""));
+ assertEquals("String", ClassUtils.getShortClassName("hello", ""));
+ assertEquals("", ClassUtils.getShortClassName(null, ""));
+ }
+
+ public void test_getShortClassName_Class() {
+ assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class));
+ assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class));
+ try {
+ ClassUtils.getShortClassName((Class) null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ public void test_getShortClassName_String() {
+ assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class.getName()));
+ assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class.getName()));
+ try {
+ ClassUtils.getShortClassName((String) null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ try {
+ ClassUtils.getShortClassName("");
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ // -------------------------------------------------------------------------
+ public void test_getPackageName_Object() {
+ assertEquals("org.apache.commons.lang", ClassUtils.getPackageName(new ClassUtils(), ""));
+ assertEquals("org.apache.commons.lang", ClassUtils.getPackageName(new Inner(), ""));
+ assertEquals("", ClassUtils.getPackageName(null, ""));
+ }
+
+ public void test_getPackageName_Class() {
+ assertEquals("java.lang", ClassUtils.getPackageName(String.class));
+ assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class));
+ try {
+ ClassUtils.getPackageName((Class) null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ public void test_getPackageName_String() {
+ assertEquals("org.apache.commons.lang", ClassUtils.getPackageName(ClassUtils.class.getName()));
+ assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class.getName()));
+ try {
+ ClassUtils.getPackageName((String) null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ try {
+ ClassUtils.getPackageName("");
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ // -------------------------------------------------------------------------
+ public void test_getAllSuperclasses_Class() {
+ List list = ClassUtils.getAllSuperclasses(CY.class);
+ assertEquals(2, list.size());
+ assertEquals(CX.class, list.get(0));
+ assertEquals(Object.class, list.get(1));
+ try {
+ ClassUtils.getAllSuperclasses(null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ public void test_getAllInterfaces_Class() {
+ List list = ClassUtils.getAllInterfaces(CY.class);
+ assertEquals(6, list.size());
+ assertEquals(IB.class, list.get(0));
+ assertEquals(IC.class, list.get(1));
+ assertEquals(ID.class, list.get(2));
+ assertEquals(IE.class, list.get(3));
+ assertEquals(IF.class, list.get(4));
+ assertEquals(IA.class, list.get(5));
+ try {
+ ClassUtils.getAllInterfaces(null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ private static interface IA {
+ }
+ private static interface IB {
+ }
+ private static interface IC extends ID, IE {
+ }
+ private static interface ID {
+ }
+ private static interface IE extends IF {
+ }
+ private static interface IF {
+ }
+ private static class CX implements IB, IA, IE {
+ }
+ private static class CY extends CX implements IB, IC {
+ }
+
+ // -------------------------------------------------------------------------
+ public void test_convertClassNamesToClasses_List() {
+ List list = new ArrayList();
+ List result = ClassUtils.convertClassNamesToClasses(list);
+ assertEquals(0, result.size());
+
+ list.add("java.lang.String");
+ list.add("java.lang.xxx");
+ list.add("java.lang.Object");
+ result = ClassUtils.convertClassNamesToClasses(list);
+ assertEquals(3, result.size());
+ assertEquals(String.class, result.get(0));
+ assertEquals(null, result.get(1));
+ assertEquals(Object.class, result.get(2));
+
+ list.add(new Object());
+ try {
+ ClassUtils.convertClassNamesToClasses(list);
+ fail();
+ } catch (ClassCastException ex) {}
+
+ try {
+ ClassUtils.convertClassNamesToClasses(null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ public void test_convertClassesToClassNames_List() {
+ List list = new ArrayList();
+ List result = ClassUtils.convertClassesToClassNames(list);
+ assertEquals(0, result.size());
+
+ list.add(String.class);
+ list.add(Object.class);
+ result = ClassUtils.convertClassesToClassNames(list);
+ assertEquals(2, result.size());
+ assertEquals("java.lang.String", result.get(0));
+ assertEquals("java.lang.Object", result.get(1));
+
+ list.add(new Object());
+ try {
+ ClassUtils.convertClassesToClassNames(list);
+ fail();
+ } catch (ClassCastException ex) {}
+
+ try {
+ ClassUtils.convertClassesToClassNames(null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ // -------------------------------------------------------------------------
+ public void test_isInnerClass_Class() {
+ assertEquals(true, ClassUtils.isInnerClass(Inner.class));
+ assertEquals(true, ClassUtils.isInnerClass(Map.Entry.class));
+ assertEquals(false, ClassUtils.isInnerClass(this.getClass()));
+ assertEquals(false, ClassUtils.isInnerClass(String.class));
+ try {
+ ClassUtils.isInnerClass(null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ }
+
+ // -------------------------------------------------------------------------
+ public void test_isAssignable_ClassArray_ClassArray() throws Exception {
+ Class[] array2 = new Class[] {Object.class, Object.class};
+ Class[] array1 = new Class[] {Object.class};
+ Class[] array1s = new Class[] {String.class};
+ Class[] array0 = new Class[] {};
+
+ assertEquals(false, ClassUtils.isAssignable(array1, array2));
+ assertEquals(false, ClassUtils.isAssignable(null, array2));
+ assertEquals(true, ClassUtils.isAssignable(null, array0));
+ assertEquals(true, ClassUtils.isAssignable(array0, array0));
+ assertEquals(true, ClassUtils.isAssignable(array0, null));
+ assertEquals(true, ClassUtils.isAssignable((Class[]) null, (Class[]) null));
+
+ assertEquals(false, ClassUtils.isAssignable(array1, array1s));
+ assertEquals(true, ClassUtils.isAssignable(array1s, array1s));
+ assertEquals(true, ClassUtils.isAssignable(array1s, array1));
+ }
+
+ public void test_isAssignable() throws Exception {
+ try {
+ ClassUtils.isAssignable(String.class, null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ try {
+ ClassUtils.isAssignable((Class) null, (Class) null);
+ fail();
+ } catch (IllegalArgumentException ex) {}
+ assertEquals(true, ClassUtils.isAssignable(null, Object.class));
+ assertEquals(true, ClassUtils.isAssignable(null, Integer.class));
+ assertEquals(false, ClassUtils.isAssignable(null, Integer.TYPE));
+ assertEquals(true, ClassUtils.isAssignable(String.class, Object.class));
+ assertEquals(true, ClassUtils.isAssignable(String.class, String.class));
+ assertEquals(false, ClassUtils.isAssignable(Object.class, String.class));
+ assertEquals(false, ClassUtils.isAssignable(Integer.TYPE, Integer.class));
+ assertEquals(false, ClassUtils.isAssignable(Integer.class, Integer.TYPE));
+ assertEquals(true, ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE));
+ assertEquals(true, ClassUtils.isAssignable(Integer.class, Integer.class));
+ }
+
+ public void test_isAssignable_Widening() throws Exception {
+ // test byte conversions
+ assertEquals("byte -> char", false, ClassUtils.isAssignable(Byte.TYPE, Character.TYPE));
+ assertEquals("byte -> byte", true, ClassUtils.isAssignable(Byte.TYPE, Byte.TYPE));
+ assertEquals("byte -> short", true, ClassUtils.isAssignable(Byte.TYPE, Short.TYPE));
+ assertEquals("byte -> int", true, ClassUtils.isAssignable(Byte.TYPE, Integer.TYPE));
+ assertEquals("byte -> long", true, ClassUtils.isAssignable(Byte.TYPE, Long.TYPE));
+ assertEquals("byte -> float", true, ClassUtils.isAssignable(Byte.TYPE, Float.TYPE));
+ assertEquals("byte -> double", true, ClassUtils.isAssignable(Byte.TYPE, Double.TYPE));
+ assertEquals("byte -> boolean", false, ClassUtils.isAssignable(Byte.TYPE, Boolean.TYPE));
+
+ // test short conversions
+ assertEquals("short -> char", false, ClassUtils.isAssignable(Short.TYPE, Character.TYPE));
+ assertEquals("short -> byte", false, ClassUtils.isAssignable(Short.TYPE, Byte.TYPE));
+ assertEquals("short -> short", true, ClassUtils.isAssignable(Short.TYPE, Short.TYPE));
+ assertEquals("short -> int", true, ClassUtils.isAssignable(Short.TYPE, Integer.TYPE));
+ assertEquals("short -> long", true, ClassUtils.isAssignable(Short.TYPE, Long.TYPE));
+ assertEquals("short -> float", true, ClassUtils.isAssignable(Short.TYPE, Float.TYPE));
+ assertEquals("short -> double", true, ClassUtils.isAssignable(Short.TYPE, Double.TYPE));
+ assertEquals("short -> boolean", false, ClassUtils.isAssignable(Short.TYPE, Boolean.TYPE));
+
+ // test char conversions
+ assertEquals("char -> char", true, ClassUtils.isAssignable(Character.TYPE, Character.TYPE));
+ assertEquals("char -> byte", false, ClassUtils.isAssignable(Character.TYPE, Byte.TYPE));
+ assertEquals("char -> short", false, ClassUtils.isAssignable(Character.TYPE, Short.TYPE));
+ assertEquals("char -> int", true, ClassUtils.isAssignable(Character.TYPE, Integer.TYPE));
+ assertEquals("char -> long", true, ClassUtils.isAssignable(Character.TYPE, Long.TYPE));
+ assertEquals("char -> float", true, ClassUtils.isAssignable(Character.TYPE, Float.TYPE));
+ assertEquals("char -> double", true, ClassUtils.isAssignable(Character.TYPE, Double.TYPE));
+ assertEquals("char -> boolean", false, ClassUtils.isAssignable(Character.TYPE, Boolean.TYPE));
+
+ // test int conversions
+ assertEquals("int -> char", false, ClassUtils.isAssignable(Integer.TYPE, Character.TYPE));
+ assertEquals("int -> byte", false, ClassUtils.isAssignable(Integer.TYPE, Byte.TYPE));
+ assertEquals("int -> short", false, ClassUtils.isAssignable(Integer.TYPE, Short.TYPE));
+ assertEquals("int -> int", true, ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE));
+ assertEquals("int -> long", true, ClassUtils.isAssignable(Integer.TYPE, Long.TYPE));
+ assertEquals("int -> float", true, ClassUtils.isAssignable(Integer.TYPE, Float.TYPE));
+ assertEquals("int -> double", true, ClassUtils.isAssignable(Integer.TYPE, Double.TYPE));
+ assertEquals("int -> boolean", false, ClassUtils.isAssignable(Integer.TYPE, Boolean.TYPE));
+
+ // test long conversions
+ assertEquals("long -> char", false, ClassUtils.isAssignable(Long.TYPE, Character.TYPE));
+ assertEquals("long -> byte", false, ClassUtils.isAssignable(Long.TYPE, Byte.TYPE));
+ assertEquals("long -> short", false, ClassUtils.isAssignable(Long.TYPE, Short.TYPE));
+ assertEquals("long -> int", false, ClassUtils.isAssignable(Long.TYPE, Integer.TYPE));
+ assertEquals("long -> long", true, ClassUtils.isAssignable(Long.TYPE, Long.TYPE));
+ assertEquals("long -> float", true, ClassUtils.isAssignable(Long.TYPE, Float.TYPE));
+ assertEquals("long -> double", true, ClassUtils.isAssignable(Long.TYPE, Double.TYPE));
+ assertEquals("long -> boolean", false, ClassUtils.isAssignable(Long.TYPE, Boolean.TYPE));
+
+ // test float conversions
+ assertEquals("float -> char", false, ClassUtils.isAssignable(Float.TYPE, Character.TYPE));
+ assertEquals("float -> byte", false, ClassUtils.isAssignable(Float.TYPE, Byte.TYPE));
+ assertEquals("float -> short", false, ClassUtils.isAssignable(Float.TYPE, Short.TYPE));
+ assertEquals("float -> int", false, ClassUtils.isAssignable(Float.TYPE, Integer.TYPE));
+ assertEquals("float -> long", false, ClassUtils.isAssignable(Float.TYPE, Long.TYPE));
+ assertEquals("float -> float", true, ClassUtils.isAssignable(Float.TYPE, Float.TYPE));
+ assertEquals("float -> double", true, ClassUtils.isAssignable(Float.TYPE, Double.TYPE));
+ assertEquals("float -> boolean", false, ClassUtils.isAssignable(Float.TYPE, Boolean.TYPE));
+
+ // test float conversions
+ assertEquals("double -> char", false, ClassUtils.isAssignable(Double.TYPE, Character.TYPE));
+ assertEquals("double -> byte", false, ClassUtils.isAssignable(Double.TYPE, Byte.TYPE));
+ assertEquals("double -> short", false, ClassUtils.isAssignable(Double.TYPE, Short.TYPE));
+ assertEquals("double -> int", false, ClassUtils.isAssignable(Double.TYPE, Integer.TYPE));
+ assertEquals("double -> long", false, ClassUtils.isAssignable(Double.TYPE, Long.TYPE));
+ assertEquals("double -> float", false, ClassUtils.isAssignable(Double.TYPE, Float.TYPE));
+ assertEquals("double -> double", true, ClassUtils.isAssignable(Double.TYPE, Double.TYPE));
+ assertEquals("double -> boolean", false, ClassUtils.isAssignable(Double.TYPE, Boolean.TYPE));
+
+ // test float conversions
+ assertEquals("boolean -> char", false, ClassUtils.isAssignable(Boolean.TYPE, Character.TYPE));
+ assertEquals("boolean -> byte", false, ClassUtils.isAssignable(Boolean.TYPE, Byte.TYPE));
+ assertEquals("boolean -> short", false, ClassUtils.isAssignable(Boolean.TYPE, Short.TYPE));
+ assertEquals("boolean -> int", false, ClassUtils.isAssignable(Boolean.TYPE, Integer.TYPE));
+ assertEquals("boolean -> long", false, ClassUtils.isAssignable(Boolean.TYPE, Long.TYPE));
+ assertEquals("boolean -> float", false, ClassUtils.isAssignable(Boolean.TYPE, Float.TYPE));
+ assertEquals("boolean -> double", false, ClassUtils.isAssignable(Boolean.TYPE, Double.TYPE));
+ assertEquals("boolean -> boolean", true, ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE));
+ }
+
+// public static List getAssignableFrom(List classes, Class superclass) {
+// public static boolean isAssignable(Class[] classArray, Class[] toClassArray) {
+// public static boolean isAssignable(Class cls, Class toClass) {
+}
diff --git a/src/test/org/apache/commons/lang/LangTestSuite.java b/src/test/org/apache/commons/lang/LangTestSuite.java
index e9c428041..da4a8a7a4 100644
--- a/src/test/org/apache/commons/lang/LangTestSuite.java
+++ b/src/test/org/apache/commons/lang/LangTestSuite.java
@@ -62,7 +62,7 @@ import junit.textui.TestRunner;
*
* @author Stephen Colebourne
* @author Ringo De Smet
- * @version $Id: LangTestSuite.java,v 1.7 2002/12/15 16:55:32 scolebourne Exp $
+ * @version $Id: LangTestSuite.java,v 1.8 2002/12/15 19:36:08 scolebourne Exp $
*/
public class LangTestSuite extends TestCase {
@@ -89,6 +89,7 @@ public class LangTestSuite extends TestCase {
suite.addTest(ArrayUtilsTest.suite());
suite.addTest(BooleanUtilsTest.suite());
suite.addTest(CharSetUtilsTest.suite());
+ suite.addTest(ClassUtilsTest.suite());
suite.addTest(NumberRangeTest.suite());
suite.addTest(NumberUtilsTest.suite());
suite.addTest(ObjectUtilsTest.suite());