Skip to content

Commit 1bb3657

Browse files
committed
ConversionUtilsTest: add convertToEnum unit test
1 parent faced57 commit 1bb3657

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,22 @@ class Struct {
295295
assertSame(numberList, struct.list);
296296
}
297297

298+
/** Tests {@link ConversionUtils#convertToEnum(String, Class)}. */
299+
@Test
300+
public void testConvertToEnum() {
301+
final Words foo = ConversionUtils.convertToEnum("FOO", Words.class);
302+
assertSame(Words.FOO, foo);
303+
final Words bar = ConversionUtils.convertToEnum("BAR", Words.class);
304+
assertSame(Words.BAR, bar);
305+
final Words fubar = ConversionUtils.convertToEnum("FUBAR", Words.class);
306+
assertSame(Words.FUBAR, fubar);
307+
final Words noConstant = ConversionUtils.convertToEnum("NONE", Words.class);
308+
assertNull(noConstant);
309+
final String notAnEnum =
310+
ConversionUtils.convertToEnum("HOOYAH", String.class);
311+
assertNull(notAnEnum);
312+
}
313+
298314
/** Tests {@link ConversionUtils#getClass(Type)}. */
299315
@Test
300316
public void testGetClass() {
@@ -861,4 +877,9 @@ public static class StringListExtension extends ArrayList<String> {
861877
// NB: No implementation needed.
862878
}
863879

880+
/** Enumeration for testing conversion to enum types. */
881+
public static enum Words {
882+
FOO, BAR, FUBAR
883+
}
884+
864885
}

0 commit comments

Comments
 (0)