Skip to content

Commit c2ed3be

Browse files
committed
Add API org.apache.commons.csv.CSVParser.getRecords(T).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1584903 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6b3afdc commit c2ed3be

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.nio.charset.Charset;
3939
import java.util.ArrayList;
4040
import java.util.Iterator;
41+
import java.util.LinkedList;
4142
import java.util.List;
4243
import java.util.Map;
4344
import java.util.NoSuchElementException;
@@ -66,6 +67,8 @@ public class CSVParserTest {
6667
// + " \"foo\n,,\n\"\",,\n\\\"\",d,e\n";
6768
+ " \"foo\n,,\n\"\",,\n\"\"\",d,e\n"; // changed to use standard CSV escaping
6869

70+
private static final String CSV_INPUT_1 = "a,b,c,d";
71+
6972
private static final String[][] RESULT = {
7073
{"a", "b", "c", "d"},
7174
{"a", "b", "1 2"},
@@ -511,6 +514,22 @@ public void testGetLineNumberWithLF() throws Exception {
511514
this.validateLineNumbers(String.valueOf(LF));
512515
}
513516

517+
@Test
518+
public void testGetOneLine() throws IOException {
519+
final CSVParser parser = CSVParser.parse(CSV_INPUT_1, CSVFormat.DEFAULT);
520+
final CSVRecord record = parser.getRecords().get(0);
521+
assertArrayEquals(RESULT[0], record.values());
522+
parser.close();
523+
}
524+
525+
@Test
526+
public void testGetOneLineCustomCollection() throws IOException {
527+
final CSVParser parser = CSVParser.parse(CSV_INPUT_1, CSVFormat.DEFAULT);
528+
final CSVRecord record = parser.getRecords(new LinkedList<CSVRecord>()).getFirst();
529+
assertArrayEquals(RESULT[0], record.values());
530+
parser.close();
531+
}
532+
514533
@Test
515534
public void testGetRecordNumberWithCR() throws Exception {
516535
this.validateRecordNumbers(String.valueOf(CR));

0 commit comments

Comments
 (0)