@@ -1644,7 +1644,7 @@ private void validateRecordPosition(final String lineSeparator) throws IOExcepti
16441644 }
16451645
16461646 @ Test
1647- public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1 () {
1647+ public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1 () throws IOException {
16481648 String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n " +
16491649 "rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\" \" rec9\" \" ,rec10" ;
16501650
@@ -1654,22 +1654,17 @@ public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1()
16541654 .setSkipHeaderRecord (true )
16551655 .build ();
16561656
1657- CSVParser csvParser = null ;
1658- try {
1659- csvParser = csvFormat .parse (stringReader );
1660- } catch (IOException e ) {
1661- fail ("Failed to parse the CSV content" );
1662- }
1663- final Iterable <CSVRecord > finalRecords = csvParser ;
1657+ CSVParser csvParser = csvFormat .parse (stringReader );
16641658 Exception exception = assertThrows (UncheckedIOException .class , () -> {
1665- for (CSVRecord record : finalRecords ) {
1666- System . out . println ( record .get (0 ) + " " + record .get (1 ) + " " + record .get (2 ) + " " + record .get (3 )
1659+ for (CSVRecord record : csvParser ) {
1660+ String content = record .get (0 ) + " " + record .get (1 ) + " " + record .get (2 ) + " " + record .get (3 )
16671661 + " " + record .get (4 ) + " " + record .get (5 ) + " " + record .get (6 ) + " " + record .get (7 )
1668- + " " + record .get (8 ) + " " + record .get (9 ));
1662+ + " " + record .get (8 ) + " " + record .get (9 );
1663+ assertNotNull (content );
16691664 }
16701665 });
1671- String expectedErrorMessage = "Exception reading next record: java.io.IOException: An exception occurred " +
1672- "while parsing the CSV content. Issue in line: 2, position: 94" ;
1666+ String expectedErrorMessage = "Exception reading next record: java.io.IOException: Exception during parsing at " +
1667+ "line: 2, position: 94" ;
16731668 String actualMessage = exception .getMessage ();
16741669 assertTrue (actualMessage .contains (expectedErrorMessage ));
16751670 assertNotNull (csvParser );
@@ -1678,7 +1673,7 @@ public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1()
16781673 }
16791674
16801675 @ Test
1681- public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_2 () {
1676+ public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_2 () throws IOException {
16821677 String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8\n " +
16831678 "rec1,rec2,rec3,rec4,\" \" rec5\" \" ,rec6,rec7,rec8" ;
16841679
@@ -1688,21 +1683,16 @@ public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_2()
16881683 .setSkipHeaderRecord (true )
16891684 .build ();
16901685
1691- CSVParser csvParser = null ;
1692- try {
1693- csvParser = csvFormat .parse (stringReader );
1694- } catch (IOException e ) {
1695- fail ("Failed to parse the CSV content" );
1696- }
1697- final Iterable <CSVRecord > finalRecords = csvParser ;
1686+ CSVParser csvParser = csvFormat .parse (stringReader );
16981687 Exception exception = assertThrows (UncheckedIOException .class , () -> {
1699- for (CSVRecord record : finalRecords ) {
1700- System .out .println (record .get (0 ) + " " + record .get (1 ) + " " + record .get (2 ) + " " + record .get (3 )
1701- + " " + record .get (4 ) + " " + record .get (5 ) + " " + record .get (6 ) + " " + record .get (7 ));
1688+ for (CSVRecord record : csvParser ) {
1689+ String content = record .get (0 ) + " " + record .get (1 ) + " " + record .get (2 ) + " " + record .get (3 )
1690+ + " " + record .get (4 ) + " " + record .get (5 ) + " " + record .get (6 ) + " " + record .get (7 );
1691+ assertNotNull (content );
17021692 }
17031693 });
1704- String expectedErrorMessage = "Exception reading next record: java.io.IOException: An exception occurred " +
1705- "while parsing the CSV content. Issue in line: 2, position: 63" ;
1694+ String expectedErrorMessage = "Exception reading next record: java.io.IOException: Exception during parsing at " +
1695+ "line: 2, position: 63" ;
17061696 String actualMessage = exception .getMessage ();
17071697 assertTrue (actualMessage .contains (expectedErrorMessage ));
17081698 assertNotNull (csvParser );
0 commit comments