@@ -571,6 +571,33 @@ public void testExcelPrintAllArrayOfArrays() throws IOException {
571571 }
572572 }
573573
574+ @ Test
575+ public void testExcelPrintAllArrayOfArraysWithFirstEmptyValue2 () throws IOException {
576+ final StringWriter sw = new StringWriter ();
577+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL )) {
578+ printer .printRecords ((Object []) new String [][] { { "" } });
579+ assertEquals ("\" \" " + recordSeparator , sw .toString ());
580+ }
581+ }
582+
583+ @ Test
584+ public void testExcelPrintAllArrayOfArraysWithFirstSpaceValue1 () throws IOException {
585+ final StringWriter sw = new StringWriter ();
586+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL )) {
587+ printer .printRecords ((Object []) new String [][] { { " " , "r1c2" } });
588+ assertEquals ("\" \" ,r1c2" + recordSeparator , sw .toString ());
589+ }
590+ }
591+
592+ @ Test
593+ public void testExcelPrintAllArrayOfArraysWithFirstTabValue1 () throws IOException {
594+ final StringWriter sw = new StringWriter ();
595+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL )) {
596+ printer .printRecords ((Object []) new String [][] { { "\t " , "r1c2" } });
597+ assertEquals ("\" \t \" ,r1c2" + recordSeparator , sw .toString ());
598+ }
599+ }
600+
574601 @ Test
575602 public void testExcelPrintAllArrayOfLists () throws IOException {
576603 final StringWriter sw = new StringWriter ();
@@ -581,6 +608,16 @@ public void testExcelPrintAllArrayOfLists() throws IOException {
581608 }
582609 }
583610
611+ @ Test
612+ public void testExcelPrintAllArrayOfListsWithFirstEmptyValue2 () throws IOException {
613+ final StringWriter sw = new StringWriter ();
614+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL )) {
615+ printer .printRecords (
616+ (Object []) new List [] { Arrays .asList ("" ) });
617+ assertEquals ("\" \" " + recordSeparator , sw .toString ());
618+ }
619+ }
620+
584621 @ Test
585622 public void testExcelPrintAllIterableOfArrays () throws IOException {
586623 final StringWriter sw = new StringWriter ();
@@ -590,6 +627,15 @@ public void testExcelPrintAllIterableOfArrays() throws IOException {
590627 }
591628 }
592629
630+ @ Test
631+ public void testExcelPrintAllIterableOfArraysWithFirstEmptyValue2 () throws IOException {
632+ final StringWriter sw = new StringWriter ();
633+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL )) {
634+ printer .printRecords (Arrays .asList (new String [][] { { "" } }));
635+ assertEquals ("\" \" " + recordSeparator , sw .toString ());
636+ }
637+ }
638+
593639 @ Test
594640 public void testExcelPrintAllIterableOfLists () throws IOException {
595641 final StringWriter sw = new StringWriter ();
@@ -689,10 +735,22 @@ public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLExc
689735 assertEquals ("1,r1,\" long text 1\" " + recordSeparator + "2,r2,\" " + longText2 + "\" " + recordSeparator , sw .toString ());
690736 }
691737
738+ @ Test
739+ public void testJdbcPrinterWithFirstEmptyValue2 () throws IOException , ClassNotFoundException , SQLException {
740+ final StringWriter sw = new StringWriter ();
741+ try (final Connection connection = getH2Connection ()) {
742+ try (final Statement stmt = connection .createStatement ();
743+ final ResultSet resultSet = stmt .executeQuery ("select '' AS EMPTYVALUE from DUAL" );
744+ final CSVPrinter printer = CSVFormat .DEFAULT .withHeader (resultSet ).print (sw )) {
745+ printer .printRecords (resultSet );
746+ }
747+ }
748+ assertEquals ("EMPTYVALUE" + recordSeparator + "\" \" " + recordSeparator , sw .toString ());
749+ }
750+
692751 @ Test
693752 public void testJdbcPrinterWithResultSet () throws IOException , ClassNotFoundException , SQLException {
694753 final StringWriter sw = new StringWriter ();
695- Class .forName ("org.h2.Driver" );
696754 try (final Connection connection = getH2Connection ()) {
697755 setUpTable (connection );
698756 try (final Statement stmt = connection .createStatement ();
@@ -729,7 +787,6 @@ public void testJdbcPrinterWithResultSetHeader() throws IOException, ClassNotFou
729787 @ Test
730788 public void testJdbcPrinterWithResultSetMetaData () throws IOException , ClassNotFoundException , SQLException {
731789 final StringWriter sw = new StringWriter ();
732- Class .forName ("org.h2.Driver" );
733790 try (final Connection connection = getH2Connection ()) {
734791 setUpTable (connection );
735792 try (final Statement stmt = connection .createStatement ();
@@ -1748,4 +1805,5 @@ private void tryFormat(final List<String> list, final Character quote, final Cha
17481805 }
17491806 assertEquals (expected , out .toString ());
17501807 }
1808+
17511809}
0 commit comments