Skip to content

Commit ae92da8

Browse files
committed
Port to JUnit 5
1 parent 7fabac6 commit ae92da8

2 files changed

Lines changed: 6 additions & 19 deletions

File tree

src/changes/changes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<!-- FIX -->
2727
<action type="add" issue="CLI-339" dev="ggregory" due-to="Gary Gregory">Deprecate CommandLine.Builder() in favor of CommandLine.builder().</action>
2828
<action type="add" issue="CLI-339" dev="ggregory" due-to="Gary Gregory">Deprecate DeprecatedAttributes.Builder() in favor of DeprecatedAttributes.builder().</action>
29-
<action type="add" issue="CLI-339" dev="ggregory" due-to="Dávid Szigecsán">Refactor default parser test #294.</action>
29+
<action type="add" issue="CLI-339" dev="ggregory" due-to="Dávid Szigecsán">Refactor default parser test #294.</action>
30+
<action type="add" dev="ggregory" due-to="Gary Gregory">Port to JUnit 5.</action>
3031
<!-- ADD -->
3132
<action type="add" issue="CLI-339" dev="ggregory" due-to="Claude Warren, Gary Gregory">Help formatter extension in the new package #314.</action>
3233
<action type="add" dev="ggregory" due-to="Gary Gregory">CommandLine.Builder implements Supplier&lt;CommandLine&gt;.</action>

src/test/java/org/apache/commons/cli/OptionsTest.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2424
import static org.junit.jupiter.api.Assertions.assertNotNull;
2525
import static org.junit.jupiter.api.Assertions.assertThrows;
2626
import static org.junit.jupiter.api.Assertions.assertTrue;
27-
import static org.junit.jupiter.api.Assertions.fail;
2827

2928
import java.util.ArrayList;
3029
import java.util.Arrays;
@@ -241,10 +240,8 @@ public void testHelpOptions() {
241240
@Test
242241
public void testLong() {
243242
final Options options = new Options();
244-
245243
options.addOption("a", "--a", false, "toggle -a");
246244
options.addOption("b", "--b", true, "set -b");
247-
248245
assertTrue(options.hasOption("a"));
249246
assertTrue(options.hasOption("b"));
250247
}
@@ -254,12 +251,8 @@ public void testMissingOptionException() throws ParseException {
254251
final Options options = new Options();
255252
OptionBuilder.isRequired();
256253
options.addOption(OptionBuilder.create("f"));
257-
try {
258-
new PosixParser().parse(options, new String[0]);
259-
fail("Expected MissingOptionException to be thrown");
260-
} catch (final MissingOptionException e) {
261-
assertEquals("Missing required option: f", e.getMessage());
262-
}
254+
final MissingOptionException e = assertThrows(MissingOptionException.class, () -> new PosixParser().parse(options, new String[0]));
255+
assertEquals("Missing required option: f", e.getMessage());
263256
}
264257

265258
@Test
@@ -269,21 +262,15 @@ public void testMissingOptionsException() throws ParseException {
269262
options.addOption(OptionBuilder.create("f"));
270263
OptionBuilder.isRequired();
271264
options.addOption(OptionBuilder.create("x"));
272-
try {
273-
new PosixParser().parse(options, new String[0]);
274-
fail("Expected MissingOptionException to be thrown");
275-
} catch (final MissingOptionException e) {
276-
assertEquals("Missing required options: f, x", e.getMessage());
277-
}
265+
final MissingOptionException e = assertThrows(MissingOptionException.class, () -> new PosixParser().parse(options, new String[0]));
266+
assertEquals("Missing required options: f, x", e.getMessage());
278267
}
279268

280269
@Test
281270
public void testSimple() {
282271
final Options options = new Options();
283-
284272
options.addOption("a", false, "toggle -a");
285273
options.addOption("b", true, "toggle -b");
286-
287274
assertTrue(options.hasOption("a"));
288275
assertTrue(options.hasOption("b"));
289276
}
@@ -293,7 +280,6 @@ public void testToString() {
293280
final Options options = new Options();
294281
options.addOption("f", "foo", true, "Foo");
295282
options.addOption("b", "bar", false, "Bar");
296-
297283
final String s = options.toString();
298284
assertNotNull(s, "null string returned");
299285
assertTrue(s.toLowerCase().contains("foo"), "foo option missing");

0 commit comments

Comments
 (0)