This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new 024f98e  [CSV-239] Cannot get headers in column order from CSVRecord.
024f98e is described below

commit 024f98e0392d1acf5d900a15c314799c6df56b6d
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Mon May 20 08:14:35 2019 -0400

    [CSV-239] Cannot get headers in column order from CSVRecord.
    
    Add test.
---
 src/test/java/org/apache/commons/csv/CSVParserTest.java | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java 
b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index 530df93..57bed48 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -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);
@@ -505,6 +506,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())) {
             for (final String[] re : RESULT) {

Reply via email to