1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.csv.issues;
20
21 import static org.apache.commons.csv.CsvAssertions.assertValuesEquals;
22
23 import java.io.IOException;
24 import java.io.StringReader;
25 import java.util.Iterator;
26
27 import org.apache.commons.csv.CSVFormat;
28 import org.apache.commons.csv.CSVParser;
29 import org.apache.commons.csv.CSVRecord;
30 import org.apache.commons.csv.QuoteMode;
31 import org.junit.jupiter.api.Test;
32
33
34
35
36 class JiraCsv253Test {
37
38 @Test
39 void testHandleAbsentValues() throws IOException {
40
41 final String source =
42 "\"John\",,\"Doe\"\n" +
43 ",\"AA\",123\n" +
44 "\"John\",90,\n" +
45 "\"\",,90";
46
47 final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.NON_NUMERIC).get();
48 try (CSVParser parser = csvFormat.parse(new StringReader(source))) {
49 final Iterator<CSVRecord> csvRecords = parser.iterator();
50 assertValuesEquals(new String[] {"John", null, "Doe"}, csvRecords.next());
51 assertValuesEquals(new String[] {null, "AA", "123"}, csvRecords.next());
52 assertValuesEquals(new String[] {"John", "90", null}, csvRecords.next());
53 assertValuesEquals(new String[] {"", null, "90"}, csvRecords.next());
54 }
55 }
56 }