Skip to content

Commit dd9b3cc

Browse files
committed
Add testcases for CSVRecord with get(Enum) and toString.
1 parent b581686 commit dd9b3cc

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
@@ -41,6 +41,23 @@ private enum EnumFixture {
4141
UNKNOWN_COLUMN
4242
}
4343

44+
public enum EnumHeader {
45+
FIRST("first"),
46+
SECOND("second"),
47+
THIRD("third");
48+
49+
private String number;
50+
51+
EnumHeader(String number) {
52+
this.number = number;
53+
}
54+
55+
@Override
56+
public String toString() {
57+
return number;
58+
}
59+
}
60+
4461
private String[] values;
4562
private CSVRecord record, recordWithHeader;
4663
private Map<String, Integer> headerMap;
@@ -164,7 +181,7 @@ public void testPutInMap() {
164181
final Map<String, String> map = new ConcurrentHashMap<>();
165182
this.recordWithHeader.putIn(map);
166183
this.validateMap(map, false);
167-
// Test that we can compile with assigment to the same map as the param.
184+
// Test that we can compile with assignment to the same map as the param.
168185
final TreeMap<String, String> map2 = recordWithHeader.putIn(new TreeMap<String, String>());
169186
this.validateMap(map2, false);
170187
}
@@ -222,4 +239,18 @@ private void validateMap(final Map<String, String> map, final boolean allowsNull
222239
assertEquals(null, map.get("fourth"));
223240
}
224241

242+
@Test
243+
public void testToString() {
244+
assertNotNull(recordWithHeader.toString());
245+
assertTrue(recordWithHeader.toString().contains("comment="));
246+
assertTrue(recordWithHeader.toString().contains("recordNumber="));
247+
assertTrue(recordWithHeader.toString().contains("values="));
248+
}
249+
250+
@Test
251+
public void testGetWithEnum() {
252+
assertEquals(recordWithHeader.get("first"), recordWithHeader.get(EnumHeader.FIRST));
253+
assertEquals(recordWithHeader.get("second"), recordWithHeader.get(EnumHeader.SECOND));
254+
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
255+
}
225256
}

0 commit comments

Comments
 (0)