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