Skip to content

Commit 09a3940

Browse files
committed
Test the Types.typeParamsOf methods
Unfortunately, Types.typeParamsOf(Type, Class) seems buggy. See commented out assertions in this commit for an example.
1 parent a5b95dc commit 09a3940

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

scijava-types/src/test/java/org/scijava/types/TypesTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static org.junit.jupiter.api.Assertions.assertEquals;
3333
import static org.junit.jupiter.api.Assertions.assertFalse;
3434
import static org.junit.jupiter.api.Assertions.assertNotEquals;
35+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3536
import static org.junit.jupiter.api.Assertions.assertNull;
3637
import static org.junit.jupiter.api.Assertions.assertSame;
3738
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -182,6 +183,28 @@ class Struct {
182183
assertSame(int[].class, paramClass);
183184
}
184185

186+
/** Tests {@link Types#typeParamsOf(Class, Class)}. */
187+
@Test
188+
public void testTypeParamsOfClass() {
189+
final Type[] argTypesRaw = Types.typeParamsOf(IntegerThing.class, Thing.class);
190+
assertEquals(1, argTypesRaw.length);
191+
assertSame(Integer.class, argTypesRaw[0]);
192+
}
193+
194+
/** Tests {@link Types#typeParamsOf(Type, Class)}. */
195+
@Test
196+
public <U extends IntegerThing> void testTypeParamsOfType() {
197+
final Type arg = new Nil<U>() {}.type();
198+
final Type[] argTypes = Types.typeParamsOf(arg, Thing.class);
199+
assertNotNull(argTypes);
200+
// FIXME: argTypes should return {Integer.class}, not {}.
201+
// In contrast, the correct result is returned by:
202+
// - Types.typeParamOf(arg, Thing.class, 0)
203+
// - Types.typeParamsOf(IntegerThing.class, Thing.class)
204+
// assertEquals(1, argTypes.length);
205+
// assertSame(Integer.class, argTypes[0]);
206+
}
207+
185208
/** Tests {@link Types#isAssignable(Type, Type)}. */
186209
@Test
187210
public void testIsAssignable() {

0 commit comments

Comments
 (0)