commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chtom...@apache.org
Subject [1/2] [text] [junit]: Added test cases for CsvTranslators
Date Mon, 05 Jun 2017 13:44:54 GMT
Repository: commons-text
Updated Branches:
  refs/heads/master da8e7a95f -> 5f498c0f4


[junit]: Added test cases for CsvTranslators


Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/e85959f7
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/e85959f7
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/e85959f7

Branch: refs/heads/master
Commit: e85959f7a2caa98b942d4b8a3e1132da7024bda5
Parents: 343b4a9
Author: Amey Jadiye <ameyjadiye@gmail.com>
Authored: Fri Jun 2 23:54:23 2017 +0530
Committer: Amey Jadiye <ameyjadiye@gmail.com>
Committed: Sat Jun 3 00:54:23 2017 +0530

----------------------------------------------------------------------
 .../text/translate/CsvTranslatorsTest.java      | 137 +++++++++++++++++++
 1 file changed, 137 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/e85959f7/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java b/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java
new file mode 100644
index 0000000..6d1e721
--- /dev/null
+++ b/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.text.translate;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.apache.commons.lang3.CharUtils;
+import org.junit.Test;
+
+public class CsvTranslatorsTest {
+
+	@Test
+	public void csvEscaperPlaneTextTest() throws IOException{
+		final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+		final Writer writer = new StringWriter();
+		final String input = "hi this is just a plane text nothing to do with csv!";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, input);
+	}
+
+	@Test
+	public void csvEscaperCommaTest() throws IOException{
+		final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+		final Writer writer = new StringWriter();
+		final String input = "hi,this,is,a,test";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, "\"hi,this,is,a,test\"");
+
+	}
+
+	@Test
+	public void csvEscaperQuoteTest() throws IOException{
+		final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+		final Writer writer = new StringWriter();
+		final String input = "hi,this,is,a,\"quote,test";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, "\"hi,this,is,a,\"\"quote,test\"");
+
+	}
+	@Test
+	public void csvEscaperCRTest() throws IOException{
+		final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+		final Writer writer = new StringWriter();
+		final String input = "hi,this,is,a,CR,test" + String.valueOf(CharUtils.CR);
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, "\"hi,this,is,a,CR,test"+String.valueOf(CharUtils.CR)+"\"");
+
+	}
+	@Test
+	public void csvEscaperLFTest() throws IOException{
+		final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+		final Writer writer = new StringWriter();
+		final String input = "hi,this,is,a,LF,test" + String.valueOf(CharUtils.LF);
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, "\"hi,this,is,a,LF,test" + String.valueOf(CharUtils.LF) +"\"");
+
+	}
+
+	@Test
+	public void csvUnEscaperPlaneTextTest() throws IOException{
+		final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+		final Writer writer = new StringWriter();
+		final String input = "hi,this,is,unescape,test";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, "hi,this,is,unescape,test");
+
+	}
+
+	@Test
+	public void csvUnEscaperTest1() throws IOException{
+		final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+		final Writer writer = new StringWriter();
+		final String input = "\"hi,this,is,unescape,test\"";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, "hi,this,is,unescape,test");
+
+	}
+
+	@Test
+	public void csvUnEscaperTest2() throws IOException{
+		final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+		final Writer writer = new StringWriter();
+		final String input = "\"hi,this,is,unescape,test";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, input);
+
+	}
+
+	@Test
+	public void csvUnEscaperTest3() throws IOException{
+		final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+		final Writer writer = new StringWriter();
+		final String input = "hi,this,is,unescape,test\"";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, input);
+
+	}
+
+	@Test
+	public void csvUnEscaperTest4() throws IOException{
+		final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+		final Writer writer = new StringWriter();
+		final String input = "\"hi,this,is,\"unescape,test\"";
+		escaper.translateWhole(input, writer);
+		String data = writer.toString();
+		assertEquals(data, "hi,this,is,\"unescape,test");
+
+	}
+
+}


Mime
View raw message