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 abfdf83  Add tests that print CSVRecords.
abfdf83 is described below

commit abfdf83f11b4b08bc987ce335598cf01253ba7b8
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jul 6 13:11:43 2021 -0400

    Add tests that print CSVRecords.
---
 .../org/apache/commons/csv/CSVPrinterTest.java     | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java 
b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index c470209..80d1c87 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -1262,6 +1262,68 @@ public class CSVPrinterTest {
     }
 
     @Test
+    public void testPrintCSVParser() throws IOException {
+        final String code = "a1,b1\n" // 1)
+            + "a2,b2\n" // 2)
+            + "a3,b3\n" // 3)
+            + "a4,b4\n"// 4)
+        ;
+        final String[][] res = {{"a1", "b1"}, {"a2", "b2"}, {"a3", "b3"}, 
{"a4", "b4"}};
+        CSVFormat format = CSVFormat.DEFAULT;
+        StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = format.print(sw); final CSVParser 
parser = CSVParser.parse(code, format)) {
+            printer.printRecords(parser);
+        }
+        try (final CSVParser parser = CSVParser.parse(sw.toString(), format)) {
+            final List<CSVRecord> records = parser.getRecords();
+            assertFalse(records.isEmpty());
+            Utils.compare("Fail", res, records);
+        }
+    }
+
+    @Test
+    public void testPrintCSVRecord() throws IOException {
+        final String code = "a1,b1\n" // 1)
+            + "a2,b2\n" // 2)
+            + "a3,b3\n" // 3)
+            + "a4,b4\n"// 4)
+        ;
+        final String[][] res = {{"a1", "b1"}, {"a2", "b2"}, {"a3", "b3"}, 
{"a4", "b4"}};
+        CSVFormat format = CSVFormat.DEFAULT;
+        StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = format.print(sw); final CSVParser 
parser = CSVParser.parse(code, format)) {
+            for (CSVRecord record : parser) {
+                printer.printRecord(record);
+            }
+        }
+        try (final CSVParser parser = CSVParser.parse(sw.toString(), format)) {
+            final List<CSVRecord> records = parser.getRecords();
+            assertFalse(records.isEmpty());
+            Utils.compare("Fail", res, records);
+        }
+    }
+
+    @Test
+    public void testPrintCSVRecords() throws IOException {
+        final String code = "a1,b1\n" // 1)
+            + "a2,b2\n" // 2)
+            + "a3,b3\n" // 3)
+            + "a4,b4\n"// 4)
+        ;
+        final String[][] res = {{"a1", "b1"}, {"a2", "b2"}, {"a3", "b3"}, 
{"a4", "b4"}};
+        CSVFormat format = CSVFormat.DEFAULT;
+        StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = format.print(sw); final CSVParser 
parser = CSVParser.parse(code, format)) {
+            printer.printRecords(parser.getRecords());
+        }
+        try (final CSVParser parser = CSVParser.parse(sw.toString(), format)) {
+            final List<CSVRecord> records = parser.getRecords();
+            assertFalse(records.isEmpty());
+            Utils.compare("Fail", res, records);
+        }
+    }
+
+    @Test
     public void testPrintCustomNullValues() throws IOException {
         final StringWriter sw = new StringWriter();
         try (final CSVPrinter printer = new CSVPrinter(sw, 
CSVFormat.DEFAULT.withNullString("NULL"))) {

Reply via email to