CSVRow { public String parse(T csvColumn) { String header = csvColumn.name(); String value = lineByHeader.get(header); if (!csvColumn.allowMissingColumn()) { Preconditions.checkNotNull(value, "Missing column " + header); } if (!csvColumn.isNullable()) { Preconditions.checkState( !value.equals(""), header + " should not be null"); } return 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 testParseNotNullableNullColumn() { Assertions.assertThrows( IllegalStateException.class, () -> INCORRECT_ROW.parse(TestCSVColumn.MISSING), "Setting Not-Nullable column MISSING to null did not cause an exception"); }