Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4B555200CAD for ; Mon, 5 Jun 2017 15:44:56 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4A1BB160BD4; Mon, 5 Jun 2017 13:44:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 73429160BBF for ; Mon, 5 Jun 2017 15:44:55 +0200 (CEST) Received: (qmail 94220 invoked by uid 500); 5 Jun 2017 13:44:54 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 94211 invoked by uid 99); 5 Jun 2017 13:44:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jun 2017 13:44:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 32F39DFFAB; Mon, 5 Jun 2017 13:44:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chtompki@apache.org To: commits@commons.apache.org Date: Mon, 05 Jun 2017 13:44:54 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] [text] [junit]: Added test cases for CsvTranslators archived-at: Mon, 05 Jun 2017 13:44:56 -0000 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 Authored: Fri Jun 2 23:54:23 2017 +0530 Committer: Amey Jadiye 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"); + + } + +}