1919
2020import org .apache .commons .csv .CSVFormat ;
2121import org .apache .commons .csv .DuplicateHeaderMode ;
22- import org .junit .jupiter .api .Assertions ;
2322import org .junit .jupiter .api .Test ;
2423
24+ import static org .junit .jupiter .api .Assertions .assertThrows ;
25+
2526import java .io .IOException ;
2627import 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 */
3435public 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