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