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 2c83a30  Fixed CSV-271 & Add testcase for new change (#157)
2c83a30 is described below

commit 2c83a308255d07295c761d7e61f10359b0687b01
Author: Amar Prakash Pandey <amar.om1...@gmail.com>
AuthorDate: Mon Jul 5 03:05:02 2021 +0530

    Fixed CSV-271 & Add testcase for new change (#157)
---
 .../java/org/apache/commons/csv/CSVPrinter.java    |  3 +-
 .../java/org/apache/commons/csv/CSVFormatTest.java |  3 +-
 .../apache/commons/csv/issues/JiraCsv271Test.java  | 54 ++++++++++++++++++++++
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/csv/CSVPrinter.java 
b/src/main/java/org/apache/commons/csv/CSVPrinter.java
index b953582..161f452 100644
--- a/src/main/java/org/apache/commons/csv/CSVPrinter.java
+++ b/src/main/java/org/apache/commons/csv/CSVPrinter.java
@@ -281,8 +281,7 @@ public final class CSVPrinter implements Flushable, 
Closeable {
      *             If an I/O error occurs
      */
     public void printRecord(final Object... values) throws IOException {
-        format.printRecord(out, values);
-        newRecord = true;
+        printRecord(Arrays.asList(values));
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java 
b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index 2c29463..3e5d734 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -43,6 +43,7 @@ import java.lang.reflect.Modifier;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
+import java.util.Objects;
 
 import org.junit.jupiter.api.Test;
 
@@ -771,7 +772,7 @@ public class CSVFormatTest {
         final CSVFormat csvFormat = CSVFormat.MYSQL;
 
         final NullPointerException e = 
assertThrows(NullPointerException.class, () -> csvFormat.format((Object[]) 
null));
-        assertEquals(CSVFormat.class.getName(), 
e.getStackTrace()[0].getClassName());
+        assertEquals(Objects.class.getName(), 
e.getStackTrace()[0].getClassName());
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java 
b/src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java
new file mode 100644
index 0000000..6150a76
--- /dev/null
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java
@@ -0,0 +1,54 @@
+/*
+ * 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.csv.issues;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Arrays;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.junit.jupiter.api.Test;
+
+public class JiraCsv271Test {
+
+    @Test
+    public void testJiraCsv271_withArray() throws IOException {
+        final CSVFormat csvFormat = CSVFormat.DEFAULT;
+        final StringWriter stringWriter = new StringWriter();
+        try (CSVPrinter printer = new CSVPrinter(stringWriter, csvFormat)) {
+            printer.print("a");
+            printer.printRecord("b","c");
+        }
+        assertEquals("a,b,c\r\n", stringWriter.toString());
+    }
+
+    @Test
+    public void testJiraCsv271_withList() throws IOException {
+        final CSVFormat csvFormat = CSVFormat.DEFAULT;
+        final StringWriter stringWriter = new StringWriter();
+        try (CSVPrinter printer = new CSVPrinter(stringWriter, csvFormat)) {
+            printer.print("a");
+            printer.printRecord(Arrays.asList("b","c"));
+        }
+        assertEquals("a,b,c\r\n", stringWriter.toString());
+    }
+
+}

Reply via email to