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

commit be4c486f8e948e5e1b83172b55e8128b6f066308
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Feb 3 13:24:17 2024 -0500

    Add the tests that pass from
    https://github.com/apache/commons-csv/pull/14
---
 .../org/apache/commons/csv/CSVPrinterTest.java     | 62 +++++++++++++++++++++-
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java 
b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index 0f9b298c..85353dc1 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -571,6 +571,33 @@ public class CSVPrinterTest {
         }
     }
 
+    @Test
+    public void testExcelPrintAllArrayOfArraysWithFirstEmptyValue2() throws 
IOException {
+        final StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) {
+            printer.printRecords((Object[]) new String[][] { { "" } });
+            assertEquals("\"\"" + recordSeparator, sw.toString());
+        }
+    }
+
+    @Test
+    public void testExcelPrintAllArrayOfArraysWithFirstSpaceValue1() throws 
IOException {
+        final StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) {
+            printer.printRecords((Object[]) new String[][] { { " ", "r1c2" } 
});
+            assertEquals("\" \",r1c2" + recordSeparator, sw.toString());
+        }
+    }
+
+    @Test
+    public void testExcelPrintAllArrayOfArraysWithFirstTabValue1() throws 
IOException {
+        final StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) {
+            printer.printRecords((Object[]) new String[][] { { "\t", "r1c2" } 
});
+            assertEquals("\"\t\",r1c2" + recordSeparator, sw.toString());
+        }
+    }
+
     @Test
     public void testExcelPrintAllArrayOfLists() throws IOException {
         final StringWriter sw = new StringWriter();
@@ -581,6 +608,16 @@ public class CSVPrinterTest {
         }
     }
 
+    @Test
+    public void testExcelPrintAllArrayOfListsWithFirstEmptyValue2() throws 
IOException {
+        final StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) {
+            printer.printRecords(
+                    (Object[]) new List[] { Arrays.asList("") });
+            assertEquals("\"\"" + recordSeparator, sw.toString());
+        }
+    }
+
     @Test
     public void testExcelPrintAllIterableOfArrays() throws IOException {
         final StringWriter sw = new StringWriter();
@@ -590,6 +627,15 @@ public class CSVPrinterTest {
         }
     }
 
+    @Test
+    public void testExcelPrintAllIterableOfArraysWithFirstEmptyValue2() throws 
IOException {
+        final StringWriter sw = new StringWriter();
+        try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) {
+            printer.printRecords(Arrays.asList(new String[][] { { "" } }));
+            assertEquals("\"\"" + recordSeparator, sw.toString());
+        }
+    }
+
     @Test
     public void testExcelPrintAllIterableOfLists() throws IOException {
         final StringWriter sw = new StringWriter();
@@ -689,10 +735,22 @@ public class CSVPrinterTest {
         assertEquals("1,r1,\"long text 1\"" + recordSeparator + "2,r2,\"" + 
longText2 + "\"" + recordSeparator, sw.toString());
     }
 
+    @Test
+    public void testJdbcPrinterWithFirstEmptyValue2() throws IOException, 
ClassNotFoundException, SQLException {
+        final StringWriter sw = new StringWriter();
+        try (final Connection connection = getH2Connection()) {
+            try (final Statement stmt = connection.createStatement();
+                    final ResultSet resultSet = stmt.executeQuery("select '' 
AS EMPTYVALUE from DUAL");
+                    final CSVPrinter printer = 
CSVFormat.DEFAULT.withHeader(resultSet).print(sw)) {
+                printer.printRecords(resultSet);
+            }
+        }
+        assertEquals("EMPTYVALUE" + recordSeparator + "\"\"" + 
recordSeparator, sw.toString());
+    }
+
     @Test
     public void testJdbcPrinterWithResultSet() throws IOException, 
ClassNotFoundException, SQLException {
         final StringWriter sw = new StringWriter();
-        Class.forName("org.h2.Driver");
         try (final Connection connection = getH2Connection()) {
             setUpTable(connection);
             try (final Statement stmt = connection.createStatement();
@@ -729,7 +787,6 @@ public class CSVPrinterTest {
     @Test
     public void testJdbcPrinterWithResultSetMetaData() throws IOException, 
ClassNotFoundException, SQLException {
         final StringWriter sw = new StringWriter();
-        Class.forName("org.h2.Driver");
         try (final Connection connection = getH2Connection()) {
             setUpTable(connection);
             try (final Statement stmt = connection.createStatement();
@@ -1748,4 +1805,5 @@ public class CSVPrinterTest {
         }
         assertEquals(expected, out.toString());
     }
+
 }

Reply via email to