@@ -1643,58 +1643,4 @@ private void validateRecordPosition(final String lineSeparator) throws IOExcepti
16431643 parser .close ();
16441644 }
16451645
1646- @ Test
1647- public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1 () throws IOException {
1648- String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n " +
1649- "rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\" \" rec9\" \" ,rec10" ;
1650-
1651- StringReader stringReader = new StringReader (csvContent );
1652- CSVFormat csvFormat = CSVFormat .DEFAULT .builder ()
1653- .setHeader ()
1654- .setSkipHeaderRecord (true )
1655- .build ();
1656-
1657- CSVParser csvParser = csvFormat .parse (stringReader );
1658- Exception exception = assertThrows (UncheckedIOException .class , () -> {
1659- for (CSVRecord record : csvParser ) {
1660- String content = record .get (0 ) + " " + record .get (1 ) + " " + record .get (2 ) + " " + record .get (3 )
1661- + " " + record .get (4 ) + " " + record .get (5 ) + " " + record .get (6 ) + " " + record .get (7 )
1662- + " " + record .get (8 ) + " " + record .get (9 );
1663- assertNotNull (content );
1664- }
1665- });
1666- String expectedErrorMessage = "Exception reading next record: java.io.IOException: Exception during parsing at " +
1667- "line: 2, position: 94" ;
1668- String actualMessage = exception .getMessage ();
1669- assertTrue (actualMessage .contains (expectedErrorMessage ));
1670- String expectedLastParsedContent = "...rec4,rec5,rec6,rec7,rec8" ;
1671- assertEquals (expectedLastParsedContent , csvParser .getLastParsedContent ());
1672- }
1673-
1674- @ Test
1675- public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_2 () throws IOException {
1676- String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8\n " +
1677- "rec1,rec2,rec3,rec4,\" \" rec5\" \" ,rec6,rec7,rec8" ;
1678-
1679- StringReader stringReader = new StringReader (csvContent );
1680- CSVFormat csvFormat = CSVFormat .DEFAULT .builder ()
1681- .setHeader ()
1682- .setSkipHeaderRecord (true )
1683- .build ();
1684-
1685- CSVParser csvParser = csvFormat .parse (stringReader );
1686- Exception exception = assertThrows (UncheckedIOException .class , () -> {
1687- for (CSVRecord record : csvParser ) {
1688- String content = record .get (0 ) + " " + record .get (1 ) + " " + record .get (2 ) + " " + record .get (3 )
1689- + " " + record .get (4 ) + " " + record .get (5 ) + " " + record .get (6 ) + " " + record .get (7 );
1690- assertNotNull (content );
1691- }
1692- });
1693- String expectedErrorMessage = "Exception reading next record: java.io.IOException: Exception during parsing at " +
1694- "line: 2, position: 63" ;
1695- String actualMessage = exception .getMessage ();
1696- assertTrue (actualMessage .contains (expectedErrorMessage ));
1697- String expectedLastParsedContent = "rec1,rec2,rec3,rec4" ;
1698- assertEquals (expectedLastParsedContent , csvParser .getLastParsedContent ());
1699- }
17001646}
0 commit comments