Skip to content

Commit

Permalink
Add the tests that pass from
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Feb 3, 2024
1 parent 998e464 commit be4c486
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,33 @@ public void testExcelPrintAllArrayOfArrays() throws IOException {
}
}

@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();
Expand All @@ -581,6 +608,16 @@ public void testExcelPrintAllArrayOfLists() throws IOException {
}
}

@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();
Expand All @@ -590,6 +627,15 @@ public void testExcelPrintAllIterableOfArrays() throws IOException {
}
}

@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();
Expand Down Expand Up @@ -689,10 +735,22 @@ public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLExc
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();
Expand Down Expand Up @@ -729,7 +787,6 @@ public void testJdbcPrinterWithResultSetHeader() throws IOException, ClassNotFou
@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();
Expand Down Expand Up @@ -1748,4 +1805,5 @@ private void tryFormat(final List<String> list, final Character quote, final Cha
}
assertEquals(expected, out.toString());
}

}

0 comments on commit be4c486

Please sign in to comment.