Skip to content

Commit f25649c

Browse files
committed
[CSV-211] Add JiraCsv211Test
1 parent d378f3e commit f25649c

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.commons.csv.issues;
18+
19+
import org.apache.commons.csv.CSVFormat;
20+
import org.apache.commons.csv.CSVParser;
21+
import org.apache.commons.csv.CSVRecord;
22+
import org.junit.jupiter.api.Test;
23+
24+
import java.io.IOException;
25+
import java.io.StringReader;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
29+
public class JiraCsv211Test {
30+
31+
@Test
32+
public void testJiraCsv211Format() throws IOException {
33+
final String[] values = new String[]{"1", "Jane Doe", "USA", ""};
34+
35+
final CSVFormat printFormat = CSVFormat.DEFAULT.withDelimiter('\t').withHeader("ID", "Name", "Country", "Age");
36+
String formatted = printFormat.format(values);
37+
assertEquals("ID\tName\tCountry\tAge\r\n1\tJane Doe\tUSA\t", formatted);
38+
39+
final CSVFormat parseFormat = CSVFormat.DEFAULT.withDelimiter('\t').withFirstRecordAsHeader();
40+
CSVParser parser = parseFormat.parse(new StringReader(formatted));
41+
for (CSVRecord record : parser) {
42+
assertEquals("1", record.get(0));
43+
assertEquals("Jane Doe", record.get(1));
44+
assertEquals("USA", record.get(2));
45+
assertEquals("", record.get(3));
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)