]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java
Add unit case to test csv import with some line feed.
[lgpl/argeo-commons.git] / basic / runtime / org.argeo.basic.nodeps / src / test / java / org / argeo / util / CsvParserParseFileTest.java
diff --git a/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java b/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java
new file mode 100644 (file)
index 0000000..4a134a5
--- /dev/null
@@ -0,0 +1,33 @@
+package org.argeo.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class CsvParserParseFileTest extends TestCase {
+       public void testParse() throws Exception {
+               String toParse = "Header1,\"Header2\",Header3,\"Header4\"\n"
+                               + "Col1,\"Col\n2\",Col3,\"\"\"Col4\"\"\"\n"
+                               + "Col1,\"Col\n2\",Col3,\"\"\"Col4\"\"\"\n"
+                               + "Col1,\"Col\n2\",Col3,\"\"\"Col4\"\"\"\n";
+
+               InputStream in = new ByteArrayInputStream(toParse.getBytes());
+
+               CsvParser csvParser = new CsvParser() {
+                       protected void processLine(Integer lineNumber, List<String> header,
+                                       List<String> tokens) {
+                               assertEquals(header.size(), tokens.size());
+                               assertEquals(4, tokens.size());
+                               assertEquals("Col1", tokens.get(0));
+                               assertEquals("Col\n2", tokens.get(1));
+                               assertEquals("Col3", tokens.get(2));
+                               assertEquals("\"Col4\"", tokens.get(3));
+                       }
+               };
+
+               csvParser.parse(in);
+               in.close();
+       }
+}