Format: Remove extra whitespace around parameters.

Longer lines.
This commit is contained in:
Gary Gregory 2022-06-13 18:01:24 -04:00
parent 2b13f5b9fd
commit 4b9c1a03cf
1 changed files with 121 additions and 143 deletions

View File

@ -100,8 +100,7 @@ public class ClassUtilsTest {
} }
private void assertGetClassThrowsException(final String className, final Class<? extends Exception> exceptionType) { private void assertGetClassThrowsException(final String className, final Class<? extends Exception> exceptionType) {
assertThrows(exceptionType, assertThrows(exceptionType, () -> ClassUtils.getClass(className),
() -> ClassUtils.getClass(className),
"ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\"."); "ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\".");
} }
@ -127,9 +126,7 @@ public class ClassUtilsTest {
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element @SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
final List<Object> olist = (List<Object>) (List<?>) list; final List<Object> olist = (List<Object>) (List<?>) list;
olist.add(new Object()); olist.add(new Object());
assertThrows(ClassCastException.class, assertThrows(ClassCastException.class, () -> ClassUtils.convertClassesToClassNames(list), "Should not have been able to convert list");
() -> ClassUtils.convertClassesToClassNames(list),
"Should not have been able to convert list");
assertNull(ClassUtils.convertClassesToClassNames(null)); 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 @SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
final List<Object> olist = (List<Object>) (List<?>) list; final List<Object> olist = (List<Object>) (List<?>) list;
olist.add(new Object()); olist.add(new Object());
assertThrows(ClassCastException.class, assertThrows(ClassCastException.class, () -> ClassUtils.convertClassNamesToClasses(list), "Should not have been able to convert list");
() -> ClassUtils.convertClassNamesToClasses(list),
"Should not have been able to convert list");
assertNull(ClassUtils.convertClassNamesToClasses(null)); assertNull(ClassUtils.convertClassNamesToClasses(null));
} }
@ -188,8 +183,7 @@ public class ClassUtilsTest {
assertEquals("j.l.String", ClassUtils.getAbbreviatedName("java.lang.String", 1)); 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("o.a.c.l.ClassUtils", ClassUtils.getAbbreviatedName("org.apache.commons.lang3.ClassUtils", 18));
assertEquals("org.apache.commons.lang3.ClassUtils", assertEquals("org.apache.commons.lang3.ClassUtils",
ClassUtils.getAbbreviatedName("org.apache.commons.lang3.ClassUtils", ClassUtils.getAbbreviatedName("org.apache.commons.lang3.ClassUtils", "org.apache.commons.lang3.ClassUtils".length()));
"org.apache.commons.lang3.ClassUtils".length()));
assertEquals("o.a.c.l.ClassUtils", ClassUtils.getAbbreviatedName("o.a.c.l.ClassUtils", 18)); 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("o..c.l.ClassUtils", ClassUtils.getAbbreviatedName("o..c.l.ClassUtils", 18));
assertEquals(".", ClassUtils.getAbbreviatedName(".", 18)); assertEquals(".", ClassUtils.getAbbreviatedName(".", 18));
@ -205,9 +199,9 @@ public class ClassUtilsTest {
} }
/** /**
* Test that in case the required length is larger than the name and thus there is no need for any shortening * Test that in case the required length is larger than the name and thus there is no need for any shortening then the
* then the returned string object is the same as the one passed as argument. Note, however, that this is * returned string object is the same as the one passed as argument. Note, however, that this is tested as an internal
* tested as an internal implementation detail, but it is not a guaranteed feature of the implementation. * implementation detail, but it is not a guaranteed feature of the implementation.
*/ */
@Test @Test
@DisplayName("When the length hint is longer than the actual length then the same String object is returned") @DisplayName("When the length hint is longer than the actual length then the same String object is returned")
@ -435,16 +429,11 @@ public class ClassUtilsTest {
@Test @Test
public void test_getPackageCanonicalName_String() { public void test_getPackageCanonicalName_String() {
assertEquals("org.apache.commons.lang3", assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils"));
ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils")); assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;"));
assertEquals("org.apache.commons.lang3", assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("[[Lorg.apache.commons.lang3.ClassUtils;"));
ClassUtils.getPackageCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;")); assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[]"));
assertEquals("org.apache.commons.lang3", assertEquals("org.apache.commons.lang3", ClassUtils.getPackageCanonicalName("org.apache.commons.lang3.ClassUtils[][]"));
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("[[I")); assertEquals("", ClassUtils.getPackageCanonicalName("[[I"));
assertEquals("", ClassUtils.getPackageCanonicalName("int[]")); assertEquals("", ClassUtils.getPackageCanonicalName("int[]"));
@ -570,15 +559,18 @@ public class ClassUtilsTest {
assertEquals("int[]", int[].class.getCanonicalName()); assertEquals("int[]", int[].class.getCanonicalName());
assertEquals("[I", int[].class.getName()); 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 // WARNING: this is fragile, implementation may change, naming is not guaranteed
assertEquals("ClassUtilsTest.6", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$6")); assertEquals("ClassUtilsTest.6", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$6"));
// WARNING: this is fragile, implementation may change, naming is not guaranteed // WARNING: this is fragile, implementation may change, naming is not guaranteed
assertEquals("ClassUtilsTest.5Named", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$5Named")); assertEquals("ClassUtilsTest.5Named", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$5Named"));
assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$Inner")); 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 // 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()); assertEquals("org.apache.commons.lang3.ClassUtilsTest$10", new org.apache.commons.lang3.ClassUtilsTest() {
assertNull(new org.apache.commons.lang3.ClassUtilsTest(){}.getClass().getCanonicalName()); }.getClass().getName());
assertNull(new org.apache.commons.lang3.ClassUtilsTest() {
}.getClass().getCanonicalName());
} }
@Test @Test
@ -1297,8 +1289,7 @@ public class ClassUtilsTest {
@Test @Test
public void testHierarchyIncludingInterfaces() { public void testHierarchyIncludingInterfaces() {
final Iterator<Class<?>> iter = final Iterator<Class<?>> iter = ClassUtils.hierarchy(StringParameterizedChild.class, Interfaces.INCLUDE).iterator();
ClassUtils.hierarchy(StringParameterizedChild.class, Interfaces.INCLUDE).iterator();
assertEquals(StringParameterizedChild.class, iter.next()); assertEquals(StringParameterizedChild.class, iter.next());
assertEquals(GenericParent.class, iter.next()); assertEquals(GenericParent.class, iter.next());
assertEquals(GenericConsumer.class, iter.next()); assertEquals(GenericConsumer.class, iter.next());
@ -1378,15 +1369,11 @@ public class ClassUtilsTest {
final Class<?>[] castNull = ClassUtils.primitivesToWrappers((Class<?>) null); // == new Class<?>[]{null} 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 // test empty array is returned unchanged
assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY), assertArrayEquals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers(ArrayUtils.EMPTY_CLASS_ARRAY), "empty -> empty");
"empty -> empty");
// test an array of various classes // test an array of various classes
final Class<?>[] primitives = new Class[] { final Class<?>[] primitives = new Class[] {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Double.TYPE, Float.TYPE,
Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, String.class, ClassUtils.class};
Integer.TYPE, Long.TYPE, Double.TYPE, Float.TYPE,
String.class, ClassUtils.class
};
final Class<?>[] wrappers = ClassUtils.primitivesToWrappers(primitives); final Class<?>[] wrappers = ClassUtils.primitivesToWrappers(primitives);
for (int i = 0; i < primitives.length; i++) { for (int i = 0; i < primitives.length; i++) {
@ -1398,9 +1385,7 @@ public class ClassUtilsTest {
} }
// test an array of no primitive classes // test an array of no primitive classes
final Class<?>[] noPrimitives = new Class[] { final Class<?>[] noPrimitives = new Class[] {String.class, ClassUtils.class, Void.TYPE};
String.class, ClassUtils.class, Void.TYPE
};
// This used to return the exact same array, but no longer does. // This used to return the exact same array, but no longer does.
assertNotSame(noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives), "unmodified"); assertNotSame(noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives), "unmodified");
} }
@ -1420,8 +1405,7 @@ public class ClassUtilsTest {
// test a few other classes // test a few other classes
assertEquals(String.class, ClassUtils.primitiveToWrapper(String.class), "String.class -> String.class"); assertEquals(String.class, ClassUtils.primitiveToWrapper(String.class), "String.class -> String.class");
assertEquals(ClassUtils.class, ClassUtils.primitiveToWrapper(ClassUtils.class), assertEquals(ClassUtils.class, ClassUtils.primitiveToWrapper(ClassUtils.class), "ClassUtils.class -> ClassUtils.class");
"ClassUtils.class -> ClassUtils.class");
assertEquals(Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE), "Void.TYPE -> Void.TYPE"); assertEquals(Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE), "Void.TYPE -> Void.TYPE");
// test null // test null
@ -1466,11 +1450,8 @@ public class ClassUtilsTest {
@Test @Test
public void testWrappersToPrimitives() { public void testWrappersToPrimitives() {
// an array with classes to test // an array with classes to test
final Class<?>[] classes = { final Class<?>[] classes = {Boolean.class, Byte.class, Character.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class,
Boolean.class, Byte.class, Character.class, Short.class, ClassUtils.class, null};
Integer.class, Long.class, Float.class, Double.class,
String.class, ClassUtils.class, null
};
final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes); final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
// now test the result // now test the result
@ -1500,10 +1481,7 @@ public class ClassUtilsTest {
@Test @Test
public void testWrapperToPrimitive() { public void testWrapperToPrimitive() {
// an array with classes to convert // an array with classes to convert
final Class<?>[] primitives = { final Class<?>[] primitives = {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE};
Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE
};
for (final Class<?> primitive : primitives) { for (final Class<?> primitive : primitives) {
final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive); final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
assertFalse(wrapperCls.isPrimitive(), "Still primitive"); assertFalse(wrapperCls.isPrimitive(), "Still primitive");