This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new da4d2e5  Add and use CSVFormat.Builder, deprecated CSVFormat#with 
methods, based on #73.
da4d2e5 is described below

commit da4d2e5c2d38e7384a0dbff4739027d034384ab6
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Jul 5 08:59:59 2021 -0400

    Add and use CSVFormat.Builder, deprecated CSVFormat#with methods, based
    on #73.
    
    Better test method names and use @SuppressWarnings("deprecation").
---
 .../java/org/apache/commons/csv/CSVFormatTest.java | 495 +++++++++++----------
 1 file changed, 260 insertions(+), 235 deletions(-)

diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java 
b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index 3e5d734..400cc07 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -78,8 +78,9 @@ public class CSVFormatTest {
         }
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testDelimiterSameAsCommentStartThrowsException0() {
+    public void testDelimiterSameAsCommentStartThrowsException_Deprecated() {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!'));
     }
 
@@ -88,8 +89,9 @@ public class CSVFormatTest {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.builder().setDelimiter('!').setCommentMarker('!').build());
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testDelimiterSameAsEscapeThrowsException0() {
+    public void testDelimiterSameAsEscapeThrowsException_Deprecated() {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withDelimiter('!').withEscape('!'));
     }
 
@@ -99,11 +101,8 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testDuplicateHeaderElements0() {
-        final String[] header = { "A", "A" };
-        final CSVFormat format = CSVFormat.DEFAULT.withHeader(header);
-        assertEquals(2, format.getHeader().length);
-        assertArrayEquals(header, format.getHeader());
+    public void testDelimiterSameAsRecordSeparatorThrowsException() {
+        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.newFormat(CR));
     }
 
     @Test
@@ -114,11 +113,13 @@ public class CSVFormatTest {
         assertArrayEquals(header, format.getHeader());
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testDuplicateHeaderElementsFalse0() {
-        assertThrows(
-                IllegalArgumentException.class,
-                () -> 
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(false).withHeader("A", "A"));
+    public void testDuplicateHeaderElements_Deprecated() {
+        final String[] header = { "A", "A" };
+        final CSVFormat format = CSVFormat.DEFAULT.withHeader(header);
+        assertEquals(2, format.getHeader().length);
+        assertArrayEquals(header, format.getHeader());
     }
 
     @Test
@@ -128,14 +129,23 @@ public class CSVFormatTest {
                 () -> 
CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setHeader("A", 
"A").build());
     }
 
-    public void testDuplicateHeaderElementsTrue0() {
-        CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(true).withHeader("A", 
"A");
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testDuplicateHeaderElementsFalse_Deprecated() {
+        assertThrows(
+                IllegalArgumentException.class,
+                () -> 
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(false).withHeader("A", "A"));
     }
 
     public void testDuplicateHeaderElementsTrue() {
         
CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("A", 
"A").build();
     }
 
+    @SuppressWarnings("deprecation")
+    public void testDuplicateHeaderElementsTrue_Deprecated() {
+        CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(true).withHeader("A", 
"A");
+    }
+
     @Test
     public void testEquals() {
         final CSVFormat right = CSVFormat.DEFAULT;
@@ -153,18 +163,6 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testEqualsCommentStart0() {
-        final CSVFormat right = CSVFormat.newFormat('\'')
-                .withQuote('"')
-                .withCommentMarker('#')
-                .withQuoteMode(QuoteMode.ALL);
-        final CSVFormat left = right
-                .withCommentMarker('!');
-
-        assertNotEquals(right, left);
-    }
-
-    @Test
     public void testEqualsCommentStart() {
         final CSVFormat right = CSVFormat.newFormat('\'').builder()
                 .setQuote('"')
@@ -178,23 +176,23 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsDelimiter() {
-        final CSVFormat right = CSVFormat.newFormat('!');
-        final CSVFormat left = CSVFormat.newFormat('?');
-
-        assertNotEquals(right, left);
-    }
-
-    @Test
-    public void testEqualsEscape0() {
+    public void testEqualsCommentStart_Deprecated() {
         final CSVFormat right = CSVFormat.newFormat('\'')
                 .withQuote('"')
                 .withCommentMarker('#')
-                .withEscape('+')
                 .withQuoteMode(QuoteMode.ALL);
         final CSVFormat left = right
-                .withEscape('!');
+                .withCommentMarker('!');
+
+        assertNotEquals(right, left);
+    }
+
+    @Test
+    public void testEqualsDelimiter() {
+        final CSVFormat right = CSVFormat.newFormat('!');
+        final CSVFormat left = CSVFormat.newFormat('?');
 
         assertNotEquals(right, left);
     }
@@ -214,6 +212,20 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testEqualsEscape_Deprecated() {
+        final CSVFormat right = CSVFormat.newFormat('\'')
+                .withQuote('"')
+                .withCommentMarker('#')
+                .withEscape('+')
+                .withQuoteMode(QuoteMode.ALL);
+        final CSVFormat left = right
+                .withEscape('!');
+
+        assertNotEquals(right, left);
+    }
+
     @Test
     public void testEqualsHash() throws Exception {
         final Method[] methods = CSVFormat.class.getDeclaredMethods();
@@ -263,23 +275,6 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testEqualsHeader0() {
-        final CSVFormat right = CSVFormat.newFormat('\'')
-                .withRecordSeparator(CR)
-                .withCommentMarker('#')
-                .withEscape('+')
-                .withHeader("One", "Two", "Three")
-                .withIgnoreEmptyLines()
-                .withIgnoreSurroundingSpaces()
-                .withQuote('"')
-                .withQuoteMode(QuoteMode.ALL);
-        final CSVFormat left = right
-                .withHeader("Three", "Two", "One");
-
-        assertNotEquals(right, left);
-    }
-
-    @Test
     public void testEqualsHeader() {
         final CSVFormat right = CSVFormat.newFormat('\'').builder()
                 .setRecordSeparator(CR)
@@ -298,17 +293,20 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsIgnoreEmptyLines0() {
+    public void testEqualsHeader_Deprecated() {
         final CSVFormat right = CSVFormat.newFormat('\'')
+                .withRecordSeparator(CR)
                 .withCommentMarker('#')
                 .withEscape('+')
+                .withHeader("One", "Two", "Three")
                 .withIgnoreEmptyLines()
                 .withIgnoreSurroundingSpaces()
                 .withQuote('"')
                 .withQuoteMode(QuoteMode.ALL);
         final CSVFormat left = right
-                .withIgnoreEmptyLines(false);
+                .withHeader("Three", "Two", "One");
 
         assertNotEquals(right, left);
     }
@@ -330,16 +328,18 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsIgnoreSurroundingSpaces0() {
+    public void testEqualsIgnoreEmptyLines_Deprecated() {
         final CSVFormat right = CSVFormat.newFormat('\'')
                 .withCommentMarker('#')
                 .withEscape('+')
+                .withIgnoreEmptyLines()
                 .withIgnoreSurroundingSpaces()
                 .withQuote('"')
                 .withQuoteMode(QuoteMode.ALL);
         final CSVFormat left = right
-                .withIgnoreSurroundingSpaces(false);
+                .withIgnoreEmptyLines(false);
 
         assertNotEquals(right, left);
     }
@@ -360,12 +360,19 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsLeftNoQuoteRightQuote0() {
-        final CSVFormat left = CSVFormat.newFormat(',').withQuote(null);
-        final CSVFormat right = left.withQuote('#');
+    public void testEqualsIgnoreSurroundingSpaces_Deprecated() {
+        final CSVFormat right = CSVFormat.newFormat('\'')
+                .withCommentMarker('#')
+                .withEscape('+')
+                .withIgnoreSurroundingSpaces()
+                .withQuote('"')
+                .withQuoteMode(QuoteMode.ALL);
+        final CSVFormat left = right
+                .withIgnoreSurroundingSpaces(false);
 
-        assertNotEquals(left, right);
+        assertNotEquals(right, left);
     }
 
     @Test
@@ -376,12 +383,13 @@ public class CSVFormatTest {
         assertNotEquals(left, right);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsNoQuotes0() {
+    public void testEqualsLeftNoQuoteRightQuote_Deprecated() {
         final CSVFormat left = CSVFormat.newFormat(',').withQuote(null);
-        final CSVFormat right = left.withQuote(null);
+        final CSVFormat right = left.withQuote('#');
 
-        assertEquals(left, right);
+        assertNotEquals(left, right);
     }
 
     @Test
@@ -392,21 +400,13 @@ public class CSVFormatTest {
         assertEquals(left, right);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsNullString0() {
-        final CSVFormat right = CSVFormat.newFormat('\'')
-                .withRecordSeparator(CR)
-                .withCommentMarker('#')
-                .withEscape('+')
-                .withIgnoreEmptyLines()
-                .withIgnoreSurroundingSpaces()
-                .withQuote('"')
-                .withQuoteMode(QuoteMode.ALL)
-                .withNullString("null");
-        final CSVFormat left = right
-                .withNullString("---");
+    public void testEqualsNoQuotes_Deprecated() {
+        final CSVFormat left = CSVFormat.newFormat(',').withQuote(null);
+        final CSVFormat right = left.withQuote(null);
 
-        assertNotEquals(right, left);
+        assertEquals(left, right);
     }
 
     @Test
@@ -428,6 +428,24 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testEqualsNullString_Deprecated() {
+        final CSVFormat right = CSVFormat.newFormat('\'')
+                .withRecordSeparator(CR)
+                .withCommentMarker('#')
+                .withEscape('+')
+                .withIgnoreEmptyLines()
+                .withIgnoreSurroundingSpaces()
+                .withQuote('"')
+                .withQuoteMode(QuoteMode.ALL)
+                .withNullString("null");
+        final CSVFormat left = right
+                .withNullString("---");
+
+        assertNotEquals(right, left);
+    }
+
     @Test
     public void testEqualsOne() {
 
@@ -558,14 +576,6 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testEqualsQuoteChar0() {
-        final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"');
-        final CSVFormat left = right.withQuote('!');
-
-        assertNotEquals(right, left);
-    }
-
-    @Test
     public void testEqualsQuoteChar() {
         final CSVFormat right = 
CSVFormat.newFormat('\'').builder().setQuote('"').build();
         final CSVFormat left = right.builder().setQuote('!').build();
@@ -573,13 +583,11 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsQuotePolicy0() {
-        final CSVFormat right = CSVFormat.newFormat('\'')
-                .withQuote('"')
-                .withQuoteMode(QuoteMode.ALL);
-        final CSVFormat left = right
-                .withQuoteMode(QuoteMode.MINIMAL);
+    public void testEqualsQuoteChar_Deprecated() {
+        final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"');
+        final CSVFormat left = right.withQuote('!');
 
         assertNotEquals(right, left);
     }
@@ -597,18 +605,14 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsRecordSeparator0() {
+    public void testEqualsQuotePolicy_Deprecated() {
         final CSVFormat right = CSVFormat.newFormat('\'')
-                .withRecordSeparator(CR)
-                .withCommentMarker('#')
-                .withEscape('+')
-                .withIgnoreEmptyLines()
-                .withIgnoreSurroundingSpaces()
                 .withQuote('"')
                 .withQuoteMode(QuoteMode.ALL);
         final CSVFormat left = right
-                .withRecordSeparator(LF);
+                .withQuoteMode(QuoteMode.MINIMAL);
 
         assertNotEquals(right, left);
     }
@@ -631,8 +635,9 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEqualsSkipHeaderRecord0() {
+    public void testEqualsRecordSeparator_Deprecated() {
         final CSVFormat right = CSVFormat.newFormat('\'')
                 .withRecordSeparator(CR)
                 .withCommentMarker('#')
@@ -640,11 +645,9 @@ public class CSVFormatTest {
                 .withIgnoreEmptyLines()
                 .withIgnoreSurroundingSpaces()
                 .withQuote('"')
-                .withQuoteMode(QuoteMode.ALL)
-                .withNullString("null")
-                .withSkipHeaderRecord();
+                .withQuoteMode(QuoteMode.ALL);
         final CSVFormat left = right
-                .withSkipHeaderRecord(false);
+                .withRecordSeparator(LF);
 
         assertNotEquals(right, left);
     }
@@ -668,6 +671,25 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testEqualsSkipHeaderRecord_Deprecated() {
+        final CSVFormat right = CSVFormat.newFormat('\'')
+                .withRecordSeparator(CR)
+                .withCommentMarker('#')
+                .withEscape('+')
+                .withIgnoreEmptyLines()
+                .withIgnoreSurroundingSpaces()
+                .withQuote('"')
+                .withQuoteMode(QuoteMode.ALL)
+                .withNullString("null")
+                .withSkipHeaderRecord();
+        final CSVFormat left = right
+                .withSkipHeaderRecord(false);
+
+        assertNotEquals(right, left);
+    }
+
     @Test
     public void testEqualsWithNull() {
 
@@ -732,29 +754,31 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testEscapeSameAsCommentStartThrowsException0() {
-        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!'));
+    public void testEscapeSameAsCommentStartThrowsException() {
+        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.builder().setEscape('!').setCommentMarker('!').build());
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEscapeSameAsCommentStartThrowsException() {
-        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.builder().setEscape('!').setCommentMarker('!').build());
+    public void testEscapeSameAsCommentStartThrowsException_Deprecated() {
+        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!'));
     }
 
     @Test
-    public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType0() {
+    public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
         // Cannot assume that callers won't use different Character objects
         assertThrows(
                 IllegalArgumentException.class,
-                () -> 
CSVFormat.DEFAULT.withEscape(Character.valueOf('!')).withCommentMarker(Character.valueOf('!')));
+                () -> 
CSVFormat.DEFAULT.builder().setEscape(Character.valueOf('!')).setCommentMarker(Character.valueOf('!')).build());
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
+    public void 
testEscapeSameAsCommentStartThrowsExceptionForWrapperType_Deprecated() {
         // Cannot assume that callers won't use different Character objects
         assertThrows(
                 IllegalArgumentException.class,
-                () -> 
CSVFormat.DEFAULT.builder().setEscape(Character.valueOf('!')).setCommentMarker(Character.valueOf('!')).build());
+                () -> 
CSVFormat.DEFAULT.withEscape(Character.valueOf('!')).withCommentMarker(Character.valueOf('!')));
     }
 
     @Test
@@ -776,6 +800,16 @@ public class CSVFormatTest {
     }
 
     @Test
+    public void testFormatToString() {
+        final CSVFormat format = 
CSVFormat.RFC4180.withEscape('?').withDelimiter(',')
+                
.withQuoteMode(QuoteMode.MINIMAL).withRecordSeparator(CRLF).withQuote('"')
+                .withNullString("").withIgnoreHeaderCase(true)
+                .withHeaderComments("This is 
HeaderComments").withHeader("col1","col2","col3");
+        assertEquals("Delimiter=<,> Escape=<?> QuoteChar=<\"> 
QuoteMode=<MINIMAL> NullString=<> RecordSeparator=<" +CRLF+
+                "> IgnoreHeaderCase:ignored SkipHeaderRecord:false 
HeaderComments:[This is HeaderComments] Header:[col1, col2, col3]", 
format.toString());
+    }
+
+    @Test
     public void testGetHeader() {
         final String[] header = {"one", "two", "three"};
         final CSVFormat formatWithHeader = 
CSVFormat.DEFAULT.withHeader(header);
@@ -807,13 +841,14 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testJiraCsv236_0() {
-        
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames().withHeader("CC","VV","VV");
+    public void testJiraCsv236() {
+        
CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("CC","VV","VV").build();
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testJiraCsv236() {
-        
CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("CC","VV","VV").build();
+    public void testJiraCsv236__Deprecated() {
+        
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames().withHeader("CC","VV","VV");
     }
 
     @Test
@@ -878,24 +913,65 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testNullRecordSeparatorCsv106_0() {
-        final CSVFormat format = 
CSVFormat.newFormat(';').withSkipHeaderRecord().withHeader("H1", "H2");
+    public void testNullRecordSeparatorCsv106() {
+        final CSVFormat format = 
CSVFormat.newFormat(';').builder().setSkipHeaderRecord(true).setHeader("H1", 
"H2").build();
         final String formatStr = format.format("A", "B");
         assertNotNull(formatStr);
         assertFalse(formatStr.endsWith("null"));
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testNullRecordSeparatorCsv106() {
-        final CSVFormat format = 
CSVFormat.newFormat(';').builder().setSkipHeaderRecord(true).setHeader("H1", 
"H2").build();
+    public void testNullRecordSeparatorCsv106__Deprecated() {
+        final CSVFormat format = 
CSVFormat.newFormat(';').withSkipHeaderRecord().withHeader("H1", "H2");
         final String formatStr = format.format("A", "B");
         assertNotNull(formatStr);
         assertFalse(formatStr.endsWith("null"));
     }
 
     @Test
-    public void testQuoteCharSameAsCommentStartThrowsException0() {
-        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!'));
+    public void testPrintWithEscapesEndWithCRLF() throws IOException {
+        final Reader in = new StringReader("x,y,x\r\na,?b,c\r\n");
+        final Appendable out = new StringBuilder();
+        final CSVFormat format = 
CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF);
+        format.print(in,out,true);
+        assertEquals("x?,y?,x?r?na?,??b?,c?r?n", out.toString());
+    }
+
+    @Test
+    public void testPrintWithEscapesEndWithoutCRLF() throws IOException {
+        final Reader in = new StringReader("x,y,x");
+        final Appendable out = new StringBuilder();
+        final CSVFormat format = 
CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF);
+        format.print(in,out,true);
+        assertEquals("x?,y?,x", out.toString());
+    }
+
+    @Test
+    public void testPrintWithoutQuotes() throws IOException {
+        final Reader in = new StringReader("");
+        final Appendable out = new StringBuilder();
+        final CSVFormat format = 
CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
+        format.print(in, out, true);
+        assertEquals("\"\"", out.toString());
+    }
+
+    @Test
+    public void testPrintWithQuoteModeIsNONE() throws IOException {
+        final Reader in = new StringReader("a,b,c");
+        final Appendable out = new StringBuilder();
+        final CSVFormat format = 
CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE);
+        format.print(in, out, true);
+        assertEquals("a?,b?,c", out.toString());
+    }
+
+    @Test
+    public void testPrintWithQuotes() throws IOException {
+        final Reader in = new StringReader("\"a,b,c\r\nx,y,z");
+        final Appendable out = new StringBuilder();
+        final CSVFormat format = 
CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
+        format.print(in, out, true);
+        assertEquals("\"\"\"\"a,b,c\r\nx,y,z\"", out.toString());
     }
 
     @Test
@@ -903,16 +979,23 @@ public class CSVFormatTest {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.builder().setQuote('!').setCommentMarker('!').build());
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void 
testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType0() {
+    public void testQuoteCharSameAsCommentStartThrowsException_Deprecated() {
+        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!'));
+    }
+
+    @Test
+    public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() 
{
         // Cannot assume that callers won't use different Character objects
         assertThrows(
                 IllegalArgumentException.class,
                 () -> 
CSVFormat.DEFAULT.builder().setQuote(Character.valueOf('!')).setCommentMarker('!').build());
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() 
{
+    public void 
testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType_Deprecated() {
         // Cannot assume that callers won't use different Character objects
         assertThrows(
                 IllegalArgumentException.class,
@@ -920,18 +1003,14 @@ public class CSVFormatTest {
     }
 
     @Test
-    public void testQuoteCharSameAsDelimiterThrowsException0() {
-        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withQuote('!').withDelimiter('!'));
-    }
-
-    @Test
     public void testQuoteCharSameAsDelimiterThrowsException() {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.builder().setQuote('!').setDelimiter('!').build());
     }
 
+    @SuppressWarnings("deprecation")
     @Test
-    public void testQuotePolicyNoneWithoutEscapeThrowsException0() {
-        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.newFormat('!').withQuoteMode(QuoteMode.NONE));
+    public void testQuoteCharSameAsDelimiterThrowsException_Deprecated() {
+        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withQuote('!').withDelimiter('!'));
     }
 
     @Test
@@ -939,6 +1018,12 @@ public class CSVFormatTest {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.newFormat('!').builder().setQuoteMode(QuoteMode.NONE).build());
     }
 
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testQuotePolicyNoneWithoutEscapeThrowsException_Deprecated() {
+        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.newFormat('!').withQuoteMode(QuoteMode.NONE));
+    }
+
     @Test
     public void testRFC4180() {
         assertEquals(null, RFC4180.getCommentMarker());
@@ -1145,44 +1230,76 @@ public class CSVFormatTest {
     }
 
     @Test
+    public void testTrim() throws IOException {
+        final CSVFormat formatWithTrim = 
CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF);
+
+        CharSequence in = "a,b,c";
+        final StringBuilder out = new StringBuilder();
+        formatWithTrim.print(in, out, true);
+        assertEquals("a,b,c", out.toString());
+
+        in = new StringBuilder(" x,y,z");
+        out.setLength(0);
+        formatWithTrim.print(in, out, true);
+        assertEquals("x,y,z", out.toString());
+
+        in = new StringBuilder("");
+        out.setLength(0);
+        formatWithTrim.print(in, out, true);
+        assertEquals("", out.toString());
+
+        in = new StringBuilder("header\r\n");
+        out.setLength(0);
+        formatWithTrim.print(in, out, true);
+        assertEquals("header", out.toString());
+    }
+
+    @Test
     public void testWithCommentStart() {
         final CSVFormat formatWithCommentStart = 
CSVFormat.DEFAULT.withCommentMarker('#');
         assertEquals( Character.valueOf('#'), 
formatWithCommentStart.getCommentMarker());
     }
 
+
     @Test
     public void testWithCommentStartCRThrowsException() {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withCommentMarker(CR));
     }
 
+
     @Test
     public void testWithDelimiter() {
         final CSVFormat formatWithDelimiter = 
CSVFormat.DEFAULT.withDelimiter('!');
         assertEquals('!', formatWithDelimiter.getDelimiter());
     }
 
+
     @Test
     public void testWithDelimiterLFThrowsException() {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withDelimiter(LF));
     }
 
+
     @Test
     public void testWithEmptyEnum() {
         final CSVFormat formatWithHeader = 
CSVFormat.DEFAULT.withHeader(EmptyEnum.class);
         assertTrue(formatWithHeader.getHeader().length == 0);
     }
 
+
     @Test
     public void testWithEscape() {
         final CSVFormat formatWithEscape = CSVFormat.DEFAULT.withEscape('&');
         assertEquals(Character.valueOf('&'), 
formatWithEscape.getEscapeCharacter());
     }
 
+
     @Test
     public void testWithEscapeCRThrowsExceptions() {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withEscape(CR));
     }
 
+
     @Test
     public void testWithFirstRecordAsHeader() {
         final CSVFormat formatWithFirstRecordAsHeader = 
CSVFormat.DEFAULT.withFirstRecordAsHeader();
@@ -1199,7 +1316,6 @@ public class CSVFormatTest {
         assertNotSame(header, formatWithHeader.getHeader());
     }
 
-
     @Test
     public void testWithHeaderComments() {
 
@@ -1361,13 +1477,25 @@ public class CSVFormatTest {
 
     }
 
-
     @Test
     public void testWithHeaderEnum() {
         final CSVFormat formatWithHeader = 
CSVFormat.DEFAULT.withHeader(Header.class);
         assertArrayEquals(new String[]{ "Name", "Email", "Phone" }, 
formatWithHeader.getHeader());
     }
 
+    @Test
+    public void testWithHeaderEnumNull() {
+        final CSVFormat format =  CSVFormat.DEFAULT;
+        final Class<Enum<?>> simpleName = null;
+        format.withHeader(simpleName);
+    }
+
+    @Test
+    public  void testWithHeaderResultSetNull() throws SQLException {
+        final CSVFormat format = CSVFormat.DEFAULT;
+        final ResultSet resultSet = null;
+        format.withHeader(resultSet);
+    }
 
     @Test
     public void testWithIgnoreEmptyLines() {
@@ -1375,28 +1503,24 @@ public class CSVFormatTest {
         
assertTrue(CSVFormat.DEFAULT.withIgnoreEmptyLines().getIgnoreEmptyLines());
     }
 
-
     @Test
     public void testWithIgnoreSurround() {
         
assertFalse(CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(false).getIgnoreSurroundingSpaces());
         
assertTrue(CSVFormat.DEFAULT.withIgnoreSurroundingSpaces().getIgnoreSurroundingSpaces());
     }
 
-
     @Test
     public void testWithNullString() {
         final CSVFormat formatWithNullString = 
CSVFormat.DEFAULT.withNullString("null");
         assertEquals("null", formatWithNullString.getNullString());
     }
 
-
     @Test
     public void testWithQuoteChar() {
         final CSVFormat formatWithQuoteChar = CSVFormat.DEFAULT.withQuote('"');
         assertEquals(Character.valueOf('"'), 
formatWithQuoteChar.getQuoteCharacter());
     }
 
-
     @Test
     public void testWithQuoteLFThrowsException() {
         assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.DEFAULT.withQuote(LF));
@@ -1431,103 +1555,4 @@ public class CSVFormatTest {
         final CSVFormat formatWithRecordSeparator = 
CSVFormat.DEFAULT.withSystemRecordSeparator();
         assertEquals(System.getProperty("line.separator"), 
formatWithRecordSeparator.getRecordSeparator());
     }
-
-    @Test
-    public void testPrintWithEscapesEndWithCRLF() throws IOException {
-        final Reader in = new StringReader("x,y,x\r\na,?b,c\r\n");
-        final Appendable out = new StringBuilder();
-        final CSVFormat format = 
CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF);
-        format.print(in,out,true);
-        assertEquals("x?,y?,x?r?na?,??b?,c?r?n", out.toString());
-    }
-
-    @Test
-    public void testPrintWithEscapesEndWithoutCRLF() throws IOException {
-        final Reader in = new StringReader("x,y,x");
-        final Appendable out = new StringBuilder();
-        final CSVFormat format = 
CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF);
-        format.print(in,out,true);
-        assertEquals("x?,y?,x", out.toString());
-    }
-
-    @Test
-    public void testFormatToString() {
-        final CSVFormat format = 
CSVFormat.RFC4180.withEscape('?').withDelimiter(',')
-                
.withQuoteMode(QuoteMode.MINIMAL).withRecordSeparator(CRLF).withQuote('"')
-                .withNullString("").withIgnoreHeaderCase(true)
-                .withHeaderComments("This is 
HeaderComments").withHeader("col1","col2","col3");
-        assertEquals("Delimiter=<,> Escape=<?> QuoteChar=<\"> 
QuoteMode=<MINIMAL> NullString=<> RecordSeparator=<" +CRLF+
-                "> IgnoreHeaderCase:ignored SkipHeaderRecord:false 
HeaderComments:[This is HeaderComments] Header:[col1, col2, col3]", 
format.toString());
-    }
-
-    @Test
-    public void testDelimiterSameAsRecordSeparatorThrowsException() {
-        assertThrows(IllegalArgumentException.class, () -> 
CSVFormat.newFormat(CR));
-    }
-
-    @Test
-    public void testWithHeaderEnumNull() {
-        final CSVFormat format =  CSVFormat.DEFAULT;
-        final Class<Enum<?>> simpleName = null;
-        format.withHeader(simpleName);
-    }
-
-    @Test
-    public  void testWithHeaderResultSetNull() throws SQLException {
-        final CSVFormat format = CSVFormat.DEFAULT;
-        final ResultSet resultSet = null;
-        format.withHeader(resultSet);
-    }
-
-    @Test
-    public void testPrintWithQuoteModeIsNONE() throws IOException {
-        final Reader in = new StringReader("a,b,c");
-        final Appendable out = new StringBuilder();
-        final CSVFormat format = 
CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE);
-        format.print(in, out, true);
-        assertEquals("a?,b?,c", out.toString());
-    }
-
-    @Test
-    public void testPrintWithQuotes() throws IOException {
-        final Reader in = new StringReader("\"a,b,c\r\nx,y,z");
-        final Appendable out = new StringBuilder();
-        final CSVFormat format = 
CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
-        format.print(in, out, true);
-        assertEquals("\"\"\"\"a,b,c\r\nx,y,z\"", out.toString());
-    }
-
-    @Test
-    public void testPrintWithoutQuotes() throws IOException {
-        final Reader in = new StringReader("");
-        final Appendable out = new StringBuilder();
-        final CSVFormat format = 
CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
-        format.print(in, out, true);
-        assertEquals("\"\"", out.toString());
-    }
-
-    @Test
-    public void testTrim() throws IOException {
-        final CSVFormat formatWithTrim = 
CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF);
-
-        CharSequence in = "a,b,c";
-        final StringBuilder out = new StringBuilder();
-        formatWithTrim.print(in, out, true);
-        assertEquals("a,b,c", out.toString());
-
-        in = new StringBuilder(" x,y,z");
-        out.setLength(0);
-        formatWithTrim.print(in, out, true);
-        assertEquals("x,y,z", out.toString());
-
-        in = new StringBuilder("");
-        out.setLength(0);
-        formatWithTrim.print(in, out, true);
-        assertEquals("", out.toString());
-
-        in = new StringBuilder("header\r\n");
-        out.setLength(0);
-        formatWithTrim.print(in, out, true);
-        assertEquals("header", out.toString());
-    }
 }

Reply via email to