View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.lang3;
18  
19  import static org.apache.commons.lang3.JavaVersion.JAVA_1_5;
20  import static org.junit.Assert.assertArrayEquals;
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertNotSame;
25  import static org.junit.Assert.assertNull;
26  import static org.junit.Assert.assertSame;
27  import static org.junit.Assert.assertTrue;
28  import static org.junit.Assert.fail;
29  
30  import java.lang.reflect.Constructor;
31  import java.lang.reflect.Method;
32  import java.lang.reflect.Modifier;
33  import java.util.ArrayList;
34  import java.util.Arrays;
35  import java.util.Collections;
36  import java.util.HashSet;
37  import java.util.Iterator;
38  import java.util.List;
39  import java.util.Map;
40  import java.util.Set;
41  
42  import org.apache.commons.lang3.ClassUtils.Interfaces;
43  import org.apache.commons.lang3.reflect.testbed.GenericConsumer;
44  import org.apache.commons.lang3.reflect.testbed.GenericParent;
45  import org.apache.commons.lang3.reflect.testbed.StringParameterizedChild;
46  import org.junit.Test;
47  
48  /**
49   * Unit tests {@link org.apache.commons.lang3.ClassUtils}.
50   *
51   * @version $Id: ClassUtilsTest.java 1510298 2013-08-04 18:36:17Z mbenson $
52   */
53  @SuppressWarnings("boxing") // JUnit4 does not support primitive equality testing apart from long
54  public class ClassUtilsTest  {
55  
56      private static class Inner {
57          private class DeeplyNested{}
58      }
59  
60      //-----------------------------------------------------------------------
61      @Test
62      public void testConstructor() {
63          assertNotNull(new ClassUtils());
64          final Constructor<?>[] cons = ClassUtils.class.getDeclaredConstructors();
65          assertEquals(1, cons.length);
66          assertTrue(Modifier.isPublic(cons[0].getModifiers()));
67          assertTrue(Modifier.isPublic(ClassUtils.class.getModifiers()));
68          assertFalse(Modifier.isFinal(ClassUtils.class.getModifiers()));
69      }
70  
71      // -------------------------------------------------------------------------
72      @Test
73      public void test_getShortClassName_Object() {
74          assertEquals("ClassUtils", ClassUtils.getShortClassName(new ClassUtils(), "<null>"));
75          assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(new Inner(), "<null>"));
76          assertEquals("String", ClassUtils.getShortClassName("hello", "<null>"));
77          assertEquals("<null>", ClassUtils.getShortClassName(null, "<null>"));
78  
79          // Inner types
80          class Named extends Object {}
81          assertEquals("ClassUtilsTest.1", ClassUtils.getShortClassName(new Object(){}, "<null>"));
82          assertEquals("ClassUtilsTest.1Named", ClassUtils.getShortClassName(new Named(), "<null>"));
83          assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(new Inner(), "<null>"));
84      }
85  
86      @Test
87      public void test_getShortClassName_Class() {
88          assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class));
89          assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class));
90          assertEquals("", ClassUtils.getShortClassName((Class<?>) null));
91  
92          // LANG-535
93          assertEquals("String[]", ClassUtils.getShortClassName(String[].class));
94          assertEquals("Map.Entry[]", ClassUtils.getShortClassName(Map.Entry[].class));
95  
96          // Primitives
97          assertEquals("boolean", ClassUtils.getShortClassName(boolean.class));
98          assertEquals("byte", ClassUtils.getShortClassName(byte.class));
99          assertEquals("char", ClassUtils.getShortClassName(char.class));
100         assertEquals("short", ClassUtils.getShortClassName(short.class));
101         assertEquals("int", ClassUtils.getShortClassName(int.class));
102         assertEquals("long", ClassUtils.getShortClassName(long.class));
103         assertEquals("float", ClassUtils.getShortClassName(float.class));
104         assertEquals("double", ClassUtils.getShortClassName(double.class));
105 
106         // Primitive Arrays
107         assertEquals("boolean[]", ClassUtils.getShortClassName(boolean[].class));
108         assertEquals("byte[]", ClassUtils.getShortClassName(byte[].class));
109         assertEquals("char[]", ClassUtils.getShortClassName(char[].class));
110         assertEquals("short[]", ClassUtils.getShortClassName(short[].class));
111         assertEquals("int[]", ClassUtils.getShortClassName(int[].class));
112         assertEquals("long[]", ClassUtils.getShortClassName(long[].class));
113         assertEquals("float[]", ClassUtils.getShortClassName(float[].class));
114         assertEquals("double[]", ClassUtils.getShortClassName(double[].class));
115 
116         // Arrays of arrays of ...
117         assertEquals("String[][]", ClassUtils.getShortClassName(String[][].class));
118         assertEquals("String[][][]", ClassUtils.getShortClassName(String[][][].class));
119         assertEquals("String[][][][]", ClassUtils.getShortClassName(String[][][][].class));
120         
121         // Inner types
122         class Named extends Object {}
123         assertEquals("ClassUtilsTest.2", ClassUtils.getShortClassName(new Object(){}.getClass()));
124         assertEquals("ClassUtilsTest.2Named", ClassUtils.getShortClassName(Named.class));
125         assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortClassName(Inner.class));
126     }
127 
128 
129 
130     @Test
131     public void test_getShortClassName_String() {
132         assertEquals("ClassUtils", ClassUtils.getShortClassName(ClassUtils.class.getName()));
133         assertEquals("Map.Entry", ClassUtils.getShortClassName(Map.Entry.class.getName()));
134         assertEquals("", ClassUtils.getShortClassName((String) null));
135         assertEquals("", ClassUtils.getShortClassName(""));
136     }
137 
138     @Test
139     public void test_getSimpleName_Class() {
140         assertEquals("ClassUtils", ClassUtils.getSimpleName(ClassUtils.class));
141         assertEquals("Entry", ClassUtils.getSimpleName(Map.Entry.class));
142         assertEquals("", ClassUtils.getSimpleName((Class<?>) null));
143 
144         // LANG-535
145         assertEquals("String[]", ClassUtils.getSimpleName(String[].class));
146         assertEquals("Entry[]", ClassUtils.getSimpleName(Map.Entry[].class));
147 
148         // Primitives
149         assertEquals("boolean", ClassUtils.getSimpleName(boolean.class));
150         assertEquals("byte", ClassUtils.getSimpleName(byte.class));
151         assertEquals("char", ClassUtils.getSimpleName(char.class));
152         assertEquals("short", ClassUtils.getSimpleName(short.class));
153         assertEquals("int", ClassUtils.getSimpleName(int.class));
154         assertEquals("long", ClassUtils.getSimpleName(long.class));
155         assertEquals("float", ClassUtils.getSimpleName(float.class));
156         assertEquals("double", ClassUtils.getSimpleName(double.class));
157 
158         // Primitive Arrays
159         assertEquals("boolean[]", ClassUtils.getSimpleName(boolean[].class));
160         assertEquals("byte[]", ClassUtils.getSimpleName(byte[].class));
161         assertEquals("char[]", ClassUtils.getSimpleName(char[].class));
162         assertEquals("short[]", ClassUtils.getSimpleName(short[].class));
163         assertEquals("int[]", ClassUtils.getSimpleName(int[].class));
164         assertEquals("long[]", ClassUtils.getSimpleName(long[].class));
165         assertEquals("float[]", ClassUtils.getSimpleName(float[].class));
166         assertEquals("double[]", ClassUtils.getSimpleName(double[].class));
167 
168         // Arrays of arrays of ...
169         assertEquals("String[][]", ClassUtils.getSimpleName(String[][].class));
170         assertEquals("String[][][]", ClassUtils.getSimpleName(String[][][].class));
171         assertEquals("String[][][][]", ClassUtils.getSimpleName(String[][][][].class));
172         
173         // On-the-fly types
174         class Named extends Object {}
175         assertEquals("", ClassUtils.getSimpleName(new Object(){}.getClass()));
176         assertEquals("Named", ClassUtils.getSimpleName(Named.class));
177     }
178 
179     @Test
180     public void test_getSimpleName_Object() {
181         assertEquals("ClassUtils", ClassUtils.getSimpleName(new ClassUtils(), "<null>"));
182         assertEquals("Inner", ClassUtils.getSimpleName(new Inner(), "<null>"));
183         assertEquals("String", ClassUtils.getSimpleName("hello", "<null>"));
184         assertEquals("<null>", ClassUtils.getSimpleName(null, "<null>"));
185     }
186 
187     // -------------------------------------------------------------------------
188     @Test
189     public void test_getPackageName_Object() {
190         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(new ClassUtils(), "<null>"));
191         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(new Inner(), "<null>"));
192         assertEquals("<null>", ClassUtils.getPackageName(null, "<null>"));
193     }
194 
195     @Test
196     public void test_getPackageName_Class() {
197         assertEquals("java.lang", ClassUtils.getPackageName(String.class));
198         assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class));
199         assertEquals("", ClassUtils.getPackageName((Class<?>)null));
200 
201         // LANG-535
202         assertEquals("java.lang", ClassUtils.getPackageName(String[].class));
203 
204         // Primitive Arrays
205         assertEquals("", ClassUtils.getPackageName(boolean[].class));
206         assertEquals("", ClassUtils.getPackageName(byte[].class));
207         assertEquals("", ClassUtils.getPackageName(char[].class));
208         assertEquals("", ClassUtils.getPackageName(short[].class));
209         assertEquals("", ClassUtils.getPackageName(int[].class));
210         assertEquals("", ClassUtils.getPackageName(long[].class));
211         assertEquals("", ClassUtils.getPackageName(float[].class));
212         assertEquals("", ClassUtils.getPackageName(double[].class));
213 
214         // Arrays of arrays of ...
215         assertEquals("java.lang", ClassUtils.getPackageName(String[][].class));
216         assertEquals("java.lang", ClassUtils.getPackageName(String[][][].class));
217         assertEquals("java.lang", ClassUtils.getPackageName(String[][][][].class));
218         
219         // On-the-fly types
220         class Named extends Object {}
221         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(new Object(){}.getClass()));
222         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(Named.class));
223     }
224 
225     @Test
226     public void test_getPackageName_String() {
227         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageName(ClassUtils.class.getName()));
228         assertEquals("java.util", ClassUtils.getPackageName(Map.Entry.class.getName()));
229         assertEquals("", ClassUtils.getPackageName((String)null));
230         assertEquals("", ClassUtils.getPackageName(""));
231     }
232 
233     // -------------------------------------------------------------------------
234     @Test
235     public void test_getAllSuperclasses_Class() {
236         final List<?> list = ClassUtils.getAllSuperclasses(CY.class);
237         assertEquals(2, list.size());
238         assertEquals(CX.class, list.get(0));
239         assertEquals(Object.class, list.get(1));
240 
241         assertEquals(null, ClassUtils.getAllSuperclasses(null));
242     }
243 
244     @Test
245     public void test_getAllInterfaces_Class() {
246         final List<?> list = ClassUtils.getAllInterfaces(CY.class);
247         assertEquals(6, list.size());
248         assertEquals(IB.class, list.get(0));
249         assertEquals(IC.class, list.get(1));
250         assertEquals(ID.class, list.get(2));
251         assertEquals(IE.class, list.get(3));
252         assertEquals(IF.class, list.get(4));
253         assertEquals(IA.class, list.get(5));
254 
255         assertEquals(null, ClassUtils.getAllInterfaces(null));
256     }
257 
258     private static interface IA {
259     }
260     private static interface IB {
261     }
262     private static interface IC extends ID, IE {
263     }
264     private static interface ID {
265     }
266     private static interface IE extends IF {
267     }
268     private static interface IF {
269     }
270     private static class CX implements IB, IA, IE {
271     }
272     private static class CY extends CX implements IB, IC {
273     }
274 
275     // -------------------------------------------------------------------------
276     @Test
277     public void test_convertClassNamesToClasses_List() {
278         final List<String> list = new ArrayList<String>();
279         List<Class<?>> result = ClassUtils.convertClassNamesToClasses(list);
280         assertEquals(0, result.size());
281 
282         list.add("java.lang.String");
283         list.add("java.lang.xxx");
284         list.add("java.lang.Object");
285         result = ClassUtils.convertClassNamesToClasses(list);
286         assertEquals(3, result.size());
287         assertEquals(String.class, result.get(0));
288         assertEquals(null, result.get(1));
289         assertEquals(Object.class, result.get(2));
290 
291         @SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
292         final
293         List<Object> olist = (List<Object>)(List<?>)list;
294         olist.add(new Object());
295         try {
296             ClassUtils.convertClassNamesToClasses(list);
297             fail("Should not have been able to convert list");
298         } catch (final ClassCastException expected) {}
299         assertEquals(null, ClassUtils.convertClassNamesToClasses(null));
300     }
301 
302     @Test
303     public void test_convertClassesToClassNames_List() {
304         final List<Class<?>> list = new ArrayList<Class<?>>();
305         List<String> result = ClassUtils.convertClassesToClassNames(list);
306         assertEquals(0, result.size());
307 
308         list.add(String.class);
309         list.add(null);
310         list.add(Object.class);
311         result = ClassUtils.convertClassesToClassNames(list);
312         assertEquals(3, result.size());
313         assertEquals("java.lang.String", result.get(0));
314         assertEquals(null, result.get(1));
315         assertEquals("java.lang.Object", result.get(2));
316 
317         @SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
318         final
319         List<Object> olist = (List<Object>)(List<?>)list;
320         olist.add(new Object());
321         try {
322             ClassUtils.convertClassesToClassNames(list);
323             fail("Should not have been able to convert list");
324         } catch (final ClassCastException expected) {}
325         assertEquals(null, ClassUtils.convertClassesToClassNames(null));
326     }
327 
328     // -------------------------------------------------------------------------
329     @Test
330     public void test_isInnerClass_Class() {
331         assertTrue(ClassUtils.isInnerClass(Inner.class));
332         assertTrue(ClassUtils.isInnerClass(Map.Entry.class));
333         assertTrue(ClassUtils.isInnerClass(new Cloneable() {
334         }.getClass()));
335         assertFalse(ClassUtils.isInnerClass(this.getClass()));
336         assertFalse(ClassUtils.isInnerClass(String.class));
337         assertFalse(ClassUtils.isInnerClass(null));
338     }
339 
340     // -------------------------------------------------------------------------
341     @Test
342     public void test_isAssignable_ClassArray_ClassArray() throws Exception {
343         final Class<?>[] array2 = new Class[] {Object.class, Object.class};
344         final Class<?>[] array1 = new Class[] {Object.class};
345         final Class<?>[] array1s = new Class[] {String.class};
346         final Class<?>[] array0 = new Class[] {};
347         final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
348         final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
349 
350         assertFalse(ClassUtils.isAssignable(array1, array2));
351         assertFalse(ClassUtils.isAssignable(null, array2));
352         assertTrue(ClassUtils.isAssignable(null, array0));
353         assertTrue(ClassUtils.isAssignable(array0, array0));
354 //        assertTrue(ClassUtils.isAssignable(array0, null)); 
355         assertTrue(ClassUtils.isAssignable(array0, (Class<?>[]) null)); // explicit cast to avoid warning
356         assertTrue(ClassUtils.isAssignable((Class[]) null, (Class[]) null));
357 
358         assertFalse(ClassUtils.isAssignable(array1, array1s));
359         assertTrue(ClassUtils.isAssignable(array1s, array1s));
360         assertTrue(ClassUtils.isAssignable(array1s, array1));
361 
362         final boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
363 
364         assertEquals(autoboxing, ClassUtils.isAssignable(arrayPrimitives, arrayWrappers));
365         assertEquals(autoboxing, ClassUtils.isAssignable(arrayWrappers, arrayPrimitives));
366         assertFalse(ClassUtils.isAssignable(arrayPrimitives, array1));
367         assertFalse(ClassUtils.isAssignable(arrayWrappers, array1));
368         assertEquals(autoboxing, ClassUtils.isAssignable(arrayPrimitives, array2));
369         assertTrue(ClassUtils.isAssignable(arrayWrappers, array2));
370     }
371 
372     @Test
373     public void test_isAssignable_ClassArray_ClassArray_Autoboxing() throws Exception {
374         final Class<?>[] array2 = new Class[] {Object.class, Object.class};
375         final Class<?>[] array1 = new Class[] {Object.class};
376         final Class<?>[] array1s = new Class[] {String.class};
377         final Class<?>[] array0 = new Class[] {};
378         final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
379         final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
380 
381         assertFalse(ClassUtils.isAssignable(array1, array2, true));
382         assertFalse(ClassUtils.isAssignable(null, array2, true));
383         assertTrue(ClassUtils.isAssignable(null, array0, true));
384         assertTrue(ClassUtils.isAssignable(array0, array0, true));
385         assertTrue(ClassUtils.isAssignable(array0, null, true));
386         assertTrue(ClassUtils.isAssignable((Class[]) null, (Class[]) null, true));
387 
388         assertFalse(ClassUtils.isAssignable(array1, array1s, true));
389         assertTrue(ClassUtils.isAssignable(array1s, array1s, true));
390         assertTrue(ClassUtils.isAssignable(array1s, array1, true));
391 
392         assertTrue(ClassUtils.isAssignable(arrayPrimitives, arrayWrappers, true));
393         assertTrue(ClassUtils.isAssignable(arrayWrappers, arrayPrimitives, true));
394         assertFalse(ClassUtils.isAssignable(arrayPrimitives, array1, true));
395         assertFalse(ClassUtils.isAssignable(arrayWrappers, array1, true));
396         assertTrue(ClassUtils.isAssignable(arrayPrimitives, array2, true));
397         assertTrue(ClassUtils.isAssignable(arrayWrappers, array2, true));
398     }
399 
400     @Test
401     public void test_isAssignable_ClassArray_ClassArray_NoAutoboxing() throws Exception {
402         final Class<?>[] array2 = new Class[] {Object.class, Object.class};
403         final Class<?>[] array1 = new Class[] {Object.class};
404         final Class<?>[] array1s = new Class[] {String.class};
405         final Class<?>[] array0 = new Class[] {};
406         final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
407         final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
408 
409         assertFalse(ClassUtils.isAssignable(array1, array2, false));
410         assertFalse(ClassUtils.isAssignable(null, array2, false));
411         assertTrue(ClassUtils.isAssignable(null, array0, false));
412         assertTrue(ClassUtils.isAssignable(array0, array0, false));
413         assertTrue(ClassUtils.isAssignable(array0, null, false));
414         assertTrue(ClassUtils.isAssignable((Class[]) null, (Class[]) null, false));
415 
416         assertFalse(ClassUtils.isAssignable(array1, array1s, false));
417         assertTrue(ClassUtils.isAssignable(array1s, array1s, false));
418         assertTrue(ClassUtils.isAssignable(array1s, array1, false));
419 
420         assertFalse(ClassUtils.isAssignable(arrayPrimitives, arrayWrappers, false));
421         assertFalse(ClassUtils.isAssignable(arrayWrappers, arrayPrimitives, false));
422         assertFalse(ClassUtils.isAssignable(arrayPrimitives, array1, false));
423         assertFalse(ClassUtils.isAssignable(arrayWrappers, array1, false));
424         assertTrue(ClassUtils.isAssignable(arrayWrappers, array2, false));
425         assertFalse(ClassUtils.isAssignable(arrayPrimitives, array2, false));
426     }
427 
428     @Test
429     public void test_isAssignable() throws Exception {
430         assertFalse(ClassUtils.isAssignable((Class<?>) null, null));
431         assertFalse(ClassUtils.isAssignable(String.class, null));
432 
433         assertTrue(ClassUtils.isAssignable(null, Object.class));
434         assertTrue(ClassUtils.isAssignable(null, Integer.class));
435         assertFalse(ClassUtils.isAssignable(null, Integer.TYPE));
436         assertTrue(ClassUtils.isAssignable(String.class, Object.class));
437         assertTrue(ClassUtils.isAssignable(String.class, String.class));
438         assertFalse(ClassUtils.isAssignable(Object.class, String.class));
439 
440         final boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
441 
442         assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, Integer.class));
443         assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, Object.class));
444         assertEquals(autoboxing, ClassUtils.isAssignable(Integer.class, Integer.TYPE));
445         assertEquals(autoboxing, ClassUtils.isAssignable(Integer.class, Object.class));
446         assertTrue(ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE));
447         assertTrue(ClassUtils.isAssignable(Integer.class, Integer.class));
448         assertEquals(autoboxing, ClassUtils.isAssignable(Boolean.TYPE, Boolean.class));
449         assertEquals(autoboxing, ClassUtils.isAssignable(Boolean.TYPE, Object.class));
450         assertEquals(autoboxing, ClassUtils.isAssignable(Boolean.class, Boolean.TYPE));
451         assertEquals(autoboxing, ClassUtils.isAssignable(Boolean.class, Object.class));
452         assertTrue(ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE));
453         assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class));
454     }
455 
456     @Test
457     public void test_isAssignable_Autoboxing() throws Exception {
458         assertFalse(ClassUtils.isAssignable((Class<?>) null, null, true));
459         assertFalse(ClassUtils.isAssignable(String.class, null, true));
460 
461         assertTrue(ClassUtils.isAssignable(null, Object.class, true));
462         assertTrue(ClassUtils.isAssignable(null, Integer.class, true));
463         assertFalse(ClassUtils.isAssignable(null, Integer.TYPE, true));
464         assertTrue(ClassUtils.isAssignable(String.class, Object.class, true));
465         assertTrue(ClassUtils.isAssignable(String.class, String.class, true));
466         assertFalse(ClassUtils.isAssignable(Object.class, String.class, true));
467         assertTrue(ClassUtils.isAssignable(Integer.TYPE, Integer.class, true));
468         assertTrue(ClassUtils.isAssignable(Integer.TYPE, Object.class, true));
469         assertTrue(ClassUtils.isAssignable(Integer.class, Integer.TYPE, true));
470         assertTrue(ClassUtils.isAssignable(Integer.class, Object.class, true));
471         assertTrue(ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE, true));
472         assertTrue(ClassUtils.isAssignable(Integer.class, Integer.class, true));
473         assertTrue(ClassUtils.isAssignable(Boolean.TYPE, Boolean.class, true));
474         assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true));
475         assertTrue(ClassUtils.isAssignable(Boolean.class, Object.class, true));
476         assertTrue(ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE, true));
477         assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class, true));
478     }
479 
480     @Test
481     public void test_isAssignable_NoAutoboxing() throws Exception {
482         assertFalse(ClassUtils.isAssignable((Class<?>) null, null, false));
483         assertFalse(ClassUtils.isAssignable(String.class, null, false));
484 
485         assertTrue(ClassUtils.isAssignable(null, Object.class, false));
486         assertTrue(ClassUtils.isAssignable(null, Integer.class, false));
487         assertFalse(ClassUtils.isAssignable(null, Integer.TYPE, false));
488         assertTrue(ClassUtils.isAssignable(String.class, Object.class, false));
489         assertTrue(ClassUtils.isAssignable(String.class, String.class, false));
490         assertFalse(ClassUtils.isAssignable(Object.class, String.class, false));
491         assertFalse(ClassUtils.isAssignable(Integer.TYPE, Integer.class, false));
492         assertFalse(ClassUtils.isAssignable(Integer.TYPE, Object.class, false));
493         assertFalse(ClassUtils.isAssignable(Integer.class, Integer.TYPE, false));
494         assertTrue(ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE, false));
495         assertTrue(ClassUtils.isAssignable(Integer.class, Integer.class, false));
496         assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Boolean.class, false));
497         assertFalse(ClassUtils.isAssignable(Boolean.TYPE, Object.class, false));
498         assertFalse(ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, false));
499         assertTrue(ClassUtils.isAssignable(Boolean.class, Object.class, false));
500         assertTrue(ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE, false));
501         assertTrue(ClassUtils.isAssignable(Boolean.class, Boolean.class, false));
502     }
503 
504     @Test
505     public void test_isAssignable_Widening() throws Exception {
506         // test byte conversions
507         assertFalse("byte -> char", ClassUtils.isAssignable(Byte.TYPE, Character.TYPE));
508         assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.TYPE, Byte.TYPE));
509         assertTrue("byte -> short", ClassUtils.isAssignable(Byte.TYPE, Short.TYPE));
510         assertTrue("byte -> int", ClassUtils.isAssignable(Byte.TYPE, Integer.TYPE));
511         assertTrue("byte -> long", ClassUtils.isAssignable(Byte.TYPE, Long.TYPE));
512         assertTrue("byte -> float", ClassUtils.isAssignable(Byte.TYPE, Float.TYPE));
513         assertTrue("byte -> double", ClassUtils.isAssignable(Byte.TYPE, Double.TYPE));
514         assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.TYPE, Boolean.TYPE));
515 
516         // test short conversions
517         assertFalse("short -> char", ClassUtils.isAssignable(Short.TYPE, Character.TYPE));
518         assertFalse("short -> byte", ClassUtils.isAssignable(Short.TYPE, Byte.TYPE));
519         assertTrue("short -> short", ClassUtils.isAssignable(Short.TYPE, Short.TYPE));
520         assertTrue("short -> int", ClassUtils.isAssignable(Short.TYPE, Integer.TYPE));
521         assertTrue("short -> long", ClassUtils.isAssignable(Short.TYPE, Long.TYPE));
522         assertTrue("short -> float", ClassUtils.isAssignable(Short.TYPE, Float.TYPE));
523         assertTrue("short -> double", ClassUtils.isAssignable(Short.TYPE, Double.TYPE));
524         assertFalse("short -> boolean", ClassUtils.isAssignable(Short.TYPE, Boolean.TYPE));
525 
526         // test char conversions
527         assertTrue("char -> char", ClassUtils.isAssignable(Character.TYPE, Character.TYPE));
528         assertFalse("char -> byte", ClassUtils.isAssignable(Character.TYPE, Byte.TYPE));
529         assertFalse("char -> short", ClassUtils.isAssignable(Character.TYPE, Short.TYPE));
530         assertTrue("char -> int", ClassUtils.isAssignable(Character.TYPE, Integer.TYPE));
531         assertTrue("char -> long", ClassUtils.isAssignable(Character.TYPE, Long.TYPE));
532         assertTrue("char -> float", ClassUtils.isAssignable(Character.TYPE, Float.TYPE));
533         assertTrue("char -> double", ClassUtils.isAssignable(Character.TYPE, Double.TYPE));
534         assertFalse("char -> boolean", ClassUtils.isAssignable(Character.TYPE, Boolean.TYPE));
535 
536         // test int conversions
537         assertFalse("int -> char", ClassUtils.isAssignable(Integer.TYPE, Character.TYPE));
538         assertFalse("int -> byte", ClassUtils.isAssignable(Integer.TYPE, Byte.TYPE));
539         assertFalse("int -> short", ClassUtils.isAssignable(Integer.TYPE, Short.TYPE));
540         assertTrue("int -> int", ClassUtils.isAssignable(Integer.TYPE, Integer.TYPE));
541         assertTrue("int -> long", ClassUtils.isAssignable(Integer.TYPE, Long.TYPE));
542         assertTrue("int -> float", ClassUtils.isAssignable(Integer.TYPE, Float.TYPE));
543         assertTrue("int -> double", ClassUtils.isAssignable(Integer.TYPE, Double.TYPE));
544         assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.TYPE, Boolean.TYPE));
545 
546         // test long conversions
547         assertFalse("long -> char", ClassUtils.isAssignable(Long.TYPE, Character.TYPE));
548         assertFalse("long -> byte", ClassUtils.isAssignable(Long.TYPE, Byte.TYPE));
549         assertFalse("long -> short", ClassUtils.isAssignable(Long.TYPE, Short.TYPE));
550         assertFalse("long -> int", ClassUtils.isAssignable(Long.TYPE, Integer.TYPE));
551         assertTrue("long -> long", ClassUtils.isAssignable(Long.TYPE, Long.TYPE));
552         assertTrue("long -> float", ClassUtils.isAssignable(Long.TYPE, Float.TYPE));
553         assertTrue("long -> double", ClassUtils.isAssignable(Long.TYPE, Double.TYPE));
554         assertFalse("long -> boolean", ClassUtils.isAssignable(Long.TYPE, Boolean.TYPE));
555 
556         // test float conversions
557         assertFalse("float -> char", ClassUtils.isAssignable(Float.TYPE, Character.TYPE));
558         assertFalse("float -> byte", ClassUtils.isAssignable(Float.TYPE, Byte.TYPE));
559         assertFalse("float -> short", ClassUtils.isAssignable(Float.TYPE, Short.TYPE));
560         assertFalse("float -> int", ClassUtils.isAssignable(Float.TYPE, Integer.TYPE));
561         assertFalse("float -> long", ClassUtils.isAssignable(Float.TYPE, Long.TYPE));
562         assertTrue("float -> float", ClassUtils.isAssignable(Float.TYPE, Float.TYPE));
563         assertTrue("float -> double", ClassUtils.isAssignable(Float.TYPE, Double.TYPE));
564         assertFalse("float -> boolean", ClassUtils.isAssignable(Float.TYPE, Boolean.TYPE));
565 
566         // test double conversions
567         assertFalse("double -> char", ClassUtils.isAssignable(Double.TYPE, Character.TYPE));
568         assertFalse("double -> byte", ClassUtils.isAssignable(Double.TYPE, Byte.TYPE));
569         assertFalse("double -> short", ClassUtils.isAssignable(Double.TYPE, Short.TYPE));
570         assertFalse("double -> int", ClassUtils.isAssignable(Double.TYPE, Integer.TYPE));
571         assertFalse("double -> long", ClassUtils.isAssignable(Double.TYPE, Long.TYPE));
572         assertFalse("double -> float", ClassUtils.isAssignable(Double.TYPE, Float.TYPE));
573         assertTrue("double -> double", ClassUtils.isAssignable(Double.TYPE, Double.TYPE));
574         assertFalse("double -> boolean", ClassUtils.isAssignable(Double.TYPE, Boolean.TYPE));
575 
576         // test boolean conversions
577         assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.TYPE, Character.TYPE));
578         assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.TYPE, Byte.TYPE));
579         assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.TYPE, Short.TYPE));
580         assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.TYPE, Integer.TYPE));
581         assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.TYPE, Long.TYPE));
582         assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.TYPE, Float.TYPE));
583         assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.TYPE, Double.TYPE));
584         assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.TYPE, Boolean.TYPE));
585     }
586 
587     @Test
588     public void test_isAssignable_DefaultUnboxing_Widening() throws Exception {
589         final boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
590 
591         // test byte conversions
592         assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE));
593         assertEquals("byte -> byte", autoboxing, ClassUtils.isAssignable(Byte.class, Byte.TYPE));
594         assertEquals("byte -> short", autoboxing, ClassUtils.isAssignable(Byte.class, Short.TYPE));
595         assertEquals("byte -> int", autoboxing, ClassUtils.isAssignable(Byte.class, Integer.TYPE));
596         assertEquals("byte -> long", autoboxing, ClassUtils.isAssignable(Byte.class, Long.TYPE));
597         assertEquals("byte -> float", autoboxing, ClassUtils.isAssignable(Byte.class, Float.TYPE));
598         assertEquals("byte -> double", autoboxing, ClassUtils.isAssignable(Byte.class, Double.TYPE));
599         assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.class, Boolean.TYPE));
600 
601         // test short conversions
602         assertFalse("short -> char", ClassUtils.isAssignable(Short.class, Character.TYPE));
603         assertFalse("short -> byte", ClassUtils.isAssignable(Short.class, Byte.TYPE));
604         assertEquals("short -> short", autoboxing, ClassUtils.isAssignable(Short.class, Short.TYPE));
605         assertEquals("short -> int", autoboxing, ClassUtils.isAssignable(Short.class, Integer.TYPE));
606         assertEquals("short -> long", autoboxing, ClassUtils.isAssignable(Short.class, Long.TYPE));
607         assertEquals("short -> float", autoboxing, ClassUtils.isAssignable(Short.class, Float.TYPE));
608         assertEquals("short -> double", autoboxing, ClassUtils.isAssignable(Short.class, Double.TYPE));
609         assertFalse("short -> boolean", ClassUtils.isAssignable(Short.class, Boolean.TYPE));
610 
611         // test char conversions
612         assertEquals("char -> char", autoboxing, ClassUtils.isAssignable(Character.class, Character.TYPE));
613         assertFalse("char -> byte", ClassUtils.isAssignable(Character.class, Byte.TYPE));
614         assertFalse("char -> short", ClassUtils.isAssignable(Character.class, Short.TYPE));
615         assertEquals("char -> int", autoboxing, ClassUtils.isAssignable(Character.class, Integer.TYPE));
616         assertEquals("char -> long", autoboxing, ClassUtils.isAssignable(Character.class, Long.TYPE));
617         assertEquals("char -> float", autoboxing, ClassUtils.isAssignable(Character.class, Float.TYPE));
618         assertEquals("char -> double", autoboxing, ClassUtils.isAssignable(Character.class, Double.TYPE));
619         assertFalse("char -> boolean", ClassUtils.isAssignable(Character.class, Boolean.TYPE));
620 
621         // test int conversions
622         assertFalse("int -> char", ClassUtils.isAssignable(Integer.class, Character.TYPE));
623         assertFalse("int -> byte", ClassUtils.isAssignable(Integer.class, Byte.TYPE));
624         assertFalse("int -> short", ClassUtils.isAssignable(Integer.class, Short.TYPE));
625         assertEquals("int -> int", autoboxing, ClassUtils.isAssignable(Integer.class, Integer.TYPE));
626         assertEquals("int -> long", autoboxing, ClassUtils.isAssignable(Integer.class, Long.TYPE));
627         assertEquals("int -> float", autoboxing, ClassUtils.isAssignable(Integer.class, Float.TYPE));
628         assertEquals("int -> double", autoboxing, ClassUtils.isAssignable(Integer.class, Double.TYPE));
629         assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.class, Boolean.TYPE));
630 
631         // test long conversions
632         assertFalse("long -> char", ClassUtils.isAssignable(Long.class, Character.TYPE));
633         assertFalse("long -> byte", ClassUtils.isAssignable(Long.class, Byte.TYPE));
634         assertFalse("long -> short", ClassUtils.isAssignable(Long.class, Short.TYPE));
635         assertFalse("long -> int", ClassUtils.isAssignable(Long.class, Integer.TYPE));
636         assertEquals("long -> long", autoboxing, ClassUtils.isAssignable(Long.class, Long.TYPE));
637         assertEquals("long -> float", autoboxing, ClassUtils.isAssignable(Long.class, Float.TYPE));
638         assertEquals("long -> double", autoboxing, ClassUtils.isAssignable(Long.class, Double.TYPE));
639         assertFalse("long -> boolean", ClassUtils.isAssignable(Long.class, Boolean.TYPE));
640 
641         // test float conversions
642         assertFalse("float -> char", ClassUtils.isAssignable(Float.class, Character.TYPE));
643         assertFalse("float -> byte", ClassUtils.isAssignable(Float.class, Byte.TYPE));
644         assertFalse("float -> short", ClassUtils.isAssignable(Float.class, Short.TYPE));
645         assertFalse("float -> int", ClassUtils.isAssignable(Float.class, Integer.TYPE));
646         assertFalse("float -> long", ClassUtils.isAssignable(Float.class, Long.TYPE));
647         assertEquals("float -> float", autoboxing, ClassUtils.isAssignable(Float.class, Float.TYPE));
648         assertEquals("float -> double", autoboxing, ClassUtils.isAssignable(Float.class, Double.TYPE));
649         assertFalse("float -> boolean", ClassUtils.isAssignable(Float.class, Boolean.TYPE));
650 
651         // test double conversions
652         assertFalse("double -> char", ClassUtils.isAssignable(Double.class, Character.TYPE));
653         assertFalse("double -> byte", ClassUtils.isAssignable(Double.class, Byte.TYPE));
654         assertFalse("double -> short", ClassUtils.isAssignable(Double.class, Short.TYPE));
655         assertFalse("double -> int", ClassUtils.isAssignable(Double.class, Integer.TYPE));
656         assertFalse("double -> long", ClassUtils.isAssignable(Double.class, Long.TYPE));
657         assertFalse("double -> float", ClassUtils.isAssignable(Double.class, Float.TYPE));
658         assertEquals("double -> double", autoboxing, ClassUtils.isAssignable(Double.class, Double.TYPE));
659         assertFalse("double -> boolean", ClassUtils.isAssignable(Double.class, Boolean.TYPE));
660 
661         // test boolean conversions
662         assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.class, Character.TYPE));
663         assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.class, Byte.TYPE));
664         assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.class, Short.TYPE));
665         assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.class, Integer.TYPE));
666         assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.class, Long.TYPE));
667         assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.class, Float.TYPE));
668         assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.class, Double.TYPE));
669         assertEquals("boolean -> boolean", autoboxing, ClassUtils.isAssignable(Boolean.class, Boolean.TYPE));
670     }
671 
672     @Test
673     public void test_isAssignable_Unboxing_Widening() throws Exception {
674         // test byte conversions
675         assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE, true));
676         assertTrue("byte -> byte", ClassUtils.isAssignable(Byte.class, Byte.TYPE, true));
677         assertTrue("byte -> short", ClassUtils.isAssignable(Byte.class, Short.TYPE, true));
678         assertTrue("byte -> int", ClassUtils.isAssignable(Byte.class, Integer.TYPE, true));
679         assertTrue("byte -> long", ClassUtils.isAssignable(Byte.class, Long.TYPE, true));
680         assertTrue("byte -> float", ClassUtils.isAssignable(Byte.class, Float.TYPE, true));
681         assertTrue("byte -> double", ClassUtils.isAssignable(Byte.class, Double.TYPE, true));
682         assertFalse("byte -> boolean", ClassUtils.isAssignable(Byte.class, Boolean.TYPE, true));
683 
684         // test short conversions
685         assertFalse("short -> char", ClassUtils.isAssignable(Short.class, Character.TYPE, true));
686         assertFalse("short -> byte", ClassUtils.isAssignable(Short.class, Byte.TYPE, true));
687         assertTrue("short -> short", ClassUtils.isAssignable(Short.class, Short.TYPE, true));
688         assertTrue("short -> int", ClassUtils.isAssignable(Short.class, Integer.TYPE, true));
689         assertTrue("short -> long", ClassUtils.isAssignable(Short.class, Long.TYPE, true));
690         assertTrue("short -> float", ClassUtils.isAssignable(Short.class, Float.TYPE, true));
691         assertTrue("short -> double", ClassUtils.isAssignable(Short.class, Double.TYPE, true));
692         assertFalse("short -> boolean", ClassUtils.isAssignable(Short.class, Boolean.TYPE, true));
693 
694         // test char conversions
695         assertTrue("char -> char", ClassUtils.isAssignable(Character.class, Character.TYPE, true));
696         assertFalse("char -> byte", ClassUtils.isAssignable(Character.class, Byte.TYPE, true));
697         assertFalse("char -> short", ClassUtils.isAssignable(Character.class, Short.TYPE, true));
698         assertTrue("char -> int", ClassUtils.isAssignable(Character.class, Integer.TYPE, true));
699         assertTrue("char -> long", ClassUtils.isAssignable(Character.class, Long.TYPE, true));
700         assertTrue("char -> float", ClassUtils.isAssignable(Character.class, Float.TYPE, true));
701         assertTrue("char -> double", ClassUtils.isAssignable(Character.class, Double.TYPE, true));
702         assertFalse("char -> boolean", ClassUtils.isAssignable(Character.class, Boolean.TYPE, true));
703 
704         // test int conversions
705         assertFalse("int -> char", ClassUtils.isAssignable(Integer.class, Character.TYPE, true));
706         assertFalse("int -> byte", ClassUtils.isAssignable(Integer.class, Byte.TYPE, true));
707         assertFalse("int -> short", ClassUtils.isAssignable(Integer.class, Short.TYPE, true));
708         assertTrue("int -> int", ClassUtils.isAssignable(Integer.class, Integer.TYPE, true));
709         assertTrue("int -> long", ClassUtils.isAssignable(Integer.class, Long.TYPE, true));
710         assertTrue("int -> float", ClassUtils.isAssignable(Integer.class, Float.TYPE, true));
711         assertTrue("int -> double", ClassUtils.isAssignable(Integer.class, Double.TYPE, true));
712         assertFalse("int -> boolean", ClassUtils.isAssignable(Integer.class, Boolean.TYPE, true));
713 
714         // test long conversions
715         assertFalse("long -> char", ClassUtils.isAssignable(Long.class, Character.TYPE, true));
716         assertFalse("long -> byte", ClassUtils.isAssignable(Long.class, Byte.TYPE, true));
717         assertFalse("long -> short", ClassUtils.isAssignable(Long.class, Short.TYPE, true));
718         assertFalse("long -> int", ClassUtils.isAssignable(Long.class, Integer.TYPE, true));
719         assertTrue("long -> long", ClassUtils.isAssignable(Long.class, Long.TYPE, true));
720         assertTrue("long -> float", ClassUtils.isAssignable(Long.class, Float.TYPE, true));
721         assertTrue("long -> double", ClassUtils.isAssignable(Long.class, Double.TYPE, true));
722         assertFalse("long -> boolean", ClassUtils.isAssignable(Long.class, Boolean.TYPE, true));
723 
724         // test float conversions
725         assertFalse("float -> char", ClassUtils.isAssignable(Float.class, Character.TYPE, true));
726         assertFalse("float -> byte", ClassUtils.isAssignable(Float.class, Byte.TYPE, true));
727         assertFalse("float -> short", ClassUtils.isAssignable(Float.class, Short.TYPE, true));
728         assertFalse("float -> int", ClassUtils.isAssignable(Float.class, Integer.TYPE, true));
729         assertFalse("float -> long", ClassUtils.isAssignable(Float.class, Long.TYPE, true));
730         assertTrue("float -> float", ClassUtils.isAssignable(Float.class, Float.TYPE, true));
731         assertTrue("float -> double", ClassUtils.isAssignable(Float.class, Double.TYPE, true));
732         assertFalse("float -> boolean", ClassUtils.isAssignable(Float.class, Boolean.TYPE, true));
733 
734         // test double conversions
735         assertFalse("double -> char", ClassUtils.isAssignable(Double.class, Character.TYPE, true));
736         assertFalse("double -> byte", ClassUtils.isAssignable(Double.class, Byte.TYPE, true));
737         assertFalse("double -> short", ClassUtils.isAssignable(Double.class, Short.TYPE, true));
738         assertFalse("double -> int", ClassUtils.isAssignable(Double.class, Integer.TYPE, true));
739         assertFalse("double -> long", ClassUtils.isAssignable(Double.class, Long.TYPE, true));
740         assertFalse("double -> float", ClassUtils.isAssignable(Double.class, Float.TYPE, true));
741         assertTrue("double -> double", ClassUtils.isAssignable(Double.class, Double.TYPE, true));
742         assertFalse("double -> boolean", ClassUtils.isAssignable(Double.class, Boolean.TYPE, true));
743 
744         // test boolean conversions
745         assertFalse("boolean -> char", ClassUtils.isAssignable(Boolean.class, Character.TYPE, true));
746         assertFalse("boolean -> byte", ClassUtils.isAssignable(Boolean.class, Byte.TYPE, true));
747         assertFalse("boolean -> short", ClassUtils.isAssignable(Boolean.class, Short.TYPE, true));
748         assertFalse("boolean -> int", ClassUtils.isAssignable(Boolean.class, Integer.TYPE, true));
749         assertFalse("boolean -> long", ClassUtils.isAssignable(Boolean.class, Long.TYPE, true));
750         assertFalse("boolean -> float", ClassUtils.isAssignable(Boolean.class, Float.TYPE, true));
751         assertFalse("boolean -> double", ClassUtils.isAssignable(Boolean.class, Double.TYPE, true));
752         assertTrue("boolean -> boolean", ClassUtils.isAssignable(Boolean.class, Boolean.TYPE, true));
753     }
754 
755     @Test
756     public void testIsPrimitiveOrWrapper() {
757 
758         // test primitive wrapper classes
759         assertTrue("Boolean.class", ClassUtils.isPrimitiveOrWrapper(Boolean.class));
760         assertTrue("Byte.class", ClassUtils.isPrimitiveOrWrapper(Byte.class));
761         assertTrue("Character.class", ClassUtils.isPrimitiveOrWrapper(Character.class));
762         assertTrue("Short.class", ClassUtils.isPrimitiveOrWrapper(Short.class));
763         assertTrue("Integer.class", ClassUtils.isPrimitiveOrWrapper(Integer.class));
764         assertTrue("Long.class", ClassUtils.isPrimitiveOrWrapper(Long.class));
765         assertTrue("Double.class", ClassUtils.isPrimitiveOrWrapper(Double.class));
766         assertTrue("Float.class", ClassUtils.isPrimitiveOrWrapper(Float.class));
767         
768         // test primitive classes
769         assertTrue("boolean", ClassUtils.isPrimitiveOrWrapper(Boolean.TYPE));
770         assertTrue("byte", ClassUtils.isPrimitiveOrWrapper(Byte.TYPE));
771         assertTrue("char", ClassUtils.isPrimitiveOrWrapper(Character.TYPE));
772         assertTrue("short", ClassUtils.isPrimitiveOrWrapper(Short.TYPE));
773         assertTrue("int", ClassUtils.isPrimitiveOrWrapper(Integer.TYPE));
774         assertTrue("long", ClassUtils.isPrimitiveOrWrapper(Long.TYPE));
775         assertTrue("double", ClassUtils.isPrimitiveOrWrapper(Double.TYPE));
776         assertTrue("float", ClassUtils.isPrimitiveOrWrapper(Float.TYPE));
777         assertTrue("Void.TYPE", ClassUtils.isPrimitiveOrWrapper(Void.TYPE));
778         
779         // others
780         assertFalse("null", ClassUtils.isPrimitiveOrWrapper(null));
781         assertFalse("Void.class", ClassUtils.isPrimitiveOrWrapper(Void.class));
782         assertFalse("String.class", ClassUtils.isPrimitiveOrWrapper(String.class));
783         assertFalse("this.getClass()", ClassUtils.isPrimitiveOrWrapper(this.getClass()));
784     }
785     
786     @Test
787     public void testIsPrimitiveWrapper() {
788 
789         // test primitive wrapper classes
790         assertTrue("Boolean.class", ClassUtils.isPrimitiveWrapper(Boolean.class));
791         assertTrue("Byte.class", ClassUtils.isPrimitiveWrapper(Byte.class));
792         assertTrue("Character.class", ClassUtils.isPrimitiveWrapper(Character.class));
793         assertTrue("Short.class", ClassUtils.isPrimitiveWrapper(Short.class));
794         assertTrue("Integer.class", ClassUtils.isPrimitiveWrapper(Integer.class));
795         assertTrue("Long.class", ClassUtils.isPrimitiveWrapper(Long.class));
796         assertTrue("Double.class", ClassUtils.isPrimitiveWrapper(Double.class));
797         assertTrue("Float.class", ClassUtils.isPrimitiveWrapper(Float.class));
798         
799         // test primitive classes
800         assertFalse("boolean", ClassUtils.isPrimitiveWrapper(Boolean.TYPE));
801         assertFalse("byte", ClassUtils.isPrimitiveWrapper(Byte.TYPE));
802         assertFalse("char", ClassUtils.isPrimitiveWrapper(Character.TYPE));
803         assertFalse("short", ClassUtils.isPrimitiveWrapper(Short.TYPE));
804         assertFalse("int", ClassUtils.isPrimitiveWrapper(Integer.TYPE));
805         assertFalse("long", ClassUtils.isPrimitiveWrapper(Long.TYPE));
806         assertFalse("double", ClassUtils.isPrimitiveWrapper(Double.TYPE));
807         assertFalse("float", ClassUtils.isPrimitiveWrapper(Float.TYPE));
808         
809         // others
810         assertFalse("null", ClassUtils.isPrimitiveWrapper(null));
811         assertFalse("Void.class", ClassUtils.isPrimitiveWrapper(Void.class));
812         assertFalse("Void.TYPE", ClassUtils.isPrimitiveWrapper(Void.TYPE));
813         assertFalse("String.class", ClassUtils.isPrimitiveWrapper(String.class));
814         assertFalse("this.getClass()", ClassUtils.isPrimitiveWrapper(this.getClass()));
815     }
816     
817     @Test
818     public void testPrimitiveToWrapper() {
819 
820         // test primitive classes
821         assertEquals("boolean -> Boolean.class",
822             Boolean.class, ClassUtils.primitiveToWrapper(Boolean.TYPE));
823         assertEquals("byte -> Byte.class",
824             Byte.class, ClassUtils.primitiveToWrapper(Byte.TYPE));
825         assertEquals("char -> Character.class",
826             Character.class, ClassUtils.primitiveToWrapper(Character.TYPE));
827         assertEquals("short -> Short.class",
828             Short.class, ClassUtils.primitiveToWrapper(Short.TYPE));
829         assertEquals("int -> Integer.class",
830             Integer.class, ClassUtils.primitiveToWrapper(Integer.TYPE));
831         assertEquals("long -> Long.class",
832             Long.class, ClassUtils.primitiveToWrapper(Long.TYPE));
833         assertEquals("double -> Double.class",
834             Double.class, ClassUtils.primitiveToWrapper(Double.TYPE));
835         assertEquals("float -> Float.class",
836             Float.class, ClassUtils.primitiveToWrapper(Float.TYPE));
837 
838         // test a few other classes
839         assertEquals("String.class -> String.class",
840             String.class, ClassUtils.primitiveToWrapper(String.class));
841         assertEquals("ClassUtils.class -> ClassUtils.class",
842             org.apache.commons.lang3.ClassUtils.class,
843             ClassUtils.primitiveToWrapper(org.apache.commons.lang3.ClassUtils.class));
844         assertEquals("Void.TYPE -> Void.TYPE",
845             Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE));
846 
847         // test null
848         assertNull("null -> null",
849             ClassUtils.primitiveToWrapper(null));
850     }
851 
852     @Test
853     public void testPrimitivesToWrappers() {
854         // test null
855 //        assertNull("null -> null", ClassUtils.primitivesToWrappers(null)); // generates warning
856         assertNull("null -> null", ClassUtils.primitivesToWrappers((Class<?>[]) null)); // equivalent cast to avoid warning
857         // Other possible casts for null
858         assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers()));
859         final Class<?>[] castNull = ClassUtils.primitivesToWrappers((Class<?>)null); // == new Class<?>[]{null}
860         assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
861         // test empty array is returned unchanged
862         // TODO this is not documented
863         assertArrayEquals("empty -> empty",
864                 ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY));
865 
866         // test an array of various classes
867         final Class<?>[] primitives = new Class[] {
868                 Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
869                 Integer.TYPE, Long.TYPE, Double.TYPE, Float.TYPE,
870                 String.class, ClassUtils.class
871         };
872         final Class<?>[] wrappers= ClassUtils.primitivesToWrappers(primitives);
873 
874         for (int i=0; i < primitives.length; i++) {
875             // test each returned wrapper
876             final Class<?> primitive = primitives[i];
877             final Class<?> expectedWrapper = ClassUtils.primitiveToWrapper(primitive);
878 
879             assertEquals(primitive + " -> " + expectedWrapper, expectedWrapper, wrappers[i]);
880         }
881 
882         // test an array of no primitive classes
883         final Class<?>[] noPrimitives = new Class[] {
884                 String.class, ClassUtils.class, Void.TYPE
885         };
886         // This used to return the exact same array, but no longer does.
887         assertNotSame("unmodified", noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives));
888     }
889 
890     @Test
891     public void testWrapperToPrimitive() {
892         // an array with classes to convert
893         final Class<?>[] primitives = {
894                 Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
895                 Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE
896         };
897         for (final Class<?> primitive : primitives) {
898             final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
899             assertFalse("Still primitive", wrapperCls.isPrimitive());
900             assertEquals(wrapperCls + " -> " + primitive, primitive,
901                     ClassUtils.wrapperToPrimitive(wrapperCls));
902         }
903     }
904 
905     @Test
906     public void testWrapperToPrimitiveNoWrapper() {
907         assertNull("Wrong result for non wrapper class", ClassUtils.wrapperToPrimitive(String.class));
908     }
909 
910     @Test
911     public void testWrapperToPrimitiveNull() {
912         assertNull("Wrong result for null class", ClassUtils.wrapperToPrimitive(null));
913     }
914 
915     @Test
916     public void testWrappersToPrimitives() {
917         // an array with classes to test
918         final Class<?>[] classes = {
919                 Boolean.class, Byte.class, Character.class, Short.class,
920                 Integer.class, Long.class, Float.class, Double.class,
921                 String.class, ClassUtils.class, null
922         };
923 
924         final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
925         // now test the result
926         assertEquals("Wrong length of result array", classes.length, primitives.length);
927         for (int i = 0; i < classes.length; i++) {
928             final Class<?> expectedPrimitive = ClassUtils.wrapperToPrimitive(classes[i]);
929             assertEquals(classes[i] + " -> " + expectedPrimitive, expectedPrimitive,
930                     primitives[i]);
931         }
932     }
933 
934     @Test
935     public void testWrappersToPrimitivesNull() {
936 //        assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives(null)); // generates warning
937         assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives((Class<?>[]) null)); // equivalent cast
938         // Other possible casts for null
939         assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.wrappersToPrimitives()));
940         final Class<?>[] castNull = ClassUtils.wrappersToPrimitives((Class<?>)null); // == new Class<?>[]{null}
941         assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
942 }
943 
944     @Test
945     public void testWrappersToPrimitivesEmpty() {
946         final Class<?>[] empty = new Class[0];
947         assertArrayEquals("Wrong result for empty input", empty, ClassUtils.wrappersToPrimitives(empty));
948     }
949 
950     @Test
951     public void testGetClassClassNotFound() throws Exception {
952         assertGetClassThrowsClassNotFound( "bool" );
953         assertGetClassThrowsClassNotFound( "bool[]" );
954         assertGetClassThrowsClassNotFound( "integer[]" );
955     }
956 
957     @Test
958     public void testGetClassInvalidArguments() throws Exception {
959         assertGetClassThrowsNullPointerException( null );
960         assertGetClassThrowsClassNotFound( "[][][]" );
961         assertGetClassThrowsClassNotFound( "[[]" );
962         assertGetClassThrowsClassNotFound( "[" );
963         assertGetClassThrowsClassNotFound( "java.lang.String][" );
964         assertGetClassThrowsClassNotFound( ".hello.world" );
965         assertGetClassThrowsClassNotFound( "hello..world" );
966     }
967 
968     @Test
969     public void testWithInterleavingWhitespace() throws ClassNotFoundException {
970         assertEquals( int[].class, ClassUtils.getClass( " int [ ] " ) );
971         assertEquals( long[].class, ClassUtils.getClass( "\rlong\t[\n]\r" ) );
972         assertEquals( short[].class, ClassUtils.getClass( "\tshort                \t\t[]" ) );
973         assertEquals( byte[].class, ClassUtils.getClass( "byte[\t\t\n\r]   " ) );
974     }
975 
976     @Test
977     public void testGetInnerClass() throws ClassNotFoundException {
978         assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner.DeeplyNested" ) );
979         assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner$DeeplyNested" ) );
980         assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest$Inner$DeeplyNested" ) );
981         assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest$Inner.DeeplyNested" ) );
982     }
983 
984     @Test
985     public void testGetClassByNormalNameArrays() throws ClassNotFoundException {
986         assertEquals( int[].class, ClassUtils.getClass( "int[]" ) );
987         assertEquals( long[].class, ClassUtils.getClass( "long[]" ) );
988         assertEquals( short[].class, ClassUtils.getClass( "short[]" ) );
989         assertEquals( byte[].class, ClassUtils.getClass( "byte[]" ) );
990         assertEquals( char[].class, ClassUtils.getClass( "char[]" ) );
991         assertEquals( float[].class, ClassUtils.getClass( "float[]" ) );
992         assertEquals( double[].class, ClassUtils.getClass( "double[]" ) );
993         assertEquals( boolean[].class, ClassUtils.getClass( "boolean[]" ) );
994         assertEquals( String[].class, ClassUtils.getClass( "java.lang.String[]" ) );
995         assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "java.util.Map.Entry[]" ) );
996         assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "java.util.Map$Entry[]" ) );
997         assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "[Ljava.util.Map.Entry;" ) );
998         assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "[Ljava.util.Map$Entry;" ) );
999     }
1000 
1001     @Test
1002     public void testGetClassByNormalNameArrays2D() throws ClassNotFoundException {
1003         assertEquals( int[][].class, ClassUtils.getClass( "int[][]" ) );
1004         assertEquals( long[][].class, ClassUtils.getClass( "long[][]" ) );
1005         assertEquals( short[][].class, ClassUtils.getClass( "short[][]" ) );
1006         assertEquals( byte[][].class, ClassUtils.getClass( "byte[][]" ) );
1007         assertEquals( char[][].class, ClassUtils.getClass( "char[][]" ) );
1008         assertEquals( float[][].class, ClassUtils.getClass( "float[][]" ) );
1009         assertEquals( double[][].class, ClassUtils.getClass( "double[][]" ) );
1010         assertEquals( boolean[][].class, ClassUtils.getClass( "boolean[][]" ) );
1011         assertEquals( String[][].class, ClassUtils.getClass( "java.lang.String[][]" ) );
1012     }
1013 
1014     @Test
1015     public void testGetClassWithArrayClasses2D() throws Exception {
1016         assertGetClassReturnsClass( String[][].class );
1017         assertGetClassReturnsClass( int[][].class );
1018         assertGetClassReturnsClass( long[][].class );
1019         assertGetClassReturnsClass( short[][].class );
1020         assertGetClassReturnsClass( byte[][].class );
1021         assertGetClassReturnsClass( char[][].class );
1022         assertGetClassReturnsClass( float[][].class );
1023         assertGetClassReturnsClass( double[][].class );
1024         assertGetClassReturnsClass( boolean[][].class );
1025     }
1026 
1027     @Test
1028     public void testGetClassWithArrayClasses() throws Exception {
1029         assertGetClassReturnsClass( String[].class );
1030         assertGetClassReturnsClass( int[].class );
1031         assertGetClassReturnsClass( long[].class );
1032         assertGetClassReturnsClass( short[].class );
1033         assertGetClassReturnsClass( byte[].class );
1034         assertGetClassReturnsClass( char[].class );
1035         assertGetClassReturnsClass( float[].class );
1036         assertGetClassReturnsClass( double[].class );
1037         assertGetClassReturnsClass( boolean[].class );
1038     }
1039 
1040     @Test
1041     public void testGetClassRawPrimitives() throws ClassNotFoundException {
1042         assertEquals( int.class, ClassUtils.getClass( "int" ) );
1043         assertEquals( long.class, ClassUtils.getClass( "long" ) );
1044         assertEquals( short.class, ClassUtils.getClass( "short" ) );
1045         assertEquals( byte.class, ClassUtils.getClass( "byte" ) );
1046         assertEquals( char.class, ClassUtils.getClass( "char" ) );
1047         assertEquals( float.class, ClassUtils.getClass( "float" ) );
1048         assertEquals( double.class, ClassUtils.getClass( "double" ) );
1049         assertEquals( boolean.class, ClassUtils.getClass( "boolean" ) );
1050     }
1051 
1052     private void assertGetClassReturnsClass( final Class<?> c ) throws Exception {
1053         assertEquals( c, ClassUtils.getClass( c.getName() ) );
1054     }
1055 
1056     private void assertGetClassThrowsException( final String className, final Class<?> exceptionType ) throws Exception {
1057         try {
1058             ClassUtils.getClass( className );
1059             fail( "ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\"." );
1060         }
1061         catch( final Exception e ) {
1062             assertTrue( exceptionType.isAssignableFrom( e.getClass() ) );
1063         }
1064     }
1065 
1066     private void assertGetClassThrowsNullPointerException( final String className ) throws Exception {
1067         assertGetClassThrowsException( className, NullPointerException.class );
1068     }
1069 
1070     private void assertGetClassThrowsClassNotFound( final String className ) throws Exception {
1071         assertGetClassThrowsException( className, ClassNotFoundException.class );
1072     }
1073 
1074     // Show the Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957
1075     // We may have to delete this if a JDK fixes the bug.
1076     @Test
1077     public void testShowJavaBug() throws Exception {
1078         // Tests with Collections$UnmodifiableSet
1079         final Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
1080         final Method isEmptyMethod = set.getClass().getMethod("isEmpty",  new Class[0]);
1081         try {
1082             isEmptyMethod.invoke(set, new Object[0]);
1083             fail("Failed to throw IllegalAccessException as expected");
1084         } catch(final IllegalAccessException iae) {
1085             // expected
1086         }
1087     }
1088 
1089     @Test
1090     public void testGetPublicMethod() throws Exception {
1091         // Tests with Collections$UnmodifiableSet
1092         final Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
1093         final Method isEmptyMethod = ClassUtils.getPublicMethod(set.getClass(), "isEmpty",  new Class[0]);
1094             assertTrue(Modifier.isPublic(isEmptyMethod.getDeclaringClass().getModifiers()));
1095 
1096         try {
1097             isEmptyMethod.invoke(set, new Object[0]);
1098         } catch(final java.lang.IllegalAccessException iae) {
1099             fail("Should not have thrown IllegalAccessException");
1100         }
1101 
1102         // Tests with a public Class
1103         final Method toStringMethod = ClassUtils.getPublicMethod(Object.class, "toString",  new Class[0]);
1104             assertEquals(Object.class.getMethod("toString", new Class[0]), toStringMethod);
1105     }
1106 
1107     @Test
1108     public void testToClass_object() {
1109 //        assertNull(ClassUtils.toClass(null)); // generates warning
1110         assertNull(ClassUtils.toClass((Object[]) null)); // equivalent explicit cast
1111         
1112         // Additional varargs tests
1113         assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass()));
1114         final Class<?>[] castNull = ClassUtils.toClass((Object) null); // == new Object[]{null}
1115         assertTrue("(Object)null -> [null]", Arrays.equals(new Object[]{null}, castNull));
1116 
1117         assertSame(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass(ArrayUtils.EMPTY_OBJECT_ARRAY));
1118 
1119         assertTrue(Arrays.equals(new Class[] { String.class, Integer.class, Double.class },
1120                 ClassUtils.toClass(new Object[] { "Test", Integer.valueOf(1), Double.valueOf(99d) })));
1121 
1122         assertTrue(Arrays.equals(new Class[] { String.class, null, Double.class },
1123                 ClassUtils.toClass(new Object[] { "Test", null, Double.valueOf(99d) })));
1124     }
1125 
1126     @Test
1127     public void test_getShortCanonicalName_Object() {
1128         assertEquals("<null>", ClassUtils.getShortCanonicalName(null, "<null>"));
1129         assertEquals("ClassUtils", ClassUtils.getShortCanonicalName(new ClassUtils(), "<null>"));
1130         assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName(new ClassUtils[0], "<null>"));
1131         assertEquals("ClassUtils[][]", ClassUtils.getShortCanonicalName(new ClassUtils[0][0], "<null>"));
1132         assertEquals("int[]", ClassUtils.getShortCanonicalName(new int[0], "<null>"));
1133         assertEquals("int[][]", ClassUtils.getShortCanonicalName(new int[0][0], "<null>"));
1134 
1135         // Inner types
1136         class Named extends Object {}
1137         assertEquals("ClassUtilsTest.6", ClassUtils.getShortCanonicalName(new Object(){}, "<null>"));
1138         assertEquals("ClassUtilsTest.5Named", ClassUtils.getShortCanonicalName(new Named(), "<null>"));
1139         assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName(new Inner(), "<null>"));
1140     }
1141 
1142     @Test
1143     public void test_getShortCanonicalName_Class() {
1144         assertEquals("ClassUtils", ClassUtils.getShortCanonicalName(ClassUtils.class));
1145         assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName(ClassUtils[].class));
1146         assertEquals("ClassUtils[][]", ClassUtils.getShortCanonicalName(ClassUtils[][].class));
1147         assertEquals("int[]", ClassUtils.getShortCanonicalName(int[].class));
1148         assertEquals("int[][]", ClassUtils.getShortCanonicalName(int[][].class));
1149         
1150         // Inner types
1151         class Named extends Object {}
1152         assertEquals("ClassUtilsTest.7", ClassUtils.getShortCanonicalName(new Object(){}.getClass()));
1153         assertEquals("ClassUtilsTest.6Named", ClassUtils.getShortCanonicalName(Named.class));
1154         assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName(Inner.class));
1155     }
1156 
1157     @Test
1158     public void test_getShortCanonicalName_String() {
1159         assertEquals("ClassUtils", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils"));
1160         assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;"));
1161         assertEquals("ClassUtils[][]", ClassUtils.getShortCanonicalName("[[Lorg.apache.commons.lang3.ClassUtils;"));
1162         assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils[]"));
1163         assertEquals("ClassUtils[][]", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils[][]"));
1164         assertEquals("int[]", ClassUtils.getShortCanonicalName("[I"));
1165         assertEquals("int[][]", ClassUtils.getShortCanonicalName("[[I"));
1166         assertEquals("int[]", ClassUtils.getShortCanonicalName("int[]"));
1167         assertEquals("int[][]", ClassUtils.getShortCanonicalName("int[][]"));
1168         
1169         // Inner types
1170         assertEquals("ClassUtilsTest.6", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$6"));
1171         assertEquals("ClassUtilsTest.5Named", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$5Named"));
1172         assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$Inner"));
1173     }
1174 
1175     @Test
1176     public void test_getPackageCanonicalName_Object() {
1177         assertEquals("<null>", ClassUtils.getPackageCanonicalName(null, "<null>"));
1178         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new ClassUtils(), "<null>"));
1179         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new ClassUtils[0], "<null>"));
1180         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new ClassUtils[0][0], "<null>"));
1181         assertEquals("", ClassUtils.getPackageCanonicalName(new int[0], "<null>"));
1182         assertEquals("", ClassUtils.getPackageCanonicalName(new int[0][0], "<null>"));
1183         
1184         // Inner types
1185         class Named extends Object {}
1186         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new Object(){}, "<null>"));
1187         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new Named(), "<null>"));
1188         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new Inner(), "<null>"));
1189     }
1190 
1191     @Test
1192     public void test_getPackageCanonicalName_Class() {
1193         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(ClassUtils.class));
1194         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(ClassUtils[].class));
1195         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(ClassUtils[][].class));
1196         assertEquals("", ClassUtils.getPackageCanonicalName(int[].class));
1197         assertEquals("", ClassUtils.getPackageCanonicalName(int[][].class));
1198         
1199         // Inner types
1200         class Named extends Object {}
1201         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(new Object(){}.getClass()));
1202         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(Named.class));
1203         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName(Inner.class));
1204     }
1205 
1206     @Test
1207     public void test_getPackageCanonicalName_String() {
1208         assertEquals("org.apache.commons.lang3",
1209             ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils"));
1210         assertEquals("org.apache.commons.lang3",
1211             ClassUtils.getPackageCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;"));
1212         assertEquals("org.apache.commons.lang3",
1213             ClassUtils.getPackageCanonicalName("[[Lorg.apache.commons.lang3.ClassUtils;"));
1214         assertEquals("org.apache.commons.lang3",
1215             ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[]"));
1216         assertEquals("org.apache.commons.lang3",
1217             ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[][]"));
1218         assertEquals("", ClassUtils.getPackageCanonicalName("[I"));
1219         assertEquals("", ClassUtils.getPackageCanonicalName("[[I"));
1220         assertEquals("", ClassUtils.getPackageCanonicalName("int[]"));
1221         assertEquals("", ClassUtils.getPackageCanonicalName("int[][]"));
1222         
1223         // Inner types
1224         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtilsTest$6"));
1225         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtilsTest$5Named"));
1226         assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtilsTest$Inner"));
1227     }
1228 
1229     @Test
1230     public void testHierarchyIncludingInterfaces() {
1231         final Iterator<Class<?>> iter =
1232             ClassUtils.hierarchy(StringParameterizedChild.class, Interfaces.INCLUDE).iterator();
1233         assertEquals(StringParameterizedChild.class, iter.next());
1234         assertEquals(GenericParent.class, iter.next());
1235         assertEquals(GenericConsumer.class, iter.next());
1236         assertEquals(Object.class, iter.next());
1237         assertFalse(iter.hasNext());
1238     }
1239 
1240     @Test
1241     public void testHierarchyExcludingInterfaces() {
1242         final Iterator<Class<?>> iter = ClassUtils.hierarchy(StringParameterizedChild.class).iterator();
1243         assertEquals(StringParameterizedChild.class, iter.next());
1244         assertEquals(GenericParent.class, iter.next());
1245         assertEquals(Object.class, iter.next());
1246         assertFalse(iter.hasNext());
1247     }
1248 }