X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.util%2Fext%2Ftest%2Forg%2Fargeo%2Futil%2FCsvParserWithQuotedSeparatorTest.java;h=f4095bb72698577a09a59eea2ab0d4f1dbac4f87;hb=438237c2b8c995d4f9562d53bfe4ea63c4442054;hp=d4131a04621b9226ad923b28388fbcb80e225463;hpb=9885228c89ca6da1835c1c3e098c92589d76301e;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.util/ext/test/org/argeo/util/CsvParserWithQuotedSeparatorTest.java b/org.argeo.util/ext/test/org/argeo/util/CsvParserWithQuotedSeparatorTest.java index d4131a046..f4095bb72 100644 --- a/org.argeo.util/ext/test/org/argeo/util/CsvParserWithQuotedSeparatorTest.java +++ b/org.argeo.util/ext/test/org/argeo/util/CsvParserWithQuotedSeparatorTest.java @@ -21,9 +21,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - -public class CsvParserWithQuotedSeparatorTest extends TestCase { +/** Test that {@link CsvParser} deals properly with "" quotes. */ +public class CsvParserWithQuotedSeparatorTest { public void testSimpleParse() throws Exception { String toParse = "Header1,\"Header2\",Header3,\"Header4\"\n" + "\"Col1, Col2\",\"Col\n2\",Col3,\"\"\"Col4\"\"\"\n"; @@ -31,11 +30,10 @@ public class CsvParserWithQuotedSeparatorTest extends TestCase { InputStream in = new ByteArrayInputStream(toParse.getBytes()); CsvParser csvParser = new CsvParser() { - protected void processLine(Integer lineNumber, List header, - List tokens) { - assertEquals(header.size(), tokens.size()); - assertEquals(4, tokens.size()); - assertEquals("Col1, Col2", tokens.get(0)); + protected void processLine(Integer lineNumber, List header, List tokens) { + assert header.size() == tokens.size(); + assert 4 == tokens.size(); + assert "Col1, Col2".equals(tokens.get(0)); } }; // System.out.println(toParse); @@ -47,12 +45,10 @@ public class CsvParserWithQuotedSeparatorTest extends TestCase { public void testParseFile() throws Exception { final Map> lines = new HashMap>(); - InputStream in = getClass().getResourceAsStream( - "/org/argeo/util/ReferenceFile.csv"); + InputStream in = getClass().getResourceAsStream("/org/argeo/util/ReferenceFile.csv"); CsvParserWithLinesAsMap parser = new CsvParserWithLinesAsMap() { - protected void processLine(Integer lineNumber, - Map line) { + protected void processLine(Integer lineNumber, Map line) { // System.out.println("processing line #" + lineNumber); lines.put(lineNumber, line); } @@ -62,17 +58,16 @@ public class CsvParserWithQuotedSeparatorTest extends TestCase { in.close(); Map line = lines.get(2); - assertEquals(",,,,", line.get("Coma testing")); + assert ",,,,".equals(line.get("Coma testing")); line = lines.get(3); - assertEquals(",, ,,", line.get("Coma testing")); + assert ",, ,,".equals(line.get("Coma testing")); line = lines.get(4); - assertEquals("module1, module2", line.get("Coma testing")); + assert "module1, module2".equals(line.get("Coma testing")); line = lines.get(5); - assertEquals("module1,module2", line.get("Coma testing")); + assert "module1,module2".equals(line.get("Coma testing")); line = lines.get(6); - assertEquals(",module1,module2, \nmodule3, module4", - line.get("Coma testing")); - assertEquals(5, lines.size()); + assert ",module1,module2, \nmodule3, module4".equals(line.get("Coma testing")); + assert 5 == lines.size(); } }