View Javadoc
1   package integrationTest.Bug259;
2   
3   import com.opencsv.CSVParser;
4   import com.opencsv.CSVReader;
5   import com.opencsv.CSVReaderBuilder;
6   import com.opencsv.RFC4180Parser;
7   import com.opencsv.exceptions.CsvValidationException;
8   import org.junit.jupiter.api.DisplayName;
9   import org.junit.jupiter.api.Test;
10  
11  import java.io.IOException;
12  import java.io.StringReader;
13  
14  import static org.junit.jupiter.api.Assertions.assertEquals;
15  import static org.junit.jupiter.api.Assertions.assertNotNull;
16  
17  public class DoubleNewLineTest {
18  
19      @Test
20      @DisplayName("Test double new line issue with the RFC4180 Parser.")
21      public void doubleNewLineWithRFCParser() throws CsvValidationException, IOException {
22          CSVReader reader = new CSVReaderBuilder(new StringReader("Hello\n\nWorld"))
23                  .withCSVParser(new RFC4180Parser())
24                  .build();
25  
26          String[] line = null;
27          line = reader.readNext();
28          assertNotNull(line);
29          assertEquals(1, line.length);
30  
31          line = reader.readNext();
32          assertNotNull(line);
33          assertEquals(1, line.length);
34  
35          line = reader.readNext();
36          assertNotNull(line);
37          assertEquals(1, line.length);
38      }
39  
40      @Test
41      @DisplayName("Test double new line issue with the CSVParser.")
42      public void doubleNewLineWithCSVParser() throws CsvValidationException, IOException {
43          CSVReader reader = new CSVReaderBuilder(new StringReader("Hello\n\nWorld"))
44                  .withCSVParser(new CSVParser())
45                  .build();
46  
47          String[] line = null;
48          line = reader.readNext();
49          assertNotNull(line);
50          assertEquals(1, line.length);
51  
52          line = reader.readNext();
53          assertNotNull(line);
54          assertEquals(1, line.length);
55  
56          line = reader.readNext();
57          assertNotNull(line);
58          assertEquals(1, line.length);
59      }
60  
61  }