|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
20 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; |
21 | 21 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
22 | 23 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
23 | 24 | import static org.junit.jupiter.api.Assertions.assertNull; |
24 | 25 | import static org.junit.jupiter.api.Assertions.assertThrows; |
@@ -444,14 +445,18 @@ void testDetermineTypeVariableAssignments() throws NoSuchFieldException { |
444 | 445 | () -> TypeUtils.determineTypeArguments(null, iterableType)); |
445 | 446 | } |
446 | 447 |
|
| 448 | + @SuppressWarnings("unlikely-arg-type") |
447 | 449 | @Test |
448 | 450 | void testGenericArrayType() throws NoSuchFieldException { |
449 | 451 | 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())); |
453 | 454 | assertTrue(TypeUtils.equals(expected, actual)); |
454 | 455 | 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())); |
455 | 460 | } |
456 | 461 |
|
457 | 462 | @Test |
@@ -1008,13 +1013,21 @@ void testParameterizeVarArgsNullPointerException() { |
1008 | 1013 | assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(null)); |
1009 | 1014 | } |
1010 | 1015 |
|
| 1016 | + @SuppressWarnings("unlikely-arg-type") |
1011 | 1017 | @Test |
1012 | 1018 | void testParameterizeWithOwner() throws NoSuchFieldException { |
1013 | 1019 | final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class); |
1014 | 1020 | final ParameterizedType dat2Type1 = TypeUtils.parameterizeWithOwner(owner, That.class, String.class, String.class); |
1015 | 1021 | assertTrue(TypeUtils.equals(getClass().getField("dat2").getGenericType(), dat2Type1)); |
| 1022 | + assertNotEquals(0, dat2Type1.hashCode()); |
| 1023 | + assertEquals(dat2Type1, dat2Type1); |
1016 | 1024 | final ParameterizedType dat2Type2 = TypeUtils.parameterizeWithOwner(null, That.class, String.class, String.class); |
1017 | 1025 | 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))); |
1018 | 1031 | } |
1019 | 1032 |
|
1020 | 1033 | @Test |
@@ -1107,13 +1120,18 @@ void testUnrollVariables() { |
1107 | 1120 | assertEquals("java.util.ArrayList<java.lang.String>", TypeUtils.unrollVariables(mapping, parameterizedType).getTypeName()); |
1108 | 1121 | } |
1109 | 1122 |
|
| 1123 | + @SuppressWarnings("unlikely-arg-type") |
1110 | 1124 | @Test |
1111 | 1125 | void testWildcardType() throws NoSuchFieldException { |
1112 | 1126 | final WildcardType simpleWildcard = TypeUtils.wildcardType().withUpperBounds(String.class).build(); |
1113 | 1127 | final Field cClass = AClass.class.getField("cClass"); |
1114 | 1128 | assertTrue(TypeUtils.equals(((ParameterizedType) cClass.getGenericType()).getActualTypeArguments()[0], simpleWildcard)); |
1115 | 1129 | assertEquals(String.format("? extends %s", String.class.getName()), TypeUtils.toString(simpleWildcard)); |
1116 | 1130 | 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))); |
1117 | 1135 | } |
1118 | 1136 |
|
1119 | 1137 | @Test |
|
0 commit comments