@@ -114,6 +114,7 @@ public void testBackslashEscaping() throws IOException {
114114 assertTrue (records .size () > 0 );
115115
116116 Utils .compare ("Records do not match expected result" , res , records );
117+ parser .close ();
117118 }
118119
119120 @ Test
@@ -143,6 +144,7 @@ public void testBackslashEscaping2() throws IOException {
143144 assertTrue (records .size () > 0 );
144145
145146 Utils .compare ("" , res , records );
147+ parser .close ();
146148 }
147149
148150 @ Test
@@ -176,6 +178,7 @@ public void testBackslashEscapingOld() throws IOException {
176178 for (int i = 0 ; i < res .length ; i ++) {
177179 assertArrayEquals (res [i ], records .get (i ).values ());
178180 }
181+ parser .close ();
179182 }
180183
181184 @ Test
@@ -207,6 +210,7 @@ public void testBOMInputStream() throws IOException {
207210 }
208211 } finally {
209212 parser .close ();
213+ reader .close ();
210214 }
211215 }
212216
@@ -216,6 +220,7 @@ public void testCarriageReturnEndings() throws IOException {
216220 final CSVParser parser = CSVParser .parse (code , CSVFormat .DEFAULT );
217221 final List <CSVRecord > records = parser .getRecords ();
218222 assertEquals (4 , records .size ());
223+ parser .close ();
219224 }
220225
221226 @ Test
@@ -224,6 +229,7 @@ public void testCarriageReturnLineFeedEndings() throws IOException {
224229 final CSVParser parser = CSVParser .parse (code , CSVFormat .DEFAULT );
225230 final List <CSVRecord > records = parser .getRecords ();
226231 assertEquals (4 , records .size ());
232+ parser .close ();
227233 }
228234
229235 @ Test (expected = NoSuchElementException .class )
@@ -243,6 +249,7 @@ public void testCSV57() throws Exception {
243249 final List <CSVRecord > list = parser .getRecords ();
244250 assertNotNull (list );
245251 assertEquals (0 , list .size ());
252+ parser .close ();
246253 }
247254
248255 @ Test
@@ -275,16 +282,19 @@ public void testDefaultFormat() throws IOException {
275282 };
276283
277284 format = CSVFormat .DEFAULT .withCommentStart ('#' );
285+ parser .close ();
278286 parser = CSVParser .parse (code , format );
279287 records = parser .getRecords ();
280288
281289 Utils .compare ("Failed to parse with comments" , res_comments , records );
290+ parser .close ();
282291 }
283292
284293 @ Test
285294 public void testEmptyFile () throws Exception {
286295 final CSVParser parser = CSVParser .parse ("" , CSVFormat .DEFAULT );
287296 assertNull (parser .nextRecord ());
297+ parser .close ();
288298 }
289299
290300 @ Test
@@ -306,6 +316,7 @@ public void testEmptyLineBehaviourCSV() throws Exception {
306316 for (int i = 0 ; i < res .length ; i ++) {
307317 assertArrayEquals (res [i ], records .get (i ).values ());
308318 }
319+ parser .close ();
309320 }
310321 }
311322
@@ -330,6 +341,7 @@ public void testEmptyLineBehaviourExcel() throws Exception {
330341 for (int i = 0 ; i < res .length ; i ++) {
331342 assertArrayEquals (res [i ], records .get (i ).values ());
332343 }
344+ parser .close ();
333345 }
334346 }
335347
@@ -357,6 +369,7 @@ public void testEndOfFileBehaviorCSV() throws Exception {
357369 for (int i = 0 ; i < res .length ; i ++) {
358370 assertArrayEquals (res [i ], records .get (i ).values ());
359371 }
372+ parser .close ();
360373 }
361374 }
362375
@@ -386,6 +399,7 @@ public void testEndOfFileBehaviourExcel() throws Exception {
386399 for (int i = 0 ; i < res .length ; i ++) {
387400 assertArrayEquals (res [i ], records .get (i ).values ());
388401 }
402+ parser .close ();
389403 }
390404 }
391405
@@ -408,6 +422,7 @@ public void testExcelFormat1() throws IOException {
408422 for (int i = 0 ; i < res .length ; i ++) {
409423 assertArrayEquals (res [i ], records .get (i ).values ());
410424 }
425+ parser .close ();
411426 }
412427
413428 @ Test
@@ -427,6 +442,7 @@ public void testExcelFormat2() throws Exception {
427442 for (int i = 0 ; i < res .length ; i ++) {
428443 assertArrayEquals (res [i ], records .get (i ).values ());
429444 }
445+ parser .close ();
430446 }
431447
432448 @ Test
@@ -466,6 +482,7 @@ public void testGetHeaderMap() throws Exception {
466482 }
467483
468484 assertFalse (records .hasNext ());
485+ parser .close ();
469486 }
470487
471488 @ Test
@@ -476,6 +493,7 @@ public void testGetLine() throws IOException {
476493 }
477494
478495 assertNull (parser .nextRecord ());
496+ parser .close ();
479497 }
480498
481499 @ Test
@@ -517,6 +535,7 @@ public void testGetRecords() throws IOException {
517535 for (int i = 0 ; i < RESULT .length ; i ++) {
518536 assertArrayEquals (RESULT [i ], records .get (i ).values ());
519537 }
538+ parser .close ();
520539 }
521540
522541 @ Test
@@ -541,6 +560,7 @@ public void testGetRecordWithMultiLineValues() throws Exception {
541560 assertNull (record = parser .nextRecord ());
542561 assertEquals (8 , parser .getCurrentLineNumber ());
543562 assertEquals (3 , parser .getRecordNumber ());
563+ parser .close ();
544564 }
545565
546566 @ Test
@@ -585,6 +605,7 @@ public void testIgnoreEmptyLines() throws IOException {
585605 final CSVParser parser = CSVParser .parse (code , CSVFormat .DEFAULT );
586606 final List <CSVRecord > records = parser .getRecords ();
587607 assertEquals (3 , records .size ());
608+ parser .close ();
588609 }
589610
590611 @ Test (expected = IllegalArgumentException .class )
@@ -628,6 +649,7 @@ public void testLineFeedEndings() throws IOException {
628649 final CSVParser parser = CSVParser .parse (code , CSVFormat .DEFAULT );
629650 final List <CSVRecord > records = parser .getRecords ();
630651 assertEquals (4 , records .size ());
652+ parser .close ();
631653 }
632654
633655 @ Test
@@ -681,22 +703,24 @@ public void testMultipleIterators() throws Exception {
681703 assertEquals ("d" , second .get (0 ));
682704 assertEquals ("e" , second .get (1 ));
683705 assertEquals ("f" , second .get (2 ));
706+ parser .close ();
684707 }
685708
686709 @ Test (expected = IllegalArgumentException .class )
687710 public void testNewCSVParserNullReaderFormat () throws Exception {
688- new CSVParser (null , CSVFormat .DEFAULT );
711+ new CSVParser (null , CSVFormat .DEFAULT ). close () ;
689712 }
690713
691714 @ Test (expected = IllegalArgumentException .class )
692715 public void testNewCSVParserReaderNullFormat () throws Exception {
693- new CSVParser (new StringReader ("" ), null );
716+ new CSVParser (new StringReader ("" ), null ). close () ;
694717 }
695718
696719 @ Test
697720 public void testNoHeaderMap () throws Exception {
698721 final CSVParser parser = CSVParser .parse ("a,b,c\n 1,2,3\n x,y,z" , CSVFormat .DEFAULT );
699722 Assert .assertNull (parser .getHeaderMap ());
723+ parser .close ();
700724 }
701725
702726 @ Test (expected = IllegalArgumentException .class )
@@ -824,6 +848,7 @@ private void validateLineNumbers(final String lineSeparator) throws IOException
824848 assertNull (parser .nextRecord ());
825849 // Still 2 because the last line is does not have EOL chars
826850 assertEquals (2 , parser .getCurrentLineNumber ());
851+ parser .close ();
827852 }
828853
829854 private void validateRecordNumbers (final String lineSeparator ) throws IOException {
@@ -841,6 +866,7 @@ private void validateRecordNumbers(final String lineSeparator) throws IOExceptio
841866 assertEquals (3 , parser .getRecordNumber ());
842867 assertNull (record = parser .nextRecord ());
843868 assertEquals (3 , parser .getRecordNumber ());
869+ parser .close ();
844870 }
845871
846872}
0 commit comments