Let a null input to CSVRecord#get(Enum) fail in CSVRecord#get(String).

This commit is contained in:
Gary Gregory 2020-01-20 21:36:11 -05:00
parent e3eca25d13
commit 7c5c08921c
2 changed files with 7 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
/**
* A CSV record parsed from a CSV file.
@ -65,7 +66,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
* @return the String at the given enum String
*/
public String get(final Enum<?> e) {
return get(e.toString());
return get(Objects.toString(e, null));
}
/**

View File

@ -91,6 +91,11 @@ public class CSVRecordTest {
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
}
@Test
public void testGetNullEnum() {
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get((Enum<?>) null));
}
@Test
public void testGetUnmappedName() {
assertThrows(IllegalArgumentException.class, () -> assertNull(recordWithHeader.get("fourth")));