Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 1023690

Browse files
committed
Break up testEscapeBackslash() method into individual tests.
1 parent d067c3f commit 1023690

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
*/
5454
public class CSVPrinterTest {
5555

56+
private static final char QUOTE_CH = '\'';
5657
private static final int ITERATIONS_FOR_RANDOM_TEST = 50000;
5758

5859
private static String printable(final String s) {
@@ -290,35 +291,46 @@ public void testEOLQuoted() throws IOException {
290291
}
291292

292293
@Test
293-
public void testEscapeBackslash() throws IOException {
294+
public void testEscapeBackslash1() throws IOException {
294295
StringWriter sw = new StringWriter();
295-
final char quoteChar = '\'';
296-
final String eol = "\r\n";
297-
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) {
296+
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
298297
printer.print("\\");
299298
}
300299
assertEquals("'\\'", sw.toString());
300+
}
301301

302-
sw = new StringWriter();
303-
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) {
302+
@Test
303+
public void testEscapeBackslash2() throws IOException {
304+
StringWriter sw = new StringWriter();
305+
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
304306
printer.print("\\\r");
305307
}
306308
assertEquals("'\\\r'", sw.toString());
307309

308-
sw = new StringWriter();
309-
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) {
310+
}
311+
312+
@Test
313+
public void testEscapeBackslash3() throws IOException {
314+
StringWriter sw = new StringWriter();
315+
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
310316
printer.print("X\\\r");
311317
}
312318
assertEquals("'X\\\r'", sw.toString());
319+
}
313320

314-
sw = new StringWriter();
315-
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) {
316-
printer.printRecord(new Object[] { "\\\r" });
321+
@Test
322+
public void testEscapeBackslash4() throws IOException {
323+
StringWriter sw = new StringWriter();
324+
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
325+
printer.print("\\\\");
317326
}
318-
assertEquals("'\\\r'" + eol, sw.toString());
327+
assertEquals("'\\\\'", sw.toString());
328+
}
319329

320-
sw = new StringWriter();
321-
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) {
330+
@Test
331+
public void testEscapeBackslash5() throws IOException {
332+
StringWriter sw = new StringWriter();
333+
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
322334
printer.print("\\\\");
323335
}
324336
assertEquals("'\\\\'", sw.toString());

0 commit comments

Comments
 (0)