[CSV-239] Cannot get headers in column order from CSVRecord.
Add test.
This commit is contained in:
parent
282f211394
commit
024f98e039
|
@ -496,6 +496,7 @@ public class CSVParserTest {
|
|||
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
|
||||
final Map<String, Integer> nameIndexMap = parser.getHeaderMap();
|
||||
final List<String> headerNames = parser.getHeaderNames();
|
||||
Assert.assertNotNull(headerNames);
|
||||
Assert.assertEquals(nameIndexMap.size(), headerNames.size());
|
||||
for (int i = 0; i < headerNames.size(); i++) {
|
||||
final String name = headerNames.get(i);
|
||||
|
@ -504,6 +505,21 @@ public class CSVParserTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHeaderNamesReadOnly() throws IOException {
|
||||
try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z",
|
||||
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
|
||||
final List<String> headerNames = parser.getHeaderNames();
|
||||
Assert.assertNotNull(headerNames);
|
||||
try {
|
||||
headerNames.add("This is a read-only list.");
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// Yes.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLine() throws IOException {
|
||||
try (final CSVParser parser = CSVParser.parse(CSV_INPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces())) {
|
||||
|
|
Loading…
Reference in New Issue