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 502C8200B2F for ; Sun, 29 May 2016 04:24:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4EB74160A1A; Sun, 29 May 2016 02:24:55 +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 D9E32160A34 for ; Sun, 29 May 2016 04:24:52 +0200 (CEST) Received: (qmail 24400 invoked by uid 500); 29 May 2016 02:24:52 -0000 Mailing-List: contact notifications-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 notifications@commons.apache.org Received: (qmail 24391 invoked by uid 99); 29 May 2016 02:24:52 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 May 2016 02:24:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 58E27180591 for ; Sun, 29 May 2016 02:24:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.416 X-Spam-Level: X-Spam-Status: No, score=-0.416 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426, T_FILL_THIS_FORM_SHORT=0.01] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id MbVyu_vCxgK1 for ; Sun, 29 May 2016 02:24:29 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTP id 2B1BC611F3 for ; Sun, 29 May 2016 02:24:11 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id F3557E59E7 for ; Sun, 29 May 2016 02:24:07 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id CEADC3A1018 for ; Sun, 29 May 2016 02:24:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r989464 [38/46] - in /websites/production/commons/content/proper/commons-csv: ./ apidocs/ apidocs/org/apache/commons/csv/ apidocs/org/apache/commons/csv/class-use/ apidocs/resources/ apidocs/src-html/org/apache/commons/csv/ archives/ css/ j... Date: Sun, 29 May 2016 02:24:05 -0000 To: notifications@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160529022407.CEADC3A1018@svn01-us-west.apache.org> archived-at: Sun, 29 May 2016 02:24:55 -0000 Modified: websites/production/commons/content/proper/commons-csv/xref-test/org/apache/commons/csv/CSVFormatTest.html ============================================================================== --- websites/production/commons/content/proper/commons-csv/xref-test/org/apache/commons/csv/CSVFormatTest.html (original) +++ websites/production/commons/content/proper/commons-csv/xref-test/org/apache/commons/csv/CSVFormatTest.html Sun May 29 02:24:04 2016 @@ -1,465 +1,465 @@ - - - -CSVFormatTest xref - - - -
-1   /*
-2    * Licensed to the Apache Software Foundation (ASF) under one or more
-3    * contributor license agreements.  See the NOTICE file distributed with
-4    * this work for additional information regarding copyright ownership.
-5    * The ASF licenses this file to You under the Apache License, Version 2.0
-6    * (the "License"); you may not use this file except in compliance with
-7    * the License.  You may obtain a copy of the License at
-8    *
-9    *      http://www.apache.org/licenses/LICENSE-2.0
-10   *
-11   * Unless required by applicable law or agreed to in writing, software
-12   * distributed under the License is distributed on an "AS IS" BASIS,
-13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-14   * See the License for the specific language governing permissions and
-15   * limitations under the License.
-16   */
-17  
-18  package org.apache.commons.csv;
-19  
-20  import static org.apache.commons.csv.CSVFormat.RFC4180;
-21  import static org.apache.commons.csv.Constants.CR;
-22  import static org.apache.commons.csv.Constants.CRLF;
-23  import static org.apache.commons.csv.Constants.LF;
-24  import static org.junit.Assert.assertArrayEquals;
-25  import static org.junit.Assert.assertEquals;
-26  import static org.junit.Assert.assertFalse;
-27  import static org.junit.Assert.assertNotNull;
-28  import static org.junit.Assert.assertNotSame;
-29  import static org.junit.Assert.assertTrue;
-30  
-31  import java.io.ByteArrayInputStream;
-32  import java.io.ByteArrayOutputStream;
-33  import java.io.ObjectInputStream;
-34  import java.io.ObjectOutputStream;
-35  import java.util.Arrays;
-36  
-37  import org.junit.Assert;
-38  import org.junit.Test;
-39  
-40  /**
-41   *
-42   *
-43   * @version $Id: CSVFormatTest.java 1742178 2016-05-03 18:54:13Z britter $
-44   */
-45  public class CSVFormatTest {
-46  
-47      private static void assertNotEquals(final Object right, final Object left) {
-48          assertFalse(right.equals(left));
-49          assertFalse(left.equals(right));
-50      }
-51  
-52      private static CSVFormat copy(final CSVFormat format) {
-53          return format.withDelimiter(format.getDelimiter());
-54      }
-55  
-56      @Test(expected = IllegalArgumentException.class)
-57      public void testDelimiterSameAsCommentStartThrowsException() {
-58          CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!');
-59      }
-60  
-61      @Test(expected = IllegalArgumentException.class)
-62      public void testDelimiterSameAsEscapeThrowsException() {
-63          CSVFormat.DEFAULT.withDelimiter('!').withEscape('!');
-64      }
-65  
-66      @Test(expected = IllegalArgumentException.class)
-67      public void testDuplicateHeaderElements() {
-68          CSVFormat.DEFAULT.withHeader("A", "A");
-69      }
-70  
-71      @Test
-72      public void testEquals() {
-73          final CSVFormat right = CSVFormat.DEFAULT;
-74          final CSVFormat left = copy(right);
-75  
-76          assertFalse(right.equals(null));
-77          assertFalse(right.equals("A String Instance"));
-78  
-79          assertEquals(right, right);
-80          assertEquals(right, left);
-81          assertEquals(left, right);
-82  
-83          assertEquals(right.hashCode(), right.hashCode());
-84          assertEquals(right.hashCode(), left.hashCode());
-85      }
-86  
-87      @Test
-88      public void testEqualsCommentStart() {
-89          final CSVFormat right = CSVFormat.newFormat('\'')
-90                  .withQuote('"')
-91                  .withCommentMarker('#')
-92                  .withQuoteMode(QuoteMode.ALL);
-93          final CSVFormat left = right
-94                  .withCommentMarker('!');
-95  
-96          assertNotEquals(right, left);
-97      }
-98  
-99      @Test
-100     public void testEqualsDelimiter() {
-101         final CSVFormat right = CSVFormat.newFormat('!');
-102         final CSVFormat left = CSVFormat.newFormat('?');
-103 
-104         assertNotEquals(right, left);
-105     }
-106 
-107     @Test
-108     public void testEqualsEscape() {
-109         final CSVFormat right = CSVFormat.newFormat('\'')
-110                 .withQuote('"')
-111                 .withCommentMarker('#')
-112                 .withEscape('+')
-113                 .withQuoteMode(QuoteMode.ALL);
-114         final CSVFormat left = right
-115                 .withEscape('!');
-116 
-117         assertNotEquals(right, left);
-118     }
-119 
-120     @Test
-121     public void testEqualsHeader() {
-122         final CSVFormat right = CSVFormat.newFormat('\'')
-123                 .withRecordSeparator(CR)
-124                 .withCommentMarker('#')
-125                 .withEscape('+')
-126                 .withHeader("One", "Two", "Three")
-127                 .withIgnoreEmptyLines()
-128                 .withIgnoreSurroundingSpaces()
-129                 .withQuote('"')
-130                 .withQuoteMode(QuoteMode.ALL);
-131         final CSVFormat left = right
-132                 .withHeader("Three", "Two", "One");
-133 
-134         assertNotEquals(right, left);
-135     }
-136 
-137     @Test
-138     public void testEqualsIgnoreEmptyLines() {
-139         final CSVFormat right = CSVFormat.newFormat('\'')
-140                 .withCommentMarker('#')
-141                 .withEscape('+')
-142                 .withIgnoreEmptyLines()
-143                 .withIgnoreSurroundingSpaces()
-144                 .withQuote('"')
-145                 .withQuoteMode(QuoteMode.ALL);
-146         final CSVFormat left = right
-147                 .withIgnoreEmptyLines(false);
-148 
-149         assertNotEquals(right, left);
-150     }
-151 
-152     @Test
-153     public void testEqualsIgnoreSurroundingSpaces() {
-154         final CSVFormat right = CSVFormat.newFormat('\'')
-155                 .withCommentMarker('#')
-156                 .withEscape('+')
-157                 .withIgnoreSurroundingSpaces()
-158                 .withQuote('"')
-159                 .withQuoteMode(QuoteMode.ALL);
-160         final CSVFormat left = right
-161                 .withIgnoreSurroundingSpaces(false);
-162 
-163         assertNotEquals(right, left);
-164     }
-165 
-166     @Test
-167     public void testEqualsQuoteChar() {
-168         final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"');
-169         final CSVFormat left = right.withQuote('!');
-170 
-171         assertNotEquals(right, left);
-172     }
-173 
-174     @Test
-175     public void testEqualsQuotePolicy() {
-176         final CSVFormat right = CSVFormat.newFormat('\'')
-177                 .withQuote('"')
-178                 .withQuoteMode(QuoteMode.ALL);
-179         final CSVFormat left = right
-180                 .withQuoteMode(QuoteMode.MINIMAL);
-181 
-182         assertNotEquals(right, left);
-183     }
-184 
-185     @Test
-186     public void testEqualsRecordSeparator() {
-187         final CSVFormat right = CSVFormat.newFormat('\'')
-188                 .withRecordSeparator(CR)
-189                 .withCommentMarker('#')
-190                 .withEscape('+')
-191                 .withIgnoreEmptyLines()
-192                 .withIgnoreSurroundingSpaces()
-193                 .withQuote('"')
-194                 .withQuoteMode(QuoteMode.ALL);
-195         final CSVFormat left = right
-196                 .withRecordSeparator(LF);
-197 
-198         assertNotEquals(right, left);
-199     }
-200 
-201     @Test
-202     public void testEqualsNullString() {
-203         final CSVFormat right = CSVFormat.newFormat('\'')
-204                 .withRecordSeparator(CR)
-205                 .withCommentMarker('#')
-206                 .withEscape('+')
-207                 .withIgnoreEmptyLines()
-208                 .withIgnoreSurroundingSpaces()
-209                 .withQuote('"')
-210                 .withQuoteMode(QuoteMode.ALL)
-211                 .withNullString("null");
-212         final CSVFormat left = right
-213                 .withNullString("---");
-214 
-215         assertNotEquals(right, left);
-216     }
-217 
-218     @Test
-219     public void testEqualsSkipHeaderRecord() {
-220         final CSVFormat right = CSVFormat.newFormat('\'')
-221                 .withRecordSeparator(CR)
-222                 .withCommentMarker('#')
-223                 .withEscape('+')
-224                 .withIgnoreEmptyLines()
-225                 .withIgnoreSurroundingSpaces()
-226                 .withQuote('"')
-227                 .withQuoteMode(QuoteMode.ALL)
-228                 .withNullString("null")
-229                 .withSkipHeaderRecord();
-230         final CSVFormat left = right
-231                 .withSkipHeaderRecord(false);
-232 
-233         assertNotEquals(right, left);
-234     }
-235 
-236     @Test(expected = IllegalArgumentException.class)
-237     public void testEscapeSameAsCommentStartThrowsException() {
-238         CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!');
-239     }
-240 
-241     @Test(expected = IllegalArgumentException.class)
-242     public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
-243         // Cannot assume that callers won't use different Character objects
-244         CSVFormat.DEFAULT.withEscape(new Character('!')).withCommentMarker(new Character('!'));
-245     }
-246 
-247     @Test
-248     public void testFormat() {
-249         final CSVFormat format = CSVFormat.DEFAULT;
-250 
-251         assertEquals("", format.format());
-252         assertEquals("a,b,c", format.format("a", "b", "c"));
-253         assertEquals("\"x,y\",z", format.format("x,y", "z"));
-254     }
-255 
-256     @Test
-257     public void testGetHeader() throws Exception {
-258         final String[] header = new String[]{"one", "two", "three"};
-259         final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header);
-260         // getHeader() makes a copy of the header array.
-261         final String[] headerCopy = formatWithHeader.getHeader();
-262         headerCopy[0] = "A";
-263         headerCopy[1] = "B";
-264         headerCopy[2] = "C";
-265         assertFalse(Arrays.equals(formatWithHeader.getHeader(), headerCopy));
-266         assertNotSame(formatWithHeader.getHeader(), headerCopy);
-267     }
-268 
-269     @Test
-270     public void testNullRecordSeparatorCsv106() {
-271         final CSVFormat format = CSVFormat.newFormat(';').withSkipHeaderRecord().withHeader("H1", "H2");
-272         final String formatStr = format.format("A", "B");
-273         assertNotNull(formatStr);
-274         assertFalse(formatStr.endsWith("null"));
-275     }
-276 
-277     @Test(expected = IllegalArgumentException.class)
-278     public void testQuoteCharSameAsCommentStartThrowsException() {
-279         CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!');
-280     }
-281 
-282     @Test(expected = IllegalArgumentException.class)
-283     public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() {
-284         // Cannot assume that callers won't use different Character objects
-285         CSVFormat.DEFAULT.withQuote(new Character('!')).withCommentMarker('!');
-286     }
-287 
-288     @Test(expected = IllegalArgumentException.class)
-289     public void testQuoteCharSameAsDelimiterThrowsException() {
-290         CSVFormat.DEFAULT.withQuote('!').withDelimiter('!');
-291     }
-292 
-293     @Test(expected = IllegalArgumentException.class)
-294     public void testQuotePolicyNoneWithoutEscapeThrowsException() {
-295         CSVFormat.newFormat('!').withQuoteMode(QuoteMode.NONE);
-296     }
-297 
-298     @Test
-299     public void testRFC4180() {
-300         assertEquals(null, RFC4180.getCommentMarker());
-301         assertEquals(',', RFC4180.getDelimiter());
-302         assertEquals(null, RFC4180.getEscapeCharacter());
-303         assertFalse(RFC4180.getIgnoreEmptyLines());
-304         assertEquals(Character.valueOf('"'), RFC4180.getQuoteCharacter());
-305         assertEquals(null, RFC4180.getQuoteMode());
-306         assertEquals("\r\n", RFC4180.getRecordSeparator());
-307     }
-308 
-309     @SuppressWarnings("boxing") // no need to worry about boxing here
-310     @Test
-311     public void testSerialization() throws Exception {
-312         final ByteArrayOutputStream out = new ByteArrayOutputStream();
-313 
-314         final ObjectOutputStream oos = new ObjectOutputStream(out);
-315         oos.writeObject(CSVFormat.DEFAULT);
-316         oos.flush();
-317         oos.close();
-318 
-319         final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
-320         final CSVFormat format = (CSVFormat) in.readObject();
-321 
-322         assertNotNull(format);
-323         assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
-324         assertEquals("encapsulator", CSVFormat.DEFAULT.getQuoteCharacter(), format.getQuoteCharacter());
-325         assertEquals("comment start", CSVFormat.DEFAULT.getCommentMarker(), format.getCommentMarker());
-326         assertEquals("record separator", CSVFormat.DEFAULT.getRecordSeparator(), format.getRecordSeparator());
-327         assertEquals("escape", CSVFormat.DEFAULT.getEscapeCharacter(), format.getEscapeCharacter());
-328         assertEquals("trim", CSVFormat.DEFAULT.getIgnoreSurroundingSpaces(), format.getIgnoreSurroundingSpaces());
-329         assertEquals("empty lines", CSVFormat.DEFAULT.getIgnoreEmptyLines(), format.getIgnoreEmptyLines());
-330     }
-331 
-332     @Test
-333     public void testWithCommentStart() throws Exception {
-334         final CSVFormat formatWithCommentStart = CSVFormat.DEFAULT.withCommentMarker('#');
-335         assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentMarker());
-336     }
-337 
-338     @Test(expected = IllegalArgumentException.class)
-339     public void testWithCommentStartCRThrowsException() {
-340         CSVFormat.DEFAULT.withCommentMarker(CR);
-341     }
-342 
-343     @Test
-344     public void testWithDelimiter() throws Exception {
-345         final CSVFormat formatWithDelimiter = CSVFormat.DEFAULT.withDelimiter('!');
-346         assertEquals('!', formatWithDelimiter.getDelimiter());
-347     }
-348 
-349     @Test(expected = IllegalArgumentException.class)
-350     public void testWithDelimiterLFThrowsException() {
-351         CSVFormat.DEFAULT.withDelimiter(LF);
-352     }
-353 
-354     @Test
-355     public void testWithEscape() throws Exception {
-356         final CSVFormat formatWithEscape = CSVFormat.DEFAULT.withEscape('&');
-357         assertEquals(Character.valueOf('&'), formatWithEscape.getEscapeCharacter());
-358     }
-359 
-360     @Test(expected = IllegalArgumentException.class)
-361     public void testWithEscapeCRThrowsExceptions() {
-362         CSVFormat.DEFAULT.withEscape(CR);
-363     }
-364 
-365     @Test
-366     public void testWithHeader() throws Exception {
-367         final String[] header = new String[]{"one", "two", "three"};
-368         // withHeader() makes a copy of the header array.
-369         final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header);
-370         assertArrayEquals(header, formatWithHeader.getHeader());
-371         assertNotSame(header, formatWithHeader.getHeader());
-372     }
-373 
-374     @Test
-375     public void testWithHeaderEnum() throws Exception {
-376         final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(Header.class);
-377         assertArrayEquals(new String[]{ "Name", "Email", "Phone" }, formatWithHeader.getHeader());
-378     }
-379 
-380     @Test
-381     public void testWithEmptyEnum() throws Exception {
-382         final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(EmptyEnum.class);
-383         Assert.assertTrue(formatWithHeader.getHeader().length == 0);
-384     }
-385 
-386     @Test
-387     public void testWithIgnoreEmptyLines() throws Exception {
-388         assertFalse(CSVFormat.DEFAULT.withIgnoreEmptyLines(false).getIgnoreEmptyLines());
-389         assertTrue(CSVFormat.DEFAULT.withIgnoreEmptyLines().getIgnoreEmptyLines());
-390     }
-391 
-392     @Test
-393     public void testWithIgnoreSurround() throws Exception {
-394         assertFalse(CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(false).getIgnoreSurroundingSpaces());
-395         assertTrue(CSVFormat.DEFAULT.withIgnoreSurroundingSpaces().getIgnoreSurroundingSpaces());
-396     }
-397 
-398     @Test
-399     public void testWithNullString() throws Exception {
-400         final CSVFormat formatWithNullString = CSVFormat.DEFAULT.withNullString("null");
-401         assertEquals("null", formatWithNullString.getNullString());
-402     }
-403 
-404     @Test
-405     public void testWithQuoteChar() throws Exception {
-406         final CSVFormat formatWithQuoteChar = CSVFormat.DEFAULT.withQuote('"');
-407         assertEquals(Character.valueOf('"'), formatWithQuoteChar.getQuoteCharacter());
-408     }
-409 
-410     @Test(expected = IllegalArgumentException.class)
-411     public void testWithQuoteLFThrowsException() {
-412         CSVFormat.DEFAULT.withQuote(LF);
-413     }
-414 
-415     @Test
-416     public void testWithQuotePolicy() throws Exception {
-417         final CSVFormat formatWithQuotePolicy = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL);
-418         assertEquals(QuoteMode.ALL, formatWithQuotePolicy.getQuoteMode());
-419     }
-420 
-421     @Test
-422     public void testWithRecordSeparatorCR() throws Exception {
-423         final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(CR);
-424         assertEquals(String.valueOf(CR), formatWithRecordSeparator.getRecordSeparator());
-425     }
-426 
-427     @Test
-428     public void testWithRecordSeparatorLF() throws Exception {
-429         final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(LF);
-430         assertEquals(String.valueOf(LF), formatWithRecordSeparator.getRecordSeparator());
-431     }
-432 
-433     @Test
-434     public void testWithRecordSeparatorCRLF() throws Exception {
-435         final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(CRLF);
-436         assertEquals(CRLF, formatWithRecordSeparator.getRecordSeparator());
-437     }
-438 
-439     @Test
-440     public void testWithFirstRecordAsHeader() throws Exception {
-441         final CSVFormat formatWithFirstRecordAsHeader = CSVFormat.DEFAULT.withFirstRecordAsHeader();
-442         assertTrue(formatWithFirstRecordAsHeader.getSkipHeaderRecord());
-443         assertTrue(formatWithFirstRecordAsHeader.getHeader().length == 0);
-444     }
-445 
-446     public enum Header {
-447         Name, Email, Phone
-448     }
-449 
-450     public enum EmptyEnum {
-451     }
-452 }
-
-
- - + + + +CSVFormatTest xref + + + +
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one or more
+3    * contributor license agreements.  See the NOTICE file distributed with
+4    * this work for additional information regarding copyright ownership.
+5    * The ASF licenses this file to You under the Apache License, Version 2.0
+6    * (the "License"); you may not use this file except in compliance with
+7    * the License.  You may obtain a copy of the License at
+8    *
+9    *      http://www.apache.org/licenses/LICENSE-2.0
+10   *
+11   * Unless required by applicable law or agreed to in writing, software
+12   * distributed under the License is distributed on an "AS IS" BASIS,
+13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+14   * See the License for the specific language governing permissions and
+15   * limitations under the License.
+16   */
+17  
+18  package org.apache.commons.csv;
+19  
+20  import static org.apache.commons.csv.CSVFormat.RFC4180;
+21  import static org.apache.commons.csv.Constants.CR;
+22  import static org.apache.commons.csv.Constants.CRLF;
+23  import static org.apache.commons.csv.Constants.LF;
+24  import static org.junit.Assert.assertArrayEquals;
+25  import static org.junit.Assert.assertEquals;
+26  import static org.junit.Assert.assertFalse;
+27  import static org.junit.Assert.assertNotNull;
+28  import static org.junit.Assert.assertNotSame;
+29  import static org.junit.Assert.assertTrue;
+30  
+31  import java.io.ByteArrayInputStream;
+32  import java.io.ByteArrayOutputStream;
+33  import java.io.ObjectInputStream;
+34  import java.io.ObjectOutputStream;
+35  import java.util.Arrays;
+36  
+37  import org.junit.Assert;
+38  import org.junit.Test;
+39  
+40  /**
+41   *
+42   *
+43   * @version $Id: CSVFormatTest.java 1742178 2016-05-03 18:54:13Z britter $
+44   */
+45  public class CSVFormatTest {
+46  
+47      private static void assertNotEquals(final Object right, final Object left) {
+48          assertFalse(right.equals(left));
+49          assertFalse(left.equals(right));
+50      }
+51  
+52      private static CSVFormat copy(final CSVFormat format) {
+53          return format.withDelimiter(format.getDelimiter());
+54      }
+55  
+56      @Test(expected = IllegalArgumentException.class)
+57      public void testDelimiterSameAsCommentStartThrowsException() {
+58          CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!');
+59      }
+60  
+61      @Test(expected = IllegalArgumentException.class)
+62      public void testDelimiterSameAsEscapeThrowsException() {
+63          CSVFormat.DEFAULT.withDelimiter('!').withEscape('!');
+64      }
+65  
+66      @Test(expected = IllegalArgumentException.class)
+67      public void testDuplicateHeaderElements() {
+68          CSVFormat.DEFAULT.withHeader("A", "A");
+69      }
+70  
+71      @Test
+72      public void testEquals() {
+73          final CSVFormat right = CSVFormat.DEFAULT;
+74          final CSVFormat left = copy(right);
+75  
+76          assertFalse(right.equals(null));
+77          assertFalse(right.equals("A String Instance"));
+78  
+79          assertEquals(right, right);
+80          assertEquals(right, left);
+81          assertEquals(left, right);
+82  
+83          assertEquals(right.hashCode(), right.hashCode());
+84          assertEquals(right.hashCode(), left.hashCode());
+85      }
+86  
+87      @Test
+88      public void testEqualsCommentStart() {
+89          final CSVFormat right = CSVFormat.newFormat('\'')
+90                  .withQuote('"')
+91                  .withCommentMarker('#')
+92                  .withQuoteMode(QuoteMode.ALL);
+93          final CSVFormat left = right
+94                  .withCommentMarker('!');
+95  
+96          assertNotEquals(right, left);
+97      }
+98  
+99      @Test
+100     public void testEqualsDelimiter() {
+101         final CSVFormat right = CSVFormat.newFormat('!');
+102         final CSVFormat left = CSVFormat.newFormat('?');
+103 
+104         assertNotEquals(right, left);
+105     }
+106 
+107     @Test
+108     public void testEqualsEscape() {
+109         final CSVFormat right = CSVFormat.newFormat('\'')
+110                 .withQuote('"')
+111                 .withCommentMarker('#')
+112                 .withEscape('+')
+113                 .withQuoteMode(QuoteMode.ALL);
+114         final CSVFormat left = right
+115                 .withEscape('!');
+116 
+117         assertNotEquals(right, left);
+118     }
+119 
+120     @Test
+121     public void testEqualsHeader() {
+122         final CSVFormat right = CSVFormat.newFormat('\'')
+123                 .withRecordSeparator(CR)
+124                 .withCommentMarker('#')
+125                 .withEscape('+')
+126                 .withHeader("One", "Two", "Three")
+127                 .withIgnoreEmptyLines()
+128                 .withIgnoreSurroundingSpaces()
+129                 .withQuote('"')
+130                 .withQuoteMode(QuoteMode.ALL);
+131         final CSVFormat left = right
+132                 .withHeader("Three", "Two", "One");
+133 
+134         assertNotEquals(right, left);
+135     }
+136 
+137     @Test
+138     public void testEqualsIgnoreEmptyLines() {
+139         final CSVFormat right = CSVFormat.newFormat('\'')
+140                 .withCommentMarker('#')
+141                 .withEscape('+')
+142                 .withIgnoreEmptyLines()
+143                 .withIgnoreSurroundingSpaces()
+144                 .withQuote('"')
+145                 .withQuoteMode(QuoteMode.ALL);
+146         final CSVFormat left = right
+147                 .withIgnoreEmptyLines(false);
+148 
+149         assertNotEquals(right, left);
+150     }
+151 
+152     @Test
+153     public void testEqualsIgnoreSurroundingSpaces() {
+154         final CSVFormat right = CSVFormat.newFormat('\'')
+155                 .withCommentMarker('#')
+156                 .withEscape('+')
+157                 .withIgnoreSurroundingSpaces()
+158                 .withQuote('"')
+159                 .withQuoteMode(QuoteMode.ALL);
+160         final CSVFormat left = right
+161                 .withIgnoreSurroundingSpaces(false);
+162 
+163         assertNotEquals(right, left);
+164     }
+165 
+166     @Test
+167     public void testEqualsQuoteChar() {
+168         final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"');
+169         final CSVFormat left = right.withQuote('!');
+170 
+171         assertNotEquals(right, left);
+172     }
+173 
+174     @Test
+175     public void testEqualsQuotePolicy() {
+176         final CSVFormat right = CSVFormat.newFormat('\'')
+177                 .withQuote('"')
+178                 .withQuoteMode(QuoteMode.ALL);
+179         final CSVFormat left = right
+180                 .withQuoteMode(QuoteMode.MINIMAL);
+181 
+182         assertNotEquals(right, left);
+183     }
+184 
+185     @Test
+186     public void testEqualsRecordSeparator() {
+187         final CSVFormat right = CSVFormat.newFormat('\'')
+188                 .withRecordSeparator(CR)
+189                 .withCommentMarker('#')
+190                 .withEscape('+')
+191                 .withIgnoreEmptyLines()
+192                 .withIgnoreSurroundingSpaces()
+193                 .withQuote('"')
+194                 .withQuoteMode(QuoteMode.ALL);
+195         final CSVFormat left = right
+196                 .withRecordSeparator(LF);
+197 
+198         assertNotEquals(right, left);
+199     }
+200 
+201     @Test
+202     public void testEqualsNullString() {
+203         final CSVFormat right = CSVFormat.newFormat('\'')
+204                 .withRecordSeparator(CR)
+205                 .withCommentMarker('#')
+206                 .withEscape('+')
+207                 .withIgnoreEmptyLines()
+208                 .withIgnoreSurroundingSpaces()
+209                 .withQuote('"')
+210                 .withQuoteMode(QuoteMode.ALL)
+211                 .withNullString("null");
+212         final CSVFormat left = right
+213                 .withNullString("---");
+214 
+215         assertNotEquals(right, left);
+216     }
+217 
+218     @Test
+219     public void testEqualsSkipHeaderRecord() {
+220         final CSVFormat right = CSVFormat.newFormat('\'')
+221                 .withRecordSeparator(CR)
+222                 .withCommentMarker('#')
+223                 .withEscape('+')
+224                 .withIgnoreEmptyLines()
+225                 .withIgnoreSurroundingSpaces()
+226                 .withQuote('"')
+227                 .withQuoteMode(QuoteMode.ALL)
+228                 .withNullString("null")
+229                 .withSkipHeaderRecord();
+230         final CSVFormat left = right
+231                 .withSkipHeaderRecord(false);
+232 
+233         assertNotEquals(right, left);
+234     }
+235 
+236     @Test(expected = IllegalArgumentException.class)
+237     public void testEscapeSameAsCommentStartThrowsException() {
+238         CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!');
+239     }
+240 
+241     @Test(expected = IllegalArgumentException.class)
+242     public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
+243         // Cannot assume that callers won't use different Character objects
+244         CSVFormat.DEFAULT.withEscape(new Character('!')).withCommentMarker(new Character('!'));
+245     }
+246 
+247     @Test
+248     public void testFormat() {
+249         final CSVFormat format = CSVFormat.DEFAULT;
+250 
+251         assertEquals("", format.format());
+252         assertEquals("a,b,c", format.format("a", "b", "c"));
+253         assertEquals("\"x,y\",z", format.format("x,y", "z"));
+254     }
+255 
+256     @Test
+257     public void testGetHeader() throws Exception {
+258         final String[] header = new String[]{"one", "two", "three"};
+259         final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header);
+260         // getHeader() makes a copy of the header array.
+261         final String[] headerCopy = formatWithHeader.getHeader();
+262         headerCopy[0] = "A";
+263         headerCopy[1] = "B";
+264         headerCopy[2] = "C";
+265         assertFalse(Arrays.equals(formatWithHeader.getHeader(), headerCopy));
+266         assertNotSame(formatWithHeader.getHeader(), headerCopy);
+267     }
+268 
+269     @Test
+270     public void testNullRecordSeparatorCsv106() {
+271         final CSVFormat format = CSVFormat.newFormat(';').withSkipHeaderRecord().withHeader("H1", "H2");
+272         final String formatStr = format.format("A", "B");
+273         assertNotNull(formatStr);
+274         assertFalse(formatStr.endsWith("null"));
+275     }
+276 
+277     @Test(expected = IllegalArgumentException.class)
+278     public void testQuoteCharSameAsCommentStartThrowsException() {
+279         CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!');
+280     }
+281 
+282     @Test(expected = IllegalArgumentException.class)
+283     public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() {
+284         // Cannot assume that callers won't use different Character objects
+285         CSVFormat.DEFAULT.withQuote(new Character('!')).withCommentMarker('!');
+286     }
+287 

[... 172 lines stripped ...]