@@ -116,19 +116,19 @@ public void testCSVFile() throws Exception {
116116
117117 // Now parse the file and compare against the expected results
118118 // We use a buffered reader internally so no need to create one here.
119- final CSVParser parser = CSVParser .parse (new File (BASE , split [0 ]), Charset .defaultCharset (), format );
120- for (final CSVRecord record : parser ) {
121- String parsed = Arrays .toString (record .values ());
122- if (checkComments ) {
123- final String comment = record .getComment ().replace ("\n " , "\\ n" );
124- if (comment != null ) {
125- parsed += "#" + comment ;
119+ try (final CSVParser parser = CSVParser .parse (new File (BASE , split [0 ]), Charset .defaultCharset (), format )) {
120+ for (final CSVRecord record : parser ) {
121+ String parsed = Arrays .toString (record .values ());
122+ if (checkComments ) {
123+ final String comment = record .getComment ().replace ("\n " , "\\ n" );
124+ if (comment != null ) {
125+ parsed += "#" + comment ;
126+ }
126127 }
128+ final int count = record .size ();
129+ assertEquals (testName , readTestData (), count + ":" + parsed );
127130 }
128- final int count = record .size ();
129- assertEquals (testName , readTestData (), count + ":" + parsed );
130131 }
131- parser .close ();
132132 }
133133
134134 @ Test
@@ -160,18 +160,18 @@ public void testCSVUrl() throws Exception {
160160
161161 // Now parse the file and compare against the expected results
162162 final URL resource = ClassLoader .getSystemResource ("CSVFileParser/" + split [0 ]);
163- final CSVParser parser = CSVParser .parse (resource , Charset .forName ("UTF-8" ), format );
164- for (final CSVRecord record : parser ) {
165- String parsed = Arrays .toString (record .values ());
166- if (checkComments ) {
167- final String comment = record .getComment ().replace ("\n " , "\\ n" );
168- if (comment != null ) {
169- parsed += "#" + comment ;
163+ try (final CSVParser parser = CSVParser .parse (resource , Charset .forName ("UTF-8" ), format )) {
164+ for (final CSVRecord record : parser ) {
165+ String parsed = Arrays .toString (record .values ());
166+ if (checkComments ) {
167+ final String comment = record .getComment ().replace ("\n " , "\\ n" );
168+ if (comment != null ) {
169+ parsed += "#" + comment ;
170+ }
170171 }
172+ final int count = record .size ();
173+ assertEquals (testName , readTestData (), count + ":" + parsed );
171174 }
172- final int count = record .size ();
173- assertEquals (testName , readTestData (), count + ":" + parsed );
174175 }
175- parser .close ();
176176 }
177177}
0 commit comments