@@ -1374,6 +1374,41 @@ public void testParseWithQuoteWithEscape() throws IOException {
13741374 assertEquals ("xyz" , csvRecord .get (1 ));
13751375 }
13761376 }
1377+ @ Test
1378+ public void testParsingPrintedEmptyFirstColumn () throws Exception {
1379+ String [][] lines = new String [][] {
1380+ {"a" , "b" },
1381+ {"" , "x" }
1382+ };
1383+ Exception firstException = null ;
1384+ for (CSVFormat .Predefined format : CSVFormat .Predefined .values ()) {
1385+ try {
1386+ StringWriter buf = new StringWriter ();
1387+ try (CSVPrinter printer = new CSVPrinter (buf , format .getFormat ())) {
1388+ for (String [] line : lines ) {
1389+ printer .printRecord ((Object []) line );
1390+ }
1391+ }
1392+ try (CSVParser csvRecords = new CSVParser (new StringReader (buf .toString ()), format .getFormat ())) {
1393+ for (String [] line : lines ) {
1394+ assertArrayEquals (line , csvRecords .nextRecord ().values ());
1395+ }
1396+ assertNull (csvRecords .nextRecord ());
1397+ }
1398+ } catch (Exception | Error e ) {
1399+ Exception detailedException = new RuntimeException ("format: " + format , e );
1400+ if (firstException == null ) {
1401+ firstException = detailedException ;
1402+ } else {
1403+ firstException .addSuppressed (detailedException );
1404+ }
1405+ }
1406+ }
1407+
1408+ if (firstException != null )
1409+ throw firstException ;
1410+ }
1411+
13771412 @ Test
13781413 public void testProvidedHeader () throws Exception {
13791414 final Reader in = new StringReader ("a,b,c\n 1,2,3\n x,y,z" );
@@ -1562,41 +1597,6 @@ public void testTrim() throws Exception {
15621597 assertEquals (3 , record .size ());
15631598 }}
15641599
1565- @ Test
1566- public void testParsingPrintedEmptyFirstColumn () throws Exception {
1567- String [][] lines = new String [][] {
1568- {"a" , "b" },
1569- {"" , "x" }
1570- };
1571- Exception firstException = null ;
1572- for (CSVFormat .Predefined format : CSVFormat .Predefined .values ()) {
1573- try {
1574- StringWriter buf = new StringWriter ();
1575- try (CSVPrinter printer = new CSVPrinter (buf , format .getFormat ())) {
1576- for (String [] line : lines ) {
1577- printer .printRecord ((Object []) line );
1578- }
1579- }
1580- try (CSVParser csvRecords = new CSVParser (new StringReader (buf .toString ()), format .getFormat ())) {
1581- for (String [] line : lines ) {
1582- assertArrayEquals (line , csvRecords .nextRecord ().values ());
1583- }
1584- assertNull (csvRecords .nextRecord ());
1585- }
1586- } catch (Exception | Error e ) {
1587- Exception detailedException = new RuntimeException ("format: " + format , e );
1588- if (firstException == null ) {
1589- firstException = detailedException ;
1590- } else {
1591- firstException .addSuppressed (detailedException );
1592- }
1593- }
1594- }
1595-
1596- if (firstException != null )
1597- throw firstException ;
1598- }
1599-
16001600 private void validateLineNumbers (final String lineSeparator ) throws IOException {
16011601 try (final CSVParser parser = CSVParser .parse ("a" + lineSeparator + "b" + lineSeparator + "c" , CSVFormat .DEFAULT .withRecordSeparator (lineSeparator ))) {
16021602 assertEquals (0 , parser .getCurrentLineNumber ());
0 commit comments