gbidsilva commented on code in PR #347:
URL: https://github.com/apache/commons-csv/pull/347#discussion_r1311708454


##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -1642,4 +1643,70 @@ private void validateRecordPosition(final String 
lineSeparator) throws IOExcepti
         parser.close();
     }
 
+    @Test
+    public void 
testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1() {
+        String csvContent = 
"col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n" +
+                "rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\"\"rec9\"\",rec10";
+
+        StringReader stringReader = new StringReader(csvContent);
+        CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
+                .setHeader()
+                .setSkipHeaderRecord(true)
+                .build();
+
+        CSVParser csvParser = null;
+        try {
+            csvParser = csvFormat.parse(stringReader);
+        } catch (IOException e) {
+            fail("Failed to parse the CSV content");
+        }
+        final Iterable<CSVRecord> finalRecords = csvParser;
+        Exception exception = assertThrows(UncheckedIOException.class, () -> {
+            for (CSVRecord record : finalRecords) {
+                System.out.println(record.get(0) + " " + record.get(1) + " " + 
record.get(2) + " " + record.get(3)
+                        + " " + record.get(4) + " " + record.get(5) + " " + 
record.get(6) + " " + record.get(7)
+                        + " " + record.get(8) + " " + record.get(9));
+            }
+        });
+        String expectedErrorMessage = "Exception reading next record: 
java.io.IOException: An exception occurred " +
+                "while parsing the CSV content. Issue in line: 2, position: 
94";
+        String actualMessage = exception.getMessage();
+        assertTrue(actualMessage.contains(expectedErrorMessage));
+        assertNotNull(csvParser);

Review Comment:
   Got it!
   I was referring to something else.
   Removed.



##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -1642,4 +1643,70 @@ private void validateRecordPosition(final String 
lineSeparator) throws IOExcepti
         parser.close();
     }
 
+    @Test
+    public void 
testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1() {
+        String csvContent = 
"col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n" +
+                "rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\"\"rec9\"\",rec10";
+
+        StringReader stringReader = new StringReader(csvContent);
+        CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
+                .setHeader()
+                .setSkipHeaderRecord(true)
+                .build();
+
+        CSVParser csvParser = null;
+        try {
+            csvParser = csvFormat.parse(stringReader);
+        } catch (IOException e) {
+            fail("Failed to parse the CSV content");
+        }
+        final Iterable<CSVRecord> finalRecords = csvParser;
+        Exception exception = assertThrows(UncheckedIOException.class, () -> {
+            for (CSVRecord record : finalRecords) {
+                System.out.println(record.get(0) + " " + record.get(1) + " " + 
record.get(2) + " " + record.get(3)
+                        + " " + record.get(4) + " " + record.get(5) + " " + 
record.get(6) + " " + record.get(7)
+                        + " " + record.get(8) + " " + record.get(9));
+            }
+        });
+        String expectedErrorMessage = "Exception reading next record: 
java.io.IOException: An exception occurred " +
+                "while parsing the CSV content. Issue in line: 2, position: 
94";
+        String actualMessage = exception.getMessage();
+        assertTrue(actualMessage.contains(expectedErrorMessage));
+        assertNotNull(csvParser);
+        String expectedLastParsedContent = "...rec4,rec5,rec6,rec7,rec8";
+        assertEquals(expectedLastParsedContent, 
csvParser.getLastParsedContent());
+    }
+
+    @Test
+    public void 
testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_2() {
+        String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8\n" +
+                "rec1,rec2,rec3,rec4,\"\"rec5\"\",rec6,rec7,rec8";
+
+        StringReader stringReader = new StringReader(csvContent);
+        CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
+                .setHeader()
+                .setSkipHeaderRecord(true)
+                .build();
+
+        CSVParser csvParser = null;

Review Comment:
   removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to