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/04/09 12:52:26 UTC

[commons-csv] branch master updated: Improve record and printer Coverage (#66)

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 83b2b9c  Improve record and printer Coverage (#66)
83b2b9c is described below

commit 83b2b9cc2cc77315912ebbc81e64e36040c017a4
Author: Chen <50...@users.noreply.github.com>
AuthorDate: Thu Apr 9 20:52:17 2020 +0800

    Improve record and printer Coverage (#66)
    
    * Improve CSVRecord and CSVPrinter coverage
    
    * remove useless test code and test throws
    
    * add space
---
 .../org/apache/commons/csv/CSVPrinterTest.java     | 22 ++++++++++++++++++++++
 .../java/org/apache/commons/csv/CSVRecordTest.java |  8 ++++++++
 2 files changed, 30 insertions(+)

diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index d7885f6..bfa0951 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -1538,6 +1538,28 @@ public class CSVPrinterTest {
         }
     }
 
+    @Test
+    public void testNotFlushable() throws IOException {
+        final Appendable out = new StringBuilder();
+        try (final CSVPrinter printer = new CSVPrinter(out, CSVFormat.DEFAULT)) {
+            printer.printRecord("a", "b", "c");
+            assertEquals("a,b,c" + recordSeparator, out.toString());
+            printer.flush();
+        }
+    }
+
+    @Test
+    public void testCRComment() throws IOException {
+        final StringWriter sw = new StringWriter();
+        final Object value = "abc";
+        try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'))) {
+            printer.print(value);
+            printer.printComment("This is a comment\r\non multiple lines\rthis is next comment\r");
+            assertEquals("abc" + recordSeparator + "# This is a comment" + recordSeparator + "# on multiple lines"
+                        + recordSeparator + "# this is next comment" + recordSeparator + "# " + recordSeparator, sw.toString());
+        }
+    }
+
     private String[] toFirstRecordValues(final String expected, final CSVFormat format) throws IOException {
         return CSVParser.parse(expected, format).getRecords().get(0).values();
     }
diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
index cd29d59..deef5c6 100644
--- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
@@ -301,4 +301,12 @@ public class CSVRecordTest {
         assertEquals(recordWithHeader.get("second"), recordWithHeader.get(EnumHeader.SECOND));
         assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
     }
+
+    @Test
+    public void testCSVRecordNULLValues() throws IOException {
+        final CSVParser parser = CSVParser.parse("A,B\r\nONE,TWO", CSVFormat.DEFAULT.withHeader());
+        final CSVRecord csvRecord = new CSVRecord(parser, null, null, 0L, 0L);
+        assertEquals(0, csvRecord.size());
+        assertThrows(IllegalArgumentException.class, () -> csvRecord.get("B"));
+    }
 }