Format: Remove extra whitespace around parameters.
Longer lines.
This commit is contained in:
parent
2b13f5b9fd
commit
4b9c1a03cf
|
@ -91,22 +91,21 @@ public class ClassUtilsTest {
|
|||
}
|
||||
}
|
||||
|
||||
private void assertGetClassReturnsClass( final Class<?> c ) throws Exception {
|
||||
assertEquals( c, ClassUtils.getClass( c.getName() ) );
|
||||
private void assertGetClassReturnsClass(final Class<?> c) throws Exception {
|
||||
assertEquals(c, ClassUtils.getClass(c.getName()));
|
||||
}
|
||||
|
||||
private void assertGetClassThrowsClassNotFound( final String className ) {
|
||||
assertGetClassThrowsException( className, ClassNotFoundException.class );
|
||||
private void assertGetClassThrowsClassNotFound(final String className) {
|
||||
assertGetClassThrowsException(className, ClassNotFoundException.class);
|
||||
}
|
||||
|
||||
private void assertGetClassThrowsException(final String className, final Class<? extends Exception> exceptionType) {
|
||||
assertThrows(exceptionType,
|
||||
() -> ClassUtils.getClass(className),
|
||||
"ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\"." );
|
||||
assertThrows(exceptionType, () -> ClassUtils.getClass(className),
|
||||
"ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\".");
|
||||
}
|
||||
|
||||
private void assertGetClassThrowsNullPointerException( final String className ) {
|
||||
assertGetClassThrowsException( className, NullPointerException.class );
|
||||
private void assertGetClassThrowsNullPointerException(final String className) {
|
||||
assertGetClassThrowsException(className, NullPointerException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -127,9 +126,7 @@ public class ClassUtilsTest {
|
|||
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
||||
final List<Object> olist = (List<Object>) (List<?>) list;
|
||||
olist.add(new Object());
|
||||
assertThrows(ClassCastException.class,
|
||||
() -> ClassUtils.convertClassesToClassNames(list),
|
||||
"Should not have been able to convert list");
|
||||
assertThrows(ClassCastException.class, () -> ClassUtils.convertClassesToClassNames(list), "Should not have been able to convert list");
|
||||
assertNull(ClassUtils.convertClassesToClassNames(null));
|
||||
}
|
||||
|
||||
|
@ -151,9 +148,7 @@ public class ClassUtilsTest {
|
|||
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
||||
final List<Object> olist = (List<Object>) (List<?>) list;
|
||||
olist.add(new Object());
|
||||
assertThrows(ClassCastException.class,
|
||||
() -> ClassUtils.convertClassNamesToClasses(list),
|
||||
"Should not have been able to convert list");
|
||||
assertThrows(ClassCastException.class, () -> ClassUtils.convertClassNamesToClasses(list), "Should not have been able to convert list");
|
||||
assertNull(ClassUtils.convertClassNamesToClasses(null));
|
||||
}
|
||||
|
||||
|
@ -188,8 +183,7 @@ public class ClassUtilsTest {
|
|||
assertEquals("j.l.String", ClassUtils.getAbbreviatedName("java.lang.String", 1));
|
||||
assertEquals("o.a.c.l.ClassUtils", ClassUtils.getAbbreviatedName("org.apache.commons.lang3.ClassUtils", 18));
|
||||
assertEquals("org.apache.commons.lang3.ClassUtils",
|
||||
ClassUtils.getAbbreviatedName("org.apache.commons.lang3.ClassUtils",
|
||||
"org.apache.commons.lang3.ClassUtils".length()));
|
||||
ClassUtils.getAbbreviatedName("org.apache.commons.lang3.ClassUtils", "org.apache.commons.lang3.ClassUtils".length()));
|
||||
assertEquals("o.a.c.l.ClassUtils", ClassUtils.getAbbreviatedName("o.a.c.l.ClassUtils", 18));
|
||||
assertEquals("o..c.l.ClassUtils", ClassUtils.getAbbreviatedName("o..c.l.ClassUtils", 18));
|
||||
assertEquals(".", ClassUtils.getAbbreviatedName(".", 18));
|
||||
|
@ -205,15 +199,15 @@ public class ClassUtilsTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that in case the required length is larger than the name and thus there is no need for any shortening
|
||||
* then the returned string object is the same as the one passed as argument. Note, however, that this is
|
||||
* tested as an internal implementation detail, but it is not a guaranteed feature of the implementation.
|
||||
* Test that in case the required length is larger than the name and thus there is no need for any shortening then the
|
||||
* returned string object is the same as the one passed as argument. Note, however, that this is tested as an internal
|
||||
* implementation detail, but it is not a guaranteed feature of the implementation.
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("When the length hint is longer than the actual length then the same String object is returned")
|
||||
public void test_getAbbreviatedName_TooLongHint(){
|
||||
public void test_getAbbreviatedName_TooLongHint() {
|
||||
final String className = "java.lang.String";
|
||||
Assertions.assertSame(className, ClassUtils.getAbbreviatedName(className, className.length()+1));
|
||||
Assertions.assertSame(className, ClassUtils.getAbbreviatedName(className, className.length() + 1));
|
||||
Assertions.assertSame(className, ClassUtils.getAbbreviatedName(className, className.length()));
|
||||
}
|
||||
|
||||
|
@ -435,16 +429,11 @@ public class ClassUtilsTest {
|
|||
|
||||
@Test
|
||||
public void test_getPackageCanonicalName_String() {
|
||||
assertEquals("org.apache.commons.lang3",
|
||||
ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils"));
|
||||
assertEquals("org.apache.commons.lang3",
|
||||
ClassUtils.getPackageCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;"));
|
||||
assertEquals("org.apache.commons.lang3",
|
||||
ClassUtils.getPackageCanonicalName("[[Lorg.apache.commons.lang3.ClassUtils;"));
|
||||
assertEquals("org.apache.commons.lang3",
|
||||
ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[]"));
|
||||
assertEquals("org.apache.commons.lang3",
|
||||
ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[][]"));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils"));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;"));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("[[Lorg.apache.commons.lang3.ClassUtils;"));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[]"));
|
||||
assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[][]"));
|
||||
assertEquals("", ClassUtils.getPackageCanonicalName("[I"));
|
||||
assertEquals("", ClassUtils.getPackageCanonicalName("[[I"));
|
||||
assertEquals("", ClassUtils.getPackageCanonicalName("int[]"));
|
||||
|
@ -570,15 +559,18 @@ public class ClassUtilsTest {
|
|||
assertEquals("int[]", int[].class.getCanonicalName());
|
||||
assertEquals("[I", int[].class.getName());
|
||||
|
||||
// Inner types... the problem is that these are not canonical names, classes with this name do not even have canonical name
|
||||
// Inner types... the problem is that these are not canonical names, classes with this name do not even have canonical
|
||||
// name
|
||||
// WARNING: this is fragile, implementation may change, naming is not guaranteed
|
||||
assertEquals("ClassUtilsTest.6", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$6"));
|
||||
// WARNING: this is fragile, implementation may change, naming is not guaranteed
|
||||
assertEquals("ClassUtilsTest.5Named", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$5Named"));
|
||||
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$Inner"));
|
||||
// demonstrating what a canonical name is... it is a bigger issue to clean this up
|
||||
assertEquals("org.apache.commons.lang3.ClassUtilsTest$10", new org.apache.commons.lang3.ClassUtilsTest(){}.getClass().getName());
|
||||
assertNull(new org.apache.commons.lang3.ClassUtilsTest(){}.getClass().getCanonicalName());
|
||||
assertEquals("org.apache.commons.lang3.ClassUtilsTest$10", new org.apache.commons.lang3.ClassUtilsTest() {
|
||||
}.getClass().getName());
|
||||
assertNull(new org.apache.commons.lang3.ClassUtilsTest() {
|
||||
}.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -776,8 +768,8 @@ public class ClassUtilsTest {
|
|||
final Class<?>[] array1 = new Class[] {Object.class};
|
||||
final Class<?>[] array1s = new Class[] {String.class};
|
||||
final Class<?>[] array0 = new Class[] {};
|
||||
final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
final Class<?>[] arrayPrimitives = {Integer.TYPE, Boolean.TYPE};
|
||||
final Class<?>[] arrayWrappers = {Integer.class, Boolean.class};
|
||||
|
||||
assertFalse(ClassUtils.isAssignable(array1, array2));
|
||||
assertFalse(ClassUtils.isAssignable(null, array2));
|
||||
|
@ -804,8 +796,8 @@ public class ClassUtilsTest {
|
|||
final Class<?>[] array1 = new Class[] {Object.class};
|
||||
final Class<?>[] array1s = new Class[] {String.class};
|
||||
final Class<?>[] array0 = new Class[] {};
|
||||
final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
final Class<?>[] arrayPrimitives = {Integer.TYPE, Boolean.TYPE};
|
||||
final Class<?>[] arrayWrappers = {Integer.class, Boolean.class};
|
||||
|
||||
assertFalse(ClassUtils.isAssignable(array1, array2, true));
|
||||
assertFalse(ClassUtils.isAssignable(null, array2, true));
|
||||
|
@ -832,8 +824,8 @@ public class ClassUtilsTest {
|
|||
final Class<?>[] array1 = new Class[] {Object.class};
|
||||
final Class<?>[] array1s = new Class[] {String.class};
|
||||
final Class<?>[] array0 = new Class[] {};
|
||||
final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
final Class<?>[] arrayPrimitives = {Integer.TYPE, Boolean.TYPE};
|
||||
final Class<?>[] arrayWrappers = {Integer.class, Boolean.class};
|
||||
|
||||
assertFalse(ClassUtils.isAssignable(array1, array2, false));
|
||||
assertFalse(ClassUtils.isAssignable(null, array2, false));
|
||||
|
@ -1169,89 +1161,89 @@ public class ClassUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testGetClassByNormalNameArrays() throws ClassNotFoundException {
|
||||
assertEquals( int[].class, ClassUtils.getClass( "int[]" ) );
|
||||
assertEquals( long[].class, ClassUtils.getClass( "long[]" ) );
|
||||
assertEquals( short[].class, ClassUtils.getClass( "short[]" ) );
|
||||
assertEquals( byte[].class, ClassUtils.getClass( "byte[]" ) );
|
||||
assertEquals( char[].class, ClassUtils.getClass( "char[]" ) );
|
||||
assertEquals( float[].class, ClassUtils.getClass( "float[]" ) );
|
||||
assertEquals( double[].class, ClassUtils.getClass( "double[]" ) );
|
||||
assertEquals( boolean[].class, ClassUtils.getClass( "boolean[]" ) );
|
||||
assertEquals( String[].class, ClassUtils.getClass( "java.lang.String[]" ) );
|
||||
assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "java.util.Map.Entry[]" ) );
|
||||
assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "java.util.Map$Entry[]" ) );
|
||||
assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "[Ljava.util.Map.Entry;" ) );
|
||||
assertEquals( java.util.Map.Entry[].class, ClassUtils.getClass( "[Ljava.util.Map$Entry;" ) );
|
||||
assertEquals(int[].class, ClassUtils.getClass("int[]"));
|
||||
assertEquals(long[].class, ClassUtils.getClass("long[]"));
|
||||
assertEquals(short[].class, ClassUtils.getClass("short[]"));
|
||||
assertEquals(byte[].class, ClassUtils.getClass("byte[]"));
|
||||
assertEquals(char[].class, ClassUtils.getClass("char[]"));
|
||||
assertEquals(float[].class, ClassUtils.getClass("float[]"));
|
||||
assertEquals(double[].class, ClassUtils.getClass("double[]"));
|
||||
assertEquals(boolean[].class, ClassUtils.getClass("boolean[]"));
|
||||
assertEquals(String[].class, ClassUtils.getClass("java.lang.String[]"));
|
||||
assertEquals(java.util.Map.Entry[].class, ClassUtils.getClass("java.util.Map.Entry[]"));
|
||||
assertEquals(java.util.Map.Entry[].class, ClassUtils.getClass("java.util.Map$Entry[]"));
|
||||
assertEquals(java.util.Map.Entry[].class, ClassUtils.getClass("[Ljava.util.Map.Entry;"));
|
||||
assertEquals(java.util.Map.Entry[].class, ClassUtils.getClass("[Ljava.util.Map$Entry;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassByNormalNameArrays2D() throws ClassNotFoundException {
|
||||
assertEquals( int[][].class, ClassUtils.getClass( "int[][]" ) );
|
||||
assertEquals( long[][].class, ClassUtils.getClass( "long[][]" ) );
|
||||
assertEquals( short[][].class, ClassUtils.getClass( "short[][]" ) );
|
||||
assertEquals( byte[][].class, ClassUtils.getClass( "byte[][]" ) );
|
||||
assertEquals( char[][].class, ClassUtils.getClass( "char[][]" ) );
|
||||
assertEquals( float[][].class, ClassUtils.getClass( "float[][]" ) );
|
||||
assertEquals( double[][].class, ClassUtils.getClass( "double[][]" ) );
|
||||
assertEquals( boolean[][].class, ClassUtils.getClass( "boolean[][]" ) );
|
||||
assertEquals( String[][].class, ClassUtils.getClass( "java.lang.String[][]" ) );
|
||||
assertEquals(int[][].class, ClassUtils.getClass("int[][]"));
|
||||
assertEquals(long[][].class, ClassUtils.getClass("long[][]"));
|
||||
assertEquals(short[][].class, ClassUtils.getClass("short[][]"));
|
||||
assertEquals(byte[][].class, ClassUtils.getClass("byte[][]"));
|
||||
assertEquals(char[][].class, ClassUtils.getClass("char[][]"));
|
||||
assertEquals(float[][].class, ClassUtils.getClass("float[][]"));
|
||||
assertEquals(double[][].class, ClassUtils.getClass("double[][]"));
|
||||
assertEquals(boolean[][].class, ClassUtils.getClass("boolean[][]"));
|
||||
assertEquals(String[][].class, ClassUtils.getClass("java.lang.String[][]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassClassNotFound() throws Exception {
|
||||
assertGetClassThrowsClassNotFound( "bool" );
|
||||
assertGetClassThrowsClassNotFound( "bool[]" );
|
||||
assertGetClassThrowsClassNotFound( "integer[]" );
|
||||
assertGetClassThrowsClassNotFound("bool");
|
||||
assertGetClassThrowsClassNotFound("bool[]");
|
||||
assertGetClassThrowsClassNotFound("integer[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassInvalidArguments() throws Exception {
|
||||
assertGetClassThrowsNullPointerException( null );
|
||||
assertGetClassThrowsClassNotFound( "[][][]" );
|
||||
assertGetClassThrowsClassNotFound( "[[]" );
|
||||
assertGetClassThrowsClassNotFound( "[" );
|
||||
assertGetClassThrowsClassNotFound( "java.lang.String][" );
|
||||
assertGetClassThrowsClassNotFound( ".hello.world" );
|
||||
assertGetClassThrowsClassNotFound( "hello..world" );
|
||||
assertGetClassThrowsNullPointerException(null);
|
||||
assertGetClassThrowsClassNotFound("[][][]");
|
||||
assertGetClassThrowsClassNotFound("[[]");
|
||||
assertGetClassThrowsClassNotFound("[");
|
||||
assertGetClassThrowsClassNotFound("java.lang.String][");
|
||||
assertGetClassThrowsClassNotFound(".hello.world");
|
||||
assertGetClassThrowsClassNotFound("hello..world");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassRawPrimitives() throws ClassNotFoundException {
|
||||
assertEquals( int.class, ClassUtils.getClass( "int" ) );
|
||||
assertEquals( long.class, ClassUtils.getClass( "long" ) );
|
||||
assertEquals( short.class, ClassUtils.getClass( "short" ) );
|
||||
assertEquals( byte.class, ClassUtils.getClass( "byte" ) );
|
||||
assertEquals( char.class, ClassUtils.getClass( "char" ) );
|
||||
assertEquals( float.class, ClassUtils.getClass( "float" ) );
|
||||
assertEquals( double.class, ClassUtils.getClass( "double" ) );
|
||||
assertEquals( boolean.class, ClassUtils.getClass( "boolean" ) );
|
||||
assertEquals( void.class, ClassUtils.getClass( "void" ) );
|
||||
assertEquals(int.class, ClassUtils.getClass("int"));
|
||||
assertEquals(long.class, ClassUtils.getClass("long"));
|
||||
assertEquals(short.class, ClassUtils.getClass("short"));
|
||||
assertEquals(byte.class, ClassUtils.getClass("byte"));
|
||||
assertEquals(char.class, ClassUtils.getClass("char"));
|
||||
assertEquals(float.class, ClassUtils.getClass("float"));
|
||||
assertEquals(double.class, ClassUtils.getClass("double"));
|
||||
assertEquals(boolean.class, ClassUtils.getClass("boolean"));
|
||||
assertEquals(void.class, ClassUtils.getClass("void"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassWithArrayClasses() throws Exception {
|
||||
assertGetClassReturnsClass( String[].class );
|
||||
assertGetClassReturnsClass( int[].class );
|
||||
assertGetClassReturnsClass( long[].class );
|
||||
assertGetClassReturnsClass( short[].class );
|
||||
assertGetClassReturnsClass( byte[].class );
|
||||
assertGetClassReturnsClass( char[].class );
|
||||
assertGetClassReturnsClass( float[].class );
|
||||
assertGetClassReturnsClass( double[].class );
|
||||
assertGetClassReturnsClass( boolean[].class );
|
||||
assertGetClassReturnsClass(String[].class);
|
||||
assertGetClassReturnsClass(int[].class);
|
||||
assertGetClassReturnsClass(long[].class);
|
||||
assertGetClassReturnsClass(short[].class);
|
||||
assertGetClassReturnsClass(byte[].class);
|
||||
assertGetClassReturnsClass(char[].class);
|
||||
assertGetClassReturnsClass(float[].class);
|
||||
assertGetClassReturnsClass(double[].class);
|
||||
assertGetClassReturnsClass(boolean[].class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassWithArrayClasses2D() throws Exception {
|
||||
assertGetClassReturnsClass( String[][].class );
|
||||
assertGetClassReturnsClass( int[][].class );
|
||||
assertGetClassReturnsClass( long[][].class );
|
||||
assertGetClassReturnsClass( short[][].class );
|
||||
assertGetClassReturnsClass( byte[][].class );
|
||||
assertGetClassReturnsClass( char[][].class );
|
||||
assertGetClassReturnsClass( float[][].class );
|
||||
assertGetClassReturnsClass( double[][].class );
|
||||
assertGetClassReturnsClass( boolean[][].class );
|
||||
assertGetClassReturnsClass(String[][].class);
|
||||
assertGetClassReturnsClass(int[][].class);
|
||||
assertGetClassReturnsClass(long[][].class);
|
||||
assertGetClassReturnsClass(short[][].class);
|
||||
assertGetClassReturnsClass(byte[][].class);
|
||||
assertGetClassReturnsClass(char[][].class);
|
||||
assertGetClassReturnsClass(float[][].class);
|
||||
assertGetClassReturnsClass(double[][].class);
|
||||
assertGetClassReturnsClass(boolean[][].class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1267,10 +1259,10 @@ public class ClassUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testGetInnerClass() throws ClassNotFoundException {
|
||||
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner.DeeplyNested" ) );
|
||||
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest.Inner$DeeplyNested" ) );
|
||||
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest$Inner$DeeplyNested" ) );
|
||||
assertEquals( Inner.DeeplyNested.class, ClassUtils.getClass( "org.apache.commons.lang3.ClassUtilsTest$Inner.DeeplyNested" ) );
|
||||
assertEquals(Inner.DeeplyNested.class, ClassUtils.getClass("org.apache.commons.lang3.ClassUtilsTest.Inner.DeeplyNested"));
|
||||
assertEquals(Inner.DeeplyNested.class, ClassUtils.getClass("org.apache.commons.lang3.ClassUtilsTest.Inner$DeeplyNested"));
|
||||
assertEquals(Inner.DeeplyNested.class, ClassUtils.getClass("org.apache.commons.lang3.ClassUtilsTest$Inner$DeeplyNested"));
|
||||
assertEquals(Inner.DeeplyNested.class, ClassUtils.getClass("org.apache.commons.lang3.ClassUtilsTest$Inner.DeeplyNested"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1297,8 +1289,7 @@ public class ClassUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testHierarchyIncludingInterfaces() {
|
||||
final Iterator<Class<?>> iter =
|
||||
ClassUtils.hierarchy(StringParameterizedChild.class, Interfaces.INCLUDE).iterator();
|
||||
final Iterator<Class<?>> iter = ClassUtils.hierarchy(StringParameterizedChild.class, Interfaces.INCLUDE).iterator();
|
||||
assertEquals(StringParameterizedChild.class, iter.next());
|
||||
assertEquals(GenericParent.class, iter.next());
|
||||
assertEquals(GenericConsumer.class, iter.next());
|
||||
|
@ -1376,20 +1367,16 @@ public class ClassUtilsTest {
|
|||
// Other possible casts for null
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(), "empty -> empty");
|
||||
final Class<?>[] castNull = ClassUtils.primitivesToWrappers((Class<?>) null); // == new Class<?>[]{null}
|
||||
assertArrayEquals(new Class<?>[]{null}, castNull, "(Class<?>) null -> [null]");
|
||||
assertArrayEquals(new Class<?>[] {null}, castNull, "(Class<?>) null -> [null]");
|
||||
// test empty array is returned unchanged
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY),
|
||||
"empty -> empty");
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY), "empty -> empty");
|
||||
|
||||
// test an array of various classes
|
||||
final Class<?>[] primitives = new Class[] {
|
||||
Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
|
||||
Integer.TYPE, Long.TYPE, Double.TYPE, Float.TYPE,
|
||||
String.class, ClassUtils.class
|
||||
};
|
||||
final Class<?>[] wrappers= ClassUtils.primitivesToWrappers(primitives);
|
||||
final Class<?>[] primitives = new Class[] {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Double.TYPE, Float.TYPE,
|
||||
String.class, ClassUtils.class};
|
||||
final Class<?>[] wrappers = ClassUtils.primitivesToWrappers(primitives);
|
||||
|
||||
for (int i=0; i < primitives.length; i++) {
|
||||
for (int i = 0; i < primitives.length; i++) {
|
||||
// test each returned wrapper
|
||||
final Class<?> primitive = primitives[i];
|
||||
final Class<?> expectedWrapper = ClassUtils.primitiveToWrapper(primitive);
|
||||
|
@ -1398,9 +1385,7 @@ public class ClassUtilsTest {
|
|||
}
|
||||
|
||||
// test an array of no primitive classes
|
||||
final Class<?>[] noPrimitives = new Class[] {
|
||||
String.class, ClassUtils.class, Void.TYPE
|
||||
};
|
||||
final Class<?>[] noPrimitives = new Class[] {String.class, ClassUtils.class, Void.TYPE};
|
||||
// This used to return the exact same array, but no longer does.
|
||||
assertNotSame(noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives), "unmodified");
|
||||
}
|
||||
|
@ -1420,8 +1405,7 @@ public class ClassUtilsTest {
|
|||
|
||||
// test a few other classes
|
||||
assertEquals(String.class, ClassUtils.primitiveToWrapper(String.class), "String.class -> String.class");
|
||||
assertEquals(ClassUtils.class, ClassUtils.primitiveToWrapper(ClassUtils.class),
|
||||
"ClassUtils.class -> ClassUtils.class");
|
||||
assertEquals(ClassUtils.class, ClassUtils.primitiveToWrapper(ClassUtils.class), "ClassUtils.class -> ClassUtils.class");
|
||||
assertEquals(Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE), "Void.TYPE -> Void.TYPE");
|
||||
|
||||
// test null
|
||||
|
@ -1446,31 +1430,28 @@ public class ClassUtilsTest {
|
|||
// Additional varargs tests
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass(), "empty -> empty");
|
||||
final Class<?>[] castNull = ClassUtils.toClass((Object) null); // == new Object[]{null}
|
||||
assertArrayEquals(new Object[]{null}, castNull, "(Object) null -> [null]");
|
||||
assertArrayEquals(new Object[] {null}, castNull, "(Object) null -> [null]");
|
||||
|
||||
assertSame(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass(ArrayUtils.EMPTY_OBJECT_ARRAY));
|
||||
|
||||
assertArrayEquals(new Class[]{String.class, Integer.class, Double.class}, ClassUtils.toClass("Test", Integer.valueOf(1), Double.valueOf(99d)));
|
||||
assertArrayEquals(new Class[] {String.class, Integer.class, Double.class}, ClassUtils.toClass("Test", Integer.valueOf(1), Double.valueOf(99d)));
|
||||
|
||||
assertArrayEquals(new Class[]{String.class, null, Double.class}, ClassUtils.toClass("Test", null, Double.valueOf(99d)));
|
||||
assertArrayEquals(new Class[] {String.class, null, Double.class}, ClassUtils.toClass("Test", null, Double.valueOf(99d)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithInterleavingWhitespace() throws ClassNotFoundException {
|
||||
assertEquals( int[].class, ClassUtils.getClass( " int [ ] " ) );
|
||||
assertEquals( long[].class, ClassUtils.getClass( "\rlong\t[\n]\r" ) );
|
||||
assertEquals( short[].class, ClassUtils.getClass( "\tshort \t\t[]" ) );
|
||||
assertEquals( byte[].class, ClassUtils.getClass( "byte[\t\t\n\r] " ) );
|
||||
assertEquals(int[].class, ClassUtils.getClass(" int [ ] "));
|
||||
assertEquals(long[].class, ClassUtils.getClass("\rlong\t[\n]\r"));
|
||||
assertEquals(short[].class, ClassUtils.getClass("\tshort \t\t[]"));
|
||||
assertEquals(byte[].class, ClassUtils.getClass("byte[\t\t\n\r] "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrappersToPrimitives() {
|
||||
// an array with classes to test
|
||||
final Class<?>[] classes = {
|
||||
Boolean.class, Byte.class, Character.class, Short.class,
|
||||
Integer.class, Long.class, Float.class, Double.class,
|
||||
String.class, ClassUtils.class, null
|
||||
};
|
||||
final Class<?>[] classes = {Boolean.class, Byte.class, Character.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class,
|
||||
ClassUtils.class, null};
|
||||
|
||||
final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
|
||||
// now test the result
|
||||
|
@ -1494,16 +1475,13 @@ public class ClassUtilsTest {
|
|||
// Other possible casts for null
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.wrappersToPrimitives(), "empty -> empty");
|
||||
final Class<?>[] castNull = ClassUtils.wrappersToPrimitives((Class<?>) null); // == new Class<?>[]{null}
|
||||
assertArrayEquals(new Class<?>[]{null}, castNull, "(Class<?>) null -> [null]");
|
||||
}
|
||||
assertArrayEquals(new Class<?>[] {null}, castNull, "(Class<?>) null -> [null]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperToPrimitive() {
|
||||
// an array with classes to convert
|
||||
final Class<?>[] primitives = {
|
||||
Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
|
||||
Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE
|
||||
};
|
||||
final Class<?>[] primitives = {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE};
|
||||
for (final Class<?> primitive : primitives) {
|
||||
final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
|
||||
assertFalse(wrapperCls.isPrimitive(), "Still primitive");
|
||||
|
|
Loading…
Reference in New Issue