From 6dc69934d24743593ec92f8cd2047775f67cd176 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Sun, 24 Mar 2013 15:28:11 +0000 Subject: [PATCH] Close printer (at least for non-Exception cases - these are unit tests) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1460400 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/csv/CSVParserTest.java | 1 + .../apache/commons/csv/CSVPrinterTest.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index b09802ba..11d70bea 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -446,6 +446,7 @@ public class CSVParserTest { printer.printRecord(record); } assertEquals(input, out.toString()); + printer.close(); } @Test diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index 4c2fe849..6e224636 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -148,6 +148,7 @@ public class CSVPrinterTest { printer.printComment("This is a comment"); assertEquals("", sw.toString()); + printer.close(); } @Test @@ -156,6 +157,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL); printer.printRecords(new String[][] { { "r1c1", "r1c2" }, { "r2c1", "r2c2" } }); assertEquals("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -164,6 +166,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL); printer.printRecords(new List[] { Arrays.asList(new String[] { "r1c1", "r1c2" }), Arrays.asList(new String[] { "r2c1", "r2c2" }) }); assertEquals("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -172,6 +175,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL); printer.printRecords(Arrays.asList(new String[][] { { "r1c1", "r1c2" }, { "r2c1", "r2c2" } })); assertEquals("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -181,6 +185,7 @@ public class CSVPrinterTest { printer.printRecords(Arrays.asList(new List[] { Arrays.asList(new String[] { "r1c1", "r1c2" }), Arrays.asList(new String[] { "r2c1", "r2c2" }) })); assertEquals("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -189,6 +194,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL); printer.printRecord("a", "b"); assertEquals("a,b" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -197,6 +203,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL); printer.printRecord("a,b", "b"); assertEquals("\"a,b\",b" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -212,6 +219,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecords(stmt.executeQuery("select ID, NAME from TEST")); assertEquals("1,r1" + recordSeparator + "2,r2" + recordSeparator, sw.toString()); + printer.close(); } finally { connection.close(); } @@ -224,6 +232,7 @@ public class CSVPrinterTest { printer.printComment("This is a comment\non multiple lines"); assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -232,6 +241,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a", "b"); assertEquals("a,b" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -240,6 +250,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a,b", "b"); assertEquals("\"a,b\",b" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -248,6 +259,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a, b", "b "); assertEquals("\"a, b\",\"b \"" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -256,6 +268,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a", "b\"c"); assertEquals("a,\"b\"\"c\"" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -264,6 +277,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a", "b\nc"); assertEquals("a,\"b\nc\"" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -272,6 +286,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a", "b\r\nc"); assertEquals("a,\"b\r\nc\"" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -280,6 +295,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a", "b\\c"); assertEquals("a,b\\c" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -288,6 +304,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT); printer.printRecord("a", null, "b"); assertEquals("a,,b" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -296,6 +313,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.ALL).build()); printer.printRecord("a", "b\nc", "d"); assertEquals("\"a\",\"b\nc\",\"d\"" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -304,6 +322,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.NON_NUMERIC).build()); printer.printRecord("a", "b\nc", Integer.valueOf(1)); assertEquals("\"a\",\"b\nc\",1" + recordSeparator, sw.toString()); + printer.close(); } @Test @@ -321,6 +340,7 @@ public class CSVPrinterTest { printer.printComment("This is a comment"); assertEquals("# This is a comment" + recordSeparator, sw.toString()); + printer.close(); } }