Sort method.
This commit is contained in:
parent
a9b0be192d
commit
47d11b853f
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue