Skip to content

Commit 024f98e

Browse files
author
Gary Gregory
committed
[CSV-239] Cannot get headers in column order from CSVRecord.
Add test.
1 parent 282f211 commit 024f98e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ public void testGetHeaderNames() throws IOException {
496496
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
497497
final Map<String, Integer> nameIndexMap = parser.getHeaderMap();
498498
final List<String> headerNames = parser.getHeaderNames();
499+
Assert.assertNotNull(headerNames);
499500
Assert.assertEquals(nameIndexMap.size(), headerNames.size());
500501
for (int i = 0; i < headerNames.size(); i++) {
501502
final String name = headerNames.get(i);
@@ -504,6 +505,21 @@ public void testGetHeaderNames() throws IOException {
504505
}
505506
}
506507

508+
@Test
509+
public void testGetHeaderNamesReadOnly() throws IOException {
510+
try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z",
511+
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
512+
final List<String> headerNames = parser.getHeaderNames();
513+
Assert.assertNotNull(headerNames);
514+
try {
515+
headerNames.add("This is a read-only list.");
516+
fail();
517+
} catch (UnsupportedOperationException e) {
518+
// Yes.
519+
}
520+
}
521+
}
522+
507523
@Test
508524
public void testGetLine() throws IOException {
509525
try (final CSVParser parser = CSVParser.parse(CSV_INPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces())) {

0 commit comments

Comments
 (0)