diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index c30133de..873f0870 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -731,33 +731,6 @@ public class CSVPrinterTest { } } - @Test - public void testPrintToFileWithDefaultCharset() throws IOException { - File file = File.createTempFile(getClass().getName(), ".csv"); - try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, Charset.defaultCharset())) { - printer.printRecord("a", "b\\c"); - } - assertEquals("a,b\\c" + recordSeparator, FileUtils.readFileToString(file, Charset.defaultCharset())); - } - - @Test - public void testPrintToPathWithDefaultCharset() throws IOException { - File file = File.createTempFile(getClass().getName(), ".csv"); - try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file.toPath(), Charset.defaultCharset())) { - printer.printRecord("a", "b\\c"); - } - assertEquals("a,b\\c" + recordSeparator, FileUtils.readFileToString(file, Charset.defaultCharset())); - } - - @Test - public void testPrintToFileWithCharsetUtf16Be() throws IOException { - File file = File.createTempFile(getClass().getName(), ".csv"); - try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, StandardCharsets.UTF_16BE)) { - printer.printRecord("a", "b\\c"); - } - assertEquals("a,b\\c" + recordSeparator, FileUtils.readFileToString(file, StandardCharsets.UTF_16BE)); - } - @Test public void testPrintCustomNullValues() throws IOException { final StringWriter sw = new StringWriter(); @@ -839,6 +812,33 @@ public class CSVPrinterTest { } } + @Test + public void testPrintToFileWithCharsetUtf16Be() throws IOException { + File file = File.createTempFile(getClass().getName(), ".csv"); + try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, StandardCharsets.UTF_16BE)) { + printer.printRecord("a", "b\\c"); + } + assertEquals("a,b\\c" + recordSeparator, FileUtils.readFileToString(file, StandardCharsets.UTF_16BE)); + } + + @Test + public void testPrintToFileWithDefaultCharset() throws IOException { + File file = File.createTempFile(getClass().getName(), ".csv"); + try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, Charset.defaultCharset())) { + printer.printRecord("a", "b\\c"); + } + assertEquals("a,b\\c" + recordSeparator, FileUtils.readFileToString(file, Charset.defaultCharset())); + } + + @Test + public void testPrintToPathWithDefaultCharset() throws IOException { + File file = File.createTempFile(getClass().getName(), ".csv"); + try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file.toPath(), Charset.defaultCharset())) { + printer.printRecord("a", "b\\c"); + } + assertEquals("a,b\\c" + recordSeparator, FileUtils.readFileToString(file, Charset.defaultCharset())); + } + @Test public void testQuoteAll() throws IOException { final StringWriter sw = new StringWriter(); @@ -925,6 +925,24 @@ public class CSVPrinterTest { } } + @Test + public void testTrailingDelimiterOnTwoColumns() throws IOException { + final StringWriter sw = new StringWriter(); + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrailingDelimiter())) { + printer.printRecord("A", "B"); + assertEquals("A,B,\r\n", sw.toString()); + } + } + + @Test + public void testTrimOffOneColumn() throws IOException { + final StringWriter sw = new StringWriter(); + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrim(false))) { + printer.print(" A "); + assertEquals("\" A \"", sw.toString()); + } + } + @Test public void testTrimOnOneColumn() throws IOException { final StringWriter sw = new StringWriter(); @@ -944,24 +962,6 @@ public class CSVPrinterTest { } } - @Test - public void testTrailingDelimiterOnTwoColumns() throws IOException { - final StringWriter sw = new StringWriter(); - try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrailingDelimiter())) { - printer.printRecord("A", "B"); - assertEquals("A,B,\r\n", sw.toString()); - } - } - - @Test - public void testTrimOffOneColumn() throws IOException { - final StringWriter sw = new StringWriter(); - try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrim(false))) { - printer.print(" A "); - assertEquals("\" A \"", sw.toString()); - } - } - private String[] toFirstRecordValues(final String expected, final CSVFormat format) throws IOException { return CSVParser.parse(expected, format).getRecords().get(0).values(); }