Skip to content

Commit 3be2646

Browse files
committed
ConversionUtilsTest: rewrite testBadObjectElements
This test is no longer applicable, at least with the current conversion logic that now handles arrays and collections as of #449 et al. There is a substantial discrepancy right now between what DefaultConverter reports as convertible via canConvert versus what it actually *does* support converting via the convert methods. But that's an issue for another day!
1 parent e9a41a4 commit 3be2646

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/test/java/org/scijava/util/ConversionUtilsTest.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
package org.scijava.util;
3131

32+
import static org.junit.Assert.assertArrayEquals;
3233
import static org.junit.Assert.assertEquals;
3334
import static org.junit.Assert.assertNotNull;
3435
import static org.junit.Assert.assertNull;
@@ -43,7 +44,6 @@
4344
import java.util.Set;
4445

4546
import org.junit.Test;
46-
import org.scijava.util.Types;
4747

4848
/**
4949
* Tests {@link ConversionUtils}.
@@ -254,23 +254,37 @@ class Struct {
254254
* and a collection.
255255
*/
256256
@Test
257-
public void testBadObjectElements() {
257+
public void testIncompatibleCollections() {
258258
class Struct {
259259

260260
private Double[] doubleArray;
261-
private List<String> stringList;
262-
@SuppressWarnings("unused")
263-
private Set<char[]> nestedArray;
261+
private List<Number> numberList;
262+
private Set<Integer[]> setOfIntegerArrays;
264263
}
265264
final Struct struct = new Struct();
266265

267-
// Test abnormal behavior for an object array
268-
setFieldValue(struct, "doubleArray", "not a double array");
269-
assertEquals(null, struct.doubleArray);
266+
// NB: DefaultConverter converts non-collection/array objects to
267+
// collection/array objects, even if some or all of the constituent elements
268+
// cannot be converted to the array/collection component/element type.
270269

271-
// Test abnormal behavior for a list
272-
setFieldValue(struct, "nestedArray", "definitely not a set of char arrays");
273-
assertNull(struct.stringList);
270+
// Test object to incompatible array type
271+
setFieldValue(struct, "doubleArray", "not a double array");
272+
assertArrayEquals(new Double[] {null}, struct.doubleArray);
273+
274+
// Test object to incompatible List type
275+
setFieldValue(struct, "numberList", "not actually a list of numbers");
276+
List<Number> expectedList = Arrays.asList((Number) null);
277+
assertEquals(expectedList, struct.numberList);
278+
279+
// Test object to incompatible Set type
280+
setFieldValue(struct, "setOfIntegerArrays", //
281+
"definitely not a set of Integer[]");
282+
assertNotNull(struct.setOfIntegerArrays);
283+
assertEquals(1, struct.setOfIntegerArrays.size());
284+
Integer[] singleton = struct.setOfIntegerArrays.iterator().next();
285+
assertNotNull(singleton);
286+
assertEquals(1, singleton.length);
287+
assertNull(singleton[0]);
274288
}
275289

276290
/**

0 commit comments

Comments
 (0)