Skip to content

Commit

Permalink
Merge 53189e9 into dc5d034
Browse files Browse the repository at this point in the history
  • Loading branch information
amarlearning committed Jul 4, 2021
2 parents dc5d034 + 53189e9 commit d06487f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/apache/commons/csv/CSVPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ public void printRecord(final Iterable<?> values) throws IOException {
* If an I/O error occurs
*/
public void printRecord(final Object... values) throws IOException {
format.printRecord(out, values);
newRecord = true;
printRecord(Arrays.asList(values));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/csv/CSVFormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Objects;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -555,7 +556,7 @@ public void testFormatThrowsNullPointerException() {
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
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java
Original file line number Diff line number Diff line change
@@ -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());
}

}

0 comments on commit d06487f

Please sign in to comment.