You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2014/04/07 16:29:32 UTC
svn commit: r1585491 -
/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
Author: ggregory
Date: Mon Apr 7 14:29:32 2014
New Revision: 1585491
URL: http://svn.apache.org/r1585491
Log:
Add org.apache.commons.csv.CSVParserTest.testGetOneLineOneParser(). See discussion in [CSV-110].
Modified:
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1585491&r1=1585490&r2=1585491&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Mon Apr 7 14:29:32 2014
@@ -31,6 +31,8 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.PipedReader;
+import java.io.PipedWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
@@ -69,6 +71,8 @@ public class CSVParserTest {
private static final String CSV_INPUT_1 = "a,b,c,d";
+ private static final String CSV_INPUT_2 = "a,b,1 2";
+
private static final String[][] RESULT = {
{"a", "b", "c", "d"},
{"a", "b", "1 2"},
@@ -530,6 +534,29 @@ public class CSVParserTest {
parser.close();
}
+ /**
+ * Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110].
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testGetOneLineOneParser() throws IOException {
+ PipedWriter writer = new PipedWriter();
+ PipedReader reader = new PipedReader(writer);
+ final CSVFormat format = CSVFormat.DEFAULT;
+ final CSVParser parser = new CSVParser(reader, format);
+ try {
+ writer.append(CSV_INPUT_1 + format.getRecordSeparator());
+ final CSVRecord record1 = parser.nextRecord();
+ assertArrayEquals(RESULT[0], record1.values());
+ writer.append(CSV_INPUT_2 + format.getRecordSeparator());
+ final CSVRecord record2 = parser.nextRecord();
+ assertArrayEquals(RESULT[1], record2.values());
+ } finally {
+ parser.close();
+ }
+ }
+
@Test
public void testGetRecordNumberWithCR() throws Exception {
this.validateRecordNumbers(String.valueOf(CR));