Skip to content

Commit e9a41a4

Browse files
committed
StringToArrayConverterTest: avoid needless objects
We can use the array classes directly, rather than reflectively instantiating and then throwing away array instances.
1 parent e8f6a8e commit e9a41a4

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,31 @@ public void tearDown() {
6969
*/
7070
@Test
7171
public void testArrayConversion() {
72-
// Component types for array conversions
72+
// Array types for array conversions
7373
List<Class<?>> classes = Arrays.asList( //
74-
byte.class, //
75-
Byte.class, //
76-
short.class, //
77-
Short.class, //
78-
int.class, //
79-
Integer.class, //
80-
long.class, //
81-
Long.class, //
82-
float.class, //
83-
Float.class, //
84-
double.class, //
85-
Double.class //
74+
byte[].class, //
75+
Byte[].class, //
76+
short[].class, //
77+
Short[].class, //
78+
int[].class, //
79+
Integer[].class, //
80+
long[].class, //
81+
Long[].class, //
82+
float[].class, //
83+
Float[].class, //
84+
double[].class, //
85+
Double[].class //
8686
);
8787
// String input
8888
String s = "{0, 1, 2}";
89-
for (Class<?> c : classes) {
90-
// Make the array class
91-
Class<?> arrayClass = Array.newInstance(c, 0).getClass();
89+
for (Class<?> arrayClass : classes) {
9290
// Ensure our Converter can do the conversion
9391
Assert.assertTrue(converter.canConvert(s, arrayClass));
9492
// Do the conversion
9593
Object converted = converter.convert(s, arrayClass);
9694
// Ensure the output is the expected type
9795
Assert.assertEquals(arrayClass, converted.getClass());
96+
Class<?> c = arrayClass.getComponentType();
9897
for (int i = 0; i < 3; i++) {
9998
// Ensure element correctness
10099
Object expected = convertService.convert(i, c);

0 commit comments

Comments
 (0)