CSVRow { public <E extends Enum<E>> E parseEnum(T csvColumn, Class<E> enumClass) { String value = parse(csvColumn); if (hasNullValue(value)) { return null; } return Enum.valueOf(enumClass, value); } CSVRow(ImmutableMap<String, String> lineByHeader); boolean hasEntry(T csvColumn); String parse(T csvColumn); Integer parseInt(T csvColumn); Double parseDouble(T csvColumn); BigDecimal parseBigDecimal(T csvColumn); @Nullable Boolean parseBoolean(T csvColumn); E parseEnum(T csvColumn, Class<E> enumClass); final ImmutableMap<String, String> lineByHeader; }
@Test void testParseEnum() { Assertions.assertEquals(ExampleEnum.EXAMPLE, FULL_ROW.parseEnum(TestCSVColumn.ENUM, ExampleEnum.class)); }
@Test void testParseMissingEnum() { Assertions.assertNull(EMPTY_ROW.parseEnum(TestCSVColumn.ENUM, ExampleEnum.class)); }
@Test void testParseIncorrectEnum() { Assertions.assertThrows(IllegalArgumentException.class, () -> INCORRECT_ROW.parseEnum(TestCSVColumn.ENUM, ExampleEnum.class)); }