Skip to content

Commit 502fc65

Browse files
committed
Add missing test coverage for
org.apache.commons.lang3.reflect.TypeUtils
1 parent 74e4a6e commit 502fc65

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2223
import static org.junit.jupiter.api.Assertions.assertNotNull;
2324
import static org.junit.jupiter.api.Assertions.assertNull;
2425
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -444,14 +445,18 @@ void testDetermineTypeVariableAssignments() throws NoSuchFieldException {
444445
() -> TypeUtils.determineTypeArguments(null, iterableType));
445446
}
446447

448+
@SuppressWarnings("unlikely-arg-type")
447449
@Test
448450
void testGenericArrayType() throws NoSuchFieldException {
449451
final Type expected = getClass().getField("intWildcardComparable").getGenericType();
450-
final GenericArrayType actual =
451-
TypeUtils.genericArrayType(TypeUtils.parameterize(Comparable.class, TypeUtils.wildcardType()
452-
.withUpperBounds(Integer.class).build()));
452+
final GenericArrayType actual = TypeUtils
453+
.genericArrayType(TypeUtils.parameterize(Comparable.class, TypeUtils.wildcardType().withUpperBounds(Integer.class).build()));
453454
assertTrue(TypeUtils.equals(expected, actual));
454455
assertEquals("java.lang.Comparable<? extends java.lang.Integer>[]", actual.toString());
456+
assertNotEquals(0, actual.hashCode());
457+
assertEquals(actual, actual);
458+
assertFalse(actual.equals(null));
459+
assertFalse(actual.equals(TypeUtils.wildcardType().build()));
455460
}
456461

457462
@Test
@@ -1008,13 +1013,21 @@ void testParameterizeVarArgsNullPointerException() {
10081013
assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(null));
10091014
}
10101015

1016+
@SuppressWarnings("unlikely-arg-type")
10111017
@Test
10121018
void testParameterizeWithOwner() throws NoSuchFieldException {
10131019
final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class);
10141020
final ParameterizedType dat2Type1 = TypeUtils.parameterizeWithOwner(owner, That.class, String.class, String.class);
10151021
assertTrue(TypeUtils.equals(getClass().getField("dat2").getGenericType(), dat2Type1));
1022+
assertNotEquals(0, dat2Type1.hashCode());
1023+
assertEquals(dat2Type1, dat2Type1);
10161024
final ParameterizedType dat2Type2 = TypeUtils.parameterizeWithOwner(null, That.class, String.class, String.class);
10171025
assertEquals(That.class, dat2Type2.getRawType());
1026+
assertNotEquals(0, dat2Type2.hashCode());
1027+
assertEquals(dat2Type2, dat2Type2);
1028+
assertNotEquals(dat2Type2, dat2Type1);
1029+
assertFalse(dat2Type1.equals(null));
1030+
assertFalse(dat2Type1.equals(TypeUtils.genericArrayType(String.class)));
10181031
}
10191032

10201033
@Test
@@ -1107,13 +1120,18 @@ void testUnrollVariables() {
11071120
assertEquals("java.util.ArrayList<java.lang.String>", TypeUtils.unrollVariables(mapping, parameterizedType).getTypeName());
11081121
}
11091122

1123+
@SuppressWarnings("unlikely-arg-type")
11101124
@Test
11111125
void testWildcardType() throws NoSuchFieldException {
11121126
final WildcardType simpleWildcard = TypeUtils.wildcardType().withUpperBounds(String.class).build();
11131127
final Field cClass = AClass.class.getField("cClass");
11141128
assertTrue(TypeUtils.equals(((ParameterizedType) cClass.getGenericType()).getActualTypeArguments()[0], simpleWildcard));
11151129
assertEquals(String.format("? extends %s", String.class.getName()), TypeUtils.toString(simpleWildcard));
11161130
assertEquals(String.format("? extends %s", String.class.getName()), simpleWildcard.toString());
1131+
assertNotEquals(0, simpleWildcard.hashCode());
1132+
assertEquals(simpleWildcard, simpleWildcard);
1133+
assertFalse(simpleWildcard.equals(null));
1134+
assertFalse(simpleWildcard.equals(TypeUtils.genericArrayType(String.class)));
11171135
}
11181136

11191137
@Test

0 commit comments

Comments
 (0)