Skip to content

Commit 61878d7

Browse files
committed
Add missing test cases for CSVFormat.CSVFormat(char|String)
Remove redundant check since setter handles the CR/LF cases when calling setDelimiter()
1 parent 054dc91 commit 61878d7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,9 +2602,6 @@ boolean useRow(final long rowNum) {
26022602
* @throws IllegalArgumentException Throw when any attribute is invalid or inconsistent with other attributes.
26032603
*/
26042604
private void validate() throws IllegalArgumentException {
2605-
if (containsLineBreak(delimiter)) {
2606-
throw new IllegalArgumentException("The delimiter cannot be a line break");
2607-
}
26082605
if (quoteCharacter != null && contains(delimiter, quoteCharacter.charValue())) { // Explicit (un)boxing is intentional
26092606
throw new IllegalArgumentException("The quoteChar character and the delimiter cannot be the same ('" + quoteCharacter + "')");
26102607
}

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ public void testBuildVsGet() {
8888
assertNotSame(builder.get(), builder.build());
8989
}
9090

91+
@Test
92+
public void testDelimiterCharLineBreakCrThrowsException1() {
93+
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(Constants.CR).get());
94+
}
95+
96+
@Test
97+
public void testDelimiterCharLineBreakLfThrowsException1() {
98+
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(Constants.LF).get());
99+
}
100+
91101
@Test
92102
public void testDelimiterEmptyStringThrowsException1() {
93103
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").get());
@@ -120,6 +130,16 @@ public void testDelimiterSameAsRecordSeparatorThrowsException() {
120130
assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat(CR));
121131
}
122132

133+
@Test
134+
public void testDelimiterStringLineBreakCrThrowsException1() {
135+
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(String.valueOf(Constants.CR)).get());
136+
}
137+
138+
@Test
139+
public void testDelimiterStringLineBreakLfThrowsException1() {
140+
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter(String.valueOf(Constants.LF)).get());
141+
}
142+
123143
@Test
124144
public void testDuplicateHeaderElements() {
125145
final String[] header = { "A", "A" };

0 commit comments

Comments
 (0)