@@ -148,6 +148,7 @@ public void testDisabledComment() throws IOException {
148148 printer .printComment ("This is a comment" );
149149
150150 assertEquals ("" , sw .toString ());
151+ printer .close ();
151152 }
152153
153154 @ Test
@@ -156,6 +157,7 @@ public void testExcelPrintAllArrayOfArrays() throws IOException {
156157 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL );
157158 printer .printRecords (new String [][] { { "r1c1" , "r1c2" }, { "r2c1" , "r2c2" } });
158159 assertEquals ("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator , sw .toString ());
160+ printer .close ();
159161 }
160162
161163 @ Test
@@ -164,6 +166,7 @@ public void testExcelPrintAllArrayOfLists() throws IOException {
164166 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL );
165167 printer .printRecords (new List [] { Arrays .asList (new String [] { "r1c1" , "r1c2" }), Arrays .asList (new String [] { "r2c1" , "r2c2" }) });
166168 assertEquals ("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator , sw .toString ());
169+ printer .close ();
167170 }
168171
169172 @ Test
@@ -172,6 +175,7 @@ public void testExcelPrintAllIterableOfArrays() throws IOException {
172175 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL );
173176 printer .printRecords (Arrays .asList (new String [][] { { "r1c1" , "r1c2" }, { "r2c1" , "r2c2" } }));
174177 assertEquals ("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator , sw .toString ());
178+ printer .close ();
175179 }
176180
177181 @ Test
@@ -181,6 +185,7 @@ public void testExcelPrintAllIterableOfLists() throws IOException {
181185 printer .printRecords (Arrays .asList (new List [] { Arrays .asList (new String [] { "r1c1" , "r1c2" }),
182186 Arrays .asList (new String [] { "r2c1" , "r2c2" }) }));
183187 assertEquals ("r1c1,r1c2" + recordSeparator + "r2c1,r2c2" + recordSeparator , sw .toString ());
188+ printer .close ();
184189 }
185190
186191 @ Test
@@ -189,6 +194,7 @@ public void testExcelPrinter1() throws IOException {
189194 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL );
190195 printer .printRecord ("a" , "b" );
191196 assertEquals ("a,b" + recordSeparator , sw .toString ());
197+ printer .close ();
192198 }
193199
194200 @ Test
@@ -197,6 +203,7 @@ public void testExcelPrinter2() throws IOException {
197203 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .EXCEL );
198204 printer .printRecord ("a,b" , "b" );
199205 assertEquals ("\" a,b\" ,b" + recordSeparator , sw .toString ());
206+ printer .close ();
200207 }
201208
202209 @ Test
@@ -212,6 +219,7 @@ public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLExc
212219 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
213220 printer .printRecords (stmt .executeQuery ("select ID, NAME from TEST" ));
214221 assertEquals ("1,r1" + recordSeparator + "2,r2" + recordSeparator , sw .toString ());
222+ printer .close ();
215223 } finally {
216224 connection .close ();
217225 }
@@ -224,6 +232,7 @@ public void testMultiLineComment() throws IOException {
224232 printer .printComment ("This is a comment\n on multiple lines" );
225233
226234 assertEquals ("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator , sw .toString ());
235+ printer .close ();
227236 }
228237
229238 @ Test
@@ -232,6 +241,7 @@ public void testPrinter1() throws IOException {
232241 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
233242 printer .printRecord ("a" , "b" );
234243 assertEquals ("a,b" + recordSeparator , sw .toString ());
244+ printer .close ();
235245 }
236246
237247 @ Test
@@ -240,6 +250,7 @@ public void testPrinter2() throws IOException {
240250 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
241251 printer .printRecord ("a,b" , "b" );
242252 assertEquals ("\" a,b\" ,b" + recordSeparator , sw .toString ());
253+ printer .close ();
243254 }
244255
245256 @ Test
@@ -248,6 +259,7 @@ public void testPrinter3() throws IOException {
248259 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
249260 printer .printRecord ("a, b" , "b " );
250261 assertEquals ("\" a, b\" ,\" b \" " + recordSeparator , sw .toString ());
262+ printer .close ();
251263 }
252264
253265 @ Test
@@ -256,6 +268,7 @@ public void testPrinter4() throws IOException {
256268 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
257269 printer .printRecord ("a" , "b\" c" );
258270 assertEquals ("a,\" b\" \" c\" " + recordSeparator , sw .toString ());
271+ printer .close ();
259272 }
260273
261274 @ Test
@@ -264,6 +277,7 @@ public void testPrinter5() throws IOException {
264277 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
265278 printer .printRecord ("a" , "b\n c" );
266279 assertEquals ("a,\" b\n c\" " + recordSeparator , sw .toString ());
280+ printer .close ();
267281 }
268282
269283 @ Test
@@ -272,6 +286,7 @@ public void testPrinter6() throws IOException {
272286 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
273287 printer .printRecord ("a" , "b\r \n c" );
274288 assertEquals ("a,\" b\r \n c\" " + recordSeparator , sw .toString ());
289+ printer .close ();
275290 }
276291
277292 @ Test
@@ -280,6 +295,7 @@ public void testPrinter7() throws IOException {
280295 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
281296 printer .printRecord ("a" , "b\\ c" );
282297 assertEquals ("a,b\\ c" + recordSeparator , sw .toString ());
298+ printer .close ();
283299 }
284300
285301 @ Test
@@ -288,6 +304,7 @@ public void testPrintNullValues() throws IOException {
288304 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
289305 printer .printRecord ("a" , null , "b" );
290306 assertEquals ("a,,b" + recordSeparator , sw .toString ());
307+ printer .close ();
291308 }
292309
293310 @ Test
@@ -296,6 +313,7 @@ public void testQuoteAll() throws IOException {
296313 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuotePolicy (Quote .ALL ).build ());
297314 printer .printRecord ("a" , "b\n c" , "d" );
298315 assertEquals ("\" a\" ,\" b\n c\" ,\" d\" " + recordSeparator , sw .toString ());
316+ printer .close ();
299317 }
300318
301319 @ Test
@@ -304,6 +322,7 @@ public void testQuoteNonNumeric() throws IOException {
304322 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuotePolicy (Quote .NON_NUMERIC ).build ());
305323 printer .printRecord ("a" , "b\n c" , Integer .valueOf (1 ));
306324 assertEquals ("\" a\" ,\" b\n c\" ,1" + recordSeparator , sw .toString ());
325+ printer .close ();
307326 }
308327
309328 @ Test
@@ -321,6 +340,7 @@ public void testSingleLineComment() throws IOException {
321340 printer .printComment ("This is a comment" );
322341
323342 assertEquals ("# This is a comment" + recordSeparator , sw .toString ());
343+ printer .close ();
324344 }
325345
326346}
0 commit comments