commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1706542 - in /commons/proper/csv/trunk/src: changes/changes.xml main/java/org/apache/commons/csv/CSVPrinter.java test/java/org/apache/commons/csv/CSVPrinterTest.java
Date Sat, 03 Oct 2015 10:46:49 GMT
Author: britter
Date: Sat Oct  3 10:46:49 2015
New Revision: 1706542

URL: http://svn.apache.org/viewvc?rev=1706542&view=rev
Log:
CSV-153: CSVPrinter doesn't skip creation of header record if skipHeaderRecord is set to true.
Thanks to Wren. This also fixes #8 from github.

Modified:
    commons/proper/csv/trunk/src/changes/changes.xml
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Modified: commons/proper/csv/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/changes/changes.xml?rev=1706542&r1=1706541&r2=1706542&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/changes/changes.xml (original)
+++ commons/proper/csv/trunk/src/changes/changes.xml Sat Oct  3 10:46:49 2015
@@ -39,7 +39,7 @@
   </properties>
   <body>
     <release version="1.3" date="2015-MM-DD" description="Feature and bug fix release">
-      <action issue="CSV-???" type="???" dev="???" due-to="???">???</action>
+      <action issue="CSV-153" type="update" dev="britter" due-to="Wren">CSVPrinter
doesn't skip creation of header record if skipHeaderRecord is set to true</action>
     </release>
     <release version="1.2" date="2015-08-24" description="Feature and bug fix release">
       <action issue="CSV-145" type="fix" dev="ggregory" due-to="Frank Ulbricht">CSVFormat.with*
methods clear the header comments</action>

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java?rev=1706542&r1=1706541&r2=1706542&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java Sat Oct
 3 10:46:49 2015
@@ -73,7 +73,7 @@ public final class CSVPrinter implements
                 }
             }
         }
-        if (format.getHeader() != null) {
+        if (format.getHeader() != null && !format.getSkipHeaderRecord()) {
             this.printRecord((Object[]) format.getHeader());
         }
     }

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java?rev=1706542&r1=1706541&r2=1706542&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java Sat
Oct  3 10:46:49 2015
@@ -558,6 +558,40 @@ public class CSVPrinterTest {
     }
 
     @Test
+    public void testHeaderNotSet() throws IOException {
+        final StringWriter sw = new StringWriter();
+        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null));
+        printer.printRecord("a", "b", "c");
+        printer.printRecord("x", "y", "z");
+        assertEquals("a,b,c\r\nx,y,z\r\n", sw.toString());
+        printer.close();
+    }
+
+    @Test
+    public void testSkipHeaderRecordTrue() throws IOException {
+    	// functionally identical to testHeaderNotSet, used to test CSV-153
+        final StringWriter sw = new StringWriter();
+        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null)
+                .withHeader("C1", "C2", "C3").withSkipHeaderRecord(true));
+        printer.printRecord("a", "b", "c");
+        printer.printRecord("x", "y", "z");
+        assertEquals("a,b,c\r\nx,y,z\r\n", sw.toString());
+        printer.close();
+    }
+
+    @Test
+    public void testSkipHeaderRecordFalse() throws IOException {
+    	// functionally identical to testHeader, used to test CSV-153
+        final StringWriter sw = new StringWriter();
+        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null)
+                .withHeader("C1", "C2", "C3").withSkipHeaderRecord(false));
+        printer.printRecord("a", "b", "c");
+        printer.printRecord("x", "y", "z");
+        assertEquals("C1,C2,C3\r\na,b,c\r\nx,y,z\r\n", sw.toString());
+        printer.close();
+    }
+
+    @Test
     public void testHeaderCommentExcel() throws IOException {
         final StringWriter sw = new StringWriter();
         final Date now = new Date();



Mime
View raw message