You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/03/15 15:34:42 UTC
(commons-csv) 07/09: Add missing test cases for CSVFormat.CSVFormat(char|String)
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
commit 61878d773d74b2e2ab1b2bb7ed3519bd47e1fc58
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 15 10:33:08 2025 -0400
Add missing test cases for CSVFormat.CSVFormat(char|String)
Remove redundant check since setter handles the CR/LF cases when calling
setDelimiter()
---
src/main/java/org/apache/commons/csv/CSVFormat.java | 3 ---
.../java/org/apache/commons/csv/CSVFormatTest.java | 20 ++++++++++++++++++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 7671ccab..9bcf9d18 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -2602,9 +2602,6 @@ public final class CSVFormat implements Serializable {
* @throws IllegalArgumentException Throw when any attribute is invalid or inconsistent with other attributes.
*/
private void validate() throws IllegalArgumentException {
- if (containsLineBreak(delimiter)) {
- throw new IllegalArgumentException("The delimiter cannot be a line break");
- }
if (quoteCharacter != null && contains(delimiter, quoteCharacter.charValue())) { // Explicit (un)boxing is intentional
throw new IllegalArgumentException("The quoteChar character and the delimiter cannot be the same ('" + quoteCharacter + "')");
}
diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index 9677d8ec..0c7e763e 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -88,6 +88,16 @@ public class CSVFormatTest {
assertNotSame(builder.get(), builder.build());
}
+ @Test
+ public void testDelimiterCharLineBreakCrThrowsException1() {
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(Constants.CR).get());
+ }
+
+ @Test
+ public void testDelimiterCharLineBreakLfThrowsException1() {
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(Constants.LF).get());
+ }
+
@Test
public void testDelimiterEmptyStringThrowsException1() {
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").get());
@@ -120,6 +130,16 @@ public class CSVFormatTest {
assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat(CR));
}
+ @Test
+ public void testDelimiterStringLineBreakCrThrowsException1() {
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(String.valueOf(Constants.CR)).get());
+ }
+
+ @Test
+ public void testDelimiterStringLineBreakLfThrowsException1() {
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(String.valueOf(Constants.LF)).get());
+ }
+
@Test
public void testDuplicateHeaderElements() {
final String[] header = { "A", "A" };