Skip to content

Commit 867ab9c

Browse files
committed
ConverterTest: Add a test for generic Collections
This is a regression test for the bug-fix in d40759d32010f86114ed099f8c425a246ad7bc3a.
1 parent ccaaa6a commit 867ab9c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/org/scijava/convert/ConverterTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@
3535
import static org.junit.Assert.assertNull;
3636
import static org.junit.Assert.assertTrue;
3737

38+
import java.lang.reflect.Field;
3839
import java.lang.reflect.Type;
3940
import java.util.ArrayList;
41+
import java.util.Collection;
4042

4143
import org.junit.Test;
44+
import org.scijava.util.ClassUtils;
45+
import org.scijava.util.GenericUtils;
4246

4347
/**
4448
* Tests individual {@link Converter}s.
@@ -49,6 +53,7 @@
4953
* </p>
5054
*
5155
* @author Mark Hiner
56+
* @author Curtis Rueden
5257
*/
5358
public class ConverterTest {
5459

@@ -83,6 +88,18 @@ public void testCanConvert() {
8388
assertTrue(nc.canConvert(Integer.class, Number.class));
8489
}
8590

91+
@SuppressWarnings("unused")
92+
private Collection<Number> collection;
93+
94+
@Test
95+
public void testCanConvertToGenericCollection() {
96+
final DefaultConverter dc = new DefaultConverter();
97+
98+
final Field destField = ClassUtils.getField(getClass(), "collection");
99+
final Type destType = GenericUtils.getFieldType(destField, getClass());
100+
assertTrue(dc.canConvert(ArrayList.class, destType));
101+
}
102+
86103
private static class NumberConverter extends AbstractConverter<Number, Number> {
87104

88105
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)