Skip to content

Commit 6dc6993

Browse files
committed
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
1 parent 1b78bc1 commit 6dc6993

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ public void testRoundtrip() throws Exception {
446446
printer.printRecord(record);
447447
}
448448
assertEquals(input, out.toString());
449+
printer.close();
449450
}
450451

451452
@Test

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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\non 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\nc");
266279
assertEquals("a,\"b\nc\"" + 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\nc");
274288
assertEquals("a,\"b\r\nc\"" + 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\nc", "d");
298315
assertEquals("\"a\",\"b\nc\",\"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\nc", Integer.valueOf(1));
306324
assertEquals("\"a\",\"b\nc\",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

Comments
 (0)