Skip to content

Commit b6b801b

Browse files
committed
fix: use assertthrows and update docs
1 parent 9cf0b00 commit b6b801b

4 files changed

Lines changed: 16 additions & 26 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,10 +1463,10 @@ public boolean getAllowDuplicateHeaderNames() {
14631463
}
14641464

14651465
/**
1466-
* Returns how duplicate headers are handled.
1466+
* Gets how duplicate headers are handled.
14671467
*
14681468
* @return if duplicate header values are allowed, allowed conditionally, or disallowed.
1469-
* @since 1.9
1469+
* @since 1.9.0
14701470
*/
14711471
public DuplicateHeaderMode getDuplicateHeaderMode() {
14721472
return duplicateHeaderMode;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.commons.csv;
1919

20+
import static org.apache.commons.csv.Token.Type.TOKEN;
21+
2022
import java.io.Closeable;
2123
import java.io.File;
2224
import java.io.IOException;
@@ -43,8 +45,6 @@
4345
import java.util.stream.Stream;
4446
import java.util.stream.StreamSupport;
4547

46-
import static org.apache.commons.csv.Token.Type.TOKEN;
47-
4848
/**
4949
* Parses CSV files according to the specified format.
5050
*

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,22 @@
2121
* Determines how duplicate header fields should be handled
2222
* if {@link CSVFormat#withHeader(String...)} is not null.
2323
*
24-
* @since 1.9
24+
* @since 1.9.0
2525
*/
2626
public enum DuplicateHeaderMode {
2727

2828
/**
29-
* Allows all duplicate headings.
29+
* Allows all duplicate headers.
3030
*/
3131
ALLOW_ALL,
3232

3333
/**
34-
* Allows duplicate headings only if they're empty
35-
* strings or null.
34+
* Allows duplicate headers only if they're empty strings or null.
3635
*/
3736
ALLOW_EMPTY,
3837

3938
/**
40-
* Disallows duplicate headings entirely.
39+
* Disallows duplicate headers entirely.
4140
*/
4241
DISALLOW
4342
}

src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@
1919

2020
import org.apache.commons.csv.CSVFormat;
2121
import org.apache.commons.csv.DuplicateHeaderMode;
22-
import org.junit.jupiter.api.Assertions;
2322
import org.junit.jupiter.api.Test;
2423

24+
import static org.junit.jupiter.api.Assertions.assertThrows;
25+
2526
import java.io.IOException;
2627
import java.io.StringReader;
2728

2829
/**
29-
* When {@link CSVFormat#withHeader(String...)} is not null;
30-
* duplicate headers with empty strings should not be allowed.
30+
* When {@link CSVFormat#withHeader(String...)} is not null; duplicate headers
31+
* with empty strings should not be allowed.
3132
*
32-
* @see <a href="https://issues.apache.org/jira/projects/CSV/issues/CSV-264?filter=allopenissues">Jira Ticker</a>
33+
* @see <a href="https://issues.apache.org/jira/browse/CSV-264">Jira Ticker</a>
3334
*/
3435
public class JiraCsv264Test {
35-
36+
3637
private static final String CSV_STRING = "\"\",\"B\",\"\"\n" +
3738
"\"1\",\"2\",\"3\"\n" +
3839
"\"4\",\"5\",\"6\"";
@@ -54,12 +55,7 @@ public void testJiraCsv264() throws IOException {
5455
.build();
5556

5657
try (StringReader reader = new StringReader(CSV_STRING)) {
57-
try {
58-
csvFormat.parse(reader);
59-
Assertions.fail("This shouldn't parse the CSV string successfully.");
60-
} catch (IllegalArgumentException ex) {
61-
// Test is successful!
62-
}
58+
assertThrows(IllegalArgumentException.class, () -> csvFormat.parse(reader));
6359
}
6460
}
6561

@@ -87,12 +83,7 @@ public void testJiraCsv264WithGapDisallow() throws IOException {
8783
.build();
8884

8985
try (StringReader reader = new StringReader(CSV_STRING_GAP)) {
90-
try {
91-
csvFormat.parse(reader);
92-
Assertions.fail("This shouldn't parse the CSV string successfully.");
93-
} catch (IllegalArgumentException ex) {
94-
// Test is successful!
95-
}
86+
assertThrows(IllegalArgumentException.class, () -> csvFormat.parse(reader));
9687
}
9788
}
9889
}

0 commit comments

Comments
 (0)