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