Skip to content

Commit 3e1d162

Browse files
authored
Add testcases for CSVRecord with get(Enum) and toString. (apache#54)
1 parent d53998e commit 3e1d162

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ private enum EnumFixture {
4646
UNKNOWN_COLUMN
4747
}
4848

49+
public enum EnumHeader {
50+
FIRST("first"),
51+
SECOND("second"),
52+
THIRD("third");
53+
54+
private String number;
55+
56+
EnumHeader(String number) {
57+
this.number = number;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return number;
63+
}
64+
}
65+
4966
private Map<String, Integer> headerMap;
5067
private CSVRecord record, recordWithHeader;
5168
private String[] values;
@@ -174,7 +191,7 @@ public void testPutInMap() {
174191
final Map<String, String> map = new ConcurrentHashMap<>();
175192
this.recordWithHeader.putIn(map);
176193
this.validateMap(map, false);
177-
// Test that we can compile with assigment to the same map as the param.
194+
// Test that we can compile with assignment to the same map as the param.
178195
final TreeMap<String, String> map2 = recordWithHeader.putIn(new TreeMap<String, String>());
179196
this.validateMap(map2, false);
180197
}
@@ -270,4 +287,18 @@ private void validateMap(final Map<String, String> map, final boolean allowsNull
270287
assertEquals(null, map.get("fourth"));
271288
}
272289

290+
@Test
291+
public void testToString() {
292+
assertNotNull(recordWithHeader.toString());
293+
assertTrue(recordWithHeader.toString().contains("comment="));
294+
assertTrue(recordWithHeader.toString().contains("recordNumber="));
295+
assertTrue(recordWithHeader.toString().contains("values="));
296+
}
297+
298+
@Test
299+
public void testGetWithEnum() {
300+
assertEquals(recordWithHeader.get("first"), recordWithHeader.get(EnumHeader.FIRST));
301+
assertEquals(recordWithHeader.get("second"), recordWithHeader.get(EnumHeader.SECOND));
302+
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
303+
}
273304
}

0 commit comments

Comments
 (0)