1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.csv.issues;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23
24 import java.io.IOException;
25 import java.io.StringReader;
26
27 import org.apache.commons.csv.CSVFormat;
28 import org.apache.commons.csv.CSVParser;
29 import org.junit.jupiter.api.Test;
30
31 class JiraCsv211Test {
32
33 @Test
34 void testJiraCsv211Format() throws IOException {
35
36 final CSVFormat printFormat = CSVFormat.DEFAULT.builder()
37 .setDelimiter('\t')
38 .setHeader("ID", "Name", "Country", "Age")
39 .get();
40
41 final String formatted = printFormat.format("1", "Jane Doe", "USA", "");
42 assertEquals("ID\tName\tCountry\tAge\r\n1\tJane Doe\tUSA\t", formatted);
43
44 final CSVFormat parseFormat = CSVFormat.DEFAULT.builder().setDelimiter('\t').setHeader().setSkipHeaderRecord(true).get();
45 try (CSVParser parser = parseFormat.parse(new StringReader(formatted))) {
46 parser.forEach(record -> {
47 assertEquals("1", record.get(0));
48 assertEquals("Jane Doe", record.get(1));
49 assertEquals("USA", record.get(2));
50 assertEquals("", record.get(3));
51 });
52 }
53 }
54 }