You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/02/08 19:46:28 UTC

[commons-csv] branch master updated: Add testcases for CSVRecord with get(Enum) and toString. (#54)

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 3e1d162  Add testcases for CSVRecord with get(Enum) and toString. (#54)
3e1d162 is described below

commit 3e1d1629859c3209ae45cb9fa596628ef93717cb
Author: Chen <50...@users.noreply.github.com>
AuthorDate: Sun Feb 9 03:46:22 2020 +0800

    Add testcases for CSVRecord with get(Enum) and toString. (#54)
---
 .../java/org/apache/commons/csv/CSVRecordTest.java | 33 +++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
index d66acfa..cd29d59 100644
--- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
@@ -46,6 +46,23 @@ public class CSVRecordTest {
         UNKNOWN_COLUMN
     }
 
+    public enum EnumHeader {
+        FIRST("first"),
+        SECOND("second"),
+        THIRD("third");
+
+        private String number;
+
+        EnumHeader(String number) {
+            this.number = number;
+        }
+
+        @Override
+        public String toString() {
+            return number;
+        }
+    }
+
     private Map<String, Integer> headerMap;
     private CSVRecord record, recordWithHeader;
     private String[] values;
@@ -174,7 +191,7 @@ public class CSVRecordTest {
         final Map<String, String> map = new ConcurrentHashMap<>();
         this.recordWithHeader.putIn(map);
         this.validateMap(map, false);
-        // Test that we can compile with assigment to the same map as the param.
+        // Test that we can compile with assignment to the same map as the param.
         final TreeMap<String, String> map2 = recordWithHeader.putIn(new TreeMap<String, String>());
         this.validateMap(map2, false);
     }
@@ -270,4 +287,18 @@ public class CSVRecordTest {
         assertEquals(null, map.get("fourth"));
     }
 
+    @Test
+    public void testToString() {
+        assertNotNull(recordWithHeader.toString());
+        assertTrue(recordWithHeader.toString().contains("comment="));
+        assertTrue(recordWithHeader.toString().contains("recordNumber="));
+        assertTrue(recordWithHeader.toString().contains("values="));
+    }
+
+    @Test
+    public void testGetWithEnum() {
+        assertEquals(recordWithHeader.get("first"), recordWithHeader.get(EnumHeader.FIRST));
+        assertEquals(recordWithHeader.get("second"), recordWithHeader.get(EnumHeader.SECOND));
+        assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
+    }
 }