@@ -113,9 +113,7 @@ private BOMInputStream createBOMInputStream(final String resource) throws IOExce
113113 }
114114
115115 private void parseFully (final CSVParser parser ) {
116- for (final CSVRecord csvRecord : parser ) {
117- assertNotNull (csvRecord );
118- }
116+ parser .forEach (record -> assertNotNull (record ));
119117 }
120118
121119 @ Test
@@ -208,47 +206,31 @@ public void testBackslashEscapingOld() throws IOException {
208206 public void testBOM () throws IOException {
209207 final URL url = ClassLoader .getSystemClassLoader ().getResource ("org/apache/commons/csv/CSVFileParser/bom.csv" );
210208 try (final CSVParser parser = CSVParser .parse (url , Charset .forName (UTF_8_NAME ), CSVFormat .EXCEL .withHeader ())) {
211- for (final CSVRecord record : parser ) {
212- final String string = record .get ("Date" );
213- assertNotNull (string );
214- // System.out.println("date: " + record.get("Date"));
215- }
209+ parser .forEach (record -> assertNotNull (record .get ("Date" )));
216210 }
217211 }
218212
219213 @ Test
220214 public void testBOMInputStream_ParserWithInputStream () throws IOException {
221215 try (final BOMInputStream inputStream = createBOMInputStream ("org/apache/commons/csv/CSVFileParser/bom.csv" );
222216 final CSVParser parser = CSVParser .parse (inputStream , UTF_8 , CSVFormat .EXCEL .withHeader ())) {
223- for (final CSVRecord record : parser ) {
224- final String string = record .get ("Date" );
225- assertNotNull (string );
226- // System.out.println("date: " + record.get("Date"));
227- }
217+ parser .forEach (record -> assertNotNull (record .get ("Date" )));
228218 }
229219 }
230220
231221 @ Test
232222 public void testBOMInputStream_ParserWithReader () throws IOException {
233223 try (final Reader reader = new InputStreamReader (createBOMInputStream ("org/apache/commons/csv/CSVFileParser/bom.csv" ), UTF_8_NAME );
234224 final CSVParser parser = new CSVParser (reader , CSVFormat .EXCEL .withHeader ())) {
235- for (final CSVRecord record : parser ) {
236- final String string = record .get ("Date" );
237- assertNotNull (string );
238- // System.out.println("date: " + record.get("Date"));
239- }
225+ parser .forEach (record -> assertNotNull (record .get ("Date" )));
240226 }
241227 }
242228
243229 @ Test
244230 public void testBOMInputStream_parseWithReader () throws IOException {
245231 try (final Reader reader = new InputStreamReader (createBOMInputStream ("org/apache/commons/csv/CSVFileParser/bom.csv" ), UTF_8_NAME );
246232 final CSVParser parser = CSVParser .parse (reader , CSVFormat .EXCEL .withHeader ())) {
247- for (final CSVRecord record : parser ) {
248- final String string = record .get ("Date" );
249- assertNotNull (string );
250- // System.out.println("date: " + record.get("Date"));
251- }
233+ parser .forEach (record -> assertNotNull (record .get ("Date" )));
252234 }
253235 }
254236
@@ -476,11 +458,11 @@ public void testExcelFormat2() throws Exception {
476458 public void testExcelHeaderCountLessThanData () throws Exception {
477459 final String code = "A,B,C,,\r \n a,b,c,d,e\r \n " ;
478460 try (final CSVParser parser = CSVParser .parse (code , CSVFormat .EXCEL .withHeader ())) {
479- for ( final CSVRecord record : parser .getRecords ()) {
461+ parser .getRecords (). forEach ( record -> {
480462 assertEquals ("a" , record .get ("A" ));
481463 assertEquals ("b" , record .get ("B" ));
482464 assertEquals ("c" , record .get ("C" ));
483- }
465+ });
484466 }
485467 }
486468
@@ -516,8 +498,8 @@ public void testFirstEndOfLineLf() throws IOException {
516498
517499 @ Test
518500 public void testForEach () throws Exception {
519- final List <CSVRecord > records = new ArrayList <>();
520501 try (final Reader in = new StringReader ("a,b,c\n 1,2,3\n x,y,z" ); final CSVParser parser = CSVFormat .DEFAULT .parse (in )) {
502+ final List <CSVRecord > records = new ArrayList <>();
521503 for (final CSVRecord record : parser ) {
522504 records .add (record );
523505 }
0 commit comments