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-cli.git

commit ae92da886a36a1b869d8769c918e3932e9d67024
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Oct 19 08:35:48 2024 -0400

    Port to JUnit 5
---
 src/changes/changes.xml                            |  3 ++-
 .../java/org/apache/commons/cli/OptionsTest.java   | 22 ++++------------------
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1cfd8500..880424a7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -26,7 +26,8 @@
       <!-- FIX -->
       <action type="add" issue="CLI-339" dev="ggregory" due-to="Gary 
Gregory">Deprecate CommandLine.Builder() in favor of 
CommandLine.builder().</action>
       <action type="add" issue="CLI-339" dev="ggregory" due-to="Gary 
Gregory">Deprecate DeprecatedAttributes.Builder() in favor of 
DeprecatedAttributes.builder().</action>
-      <action type="add" issue="CLI-339" dev="ggregory" due-to="Dávid 
Szigecsán">Refactor default parser test #294.</action> 
+      <action type="add" issue="CLI-339" dev="ggregory" due-to="Dávid 
Szigecsán">Refactor default parser test #294.</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Port to JUnit 
5.</action> 
       <!-- ADD -->
       <action type="add" issue="CLI-339" dev="ggregory" due-to="Claude Warren, 
Gary Gregory">Help formatter extension in the new package #314.</action>
       <action type="add" dev="ggregory" due-to="Gary 
Gregory">CommandLine.Builder implements Supplier&lt;CommandLine&gt;.</action>
diff --git a/src/test/java/org/apache/commons/cli/OptionsTest.java 
b/src/test/java/org/apache/commons/cli/OptionsTest.java
index 41f7c515..be1fb0fb 100644
--- a/src/test/java/org/apache/commons/cli/OptionsTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionsTest.java
@@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -241,10 +240,8 @@ public class OptionsTest {
     @Test
     public void testLong() {
         final Options options = new Options();
-
         options.addOption("a", "--a", false, "toggle -a");
         options.addOption("b", "--b", true, "set -b");
-
         assertTrue(options.hasOption("a"));
         assertTrue(options.hasOption("b"));
     }
@@ -254,12 +251,8 @@ public class OptionsTest {
         final Options options = new Options();
         OptionBuilder.isRequired();
         options.addOption(OptionBuilder.create("f"));
-        try {
-            new PosixParser().parse(options, new String[0]);
-            fail("Expected MissingOptionException to be thrown");
-        } catch (final MissingOptionException e) {
-            assertEquals("Missing required option: f", e.getMessage());
-        }
+        final MissingOptionException e = 
assertThrows(MissingOptionException.class, () -> new 
PosixParser().parse(options, new String[0]));
+        assertEquals("Missing required option: f", e.getMessage());
     }
 
     @Test
@@ -269,21 +262,15 @@ public class OptionsTest {
         options.addOption(OptionBuilder.create("f"));
         OptionBuilder.isRequired();
         options.addOption(OptionBuilder.create("x"));
-        try {
-            new PosixParser().parse(options, new String[0]);
-            fail("Expected MissingOptionException to be thrown");
-        } catch (final MissingOptionException e) {
-            assertEquals("Missing required options: f, x", e.getMessage());
-        }
+        final MissingOptionException e = 
assertThrows(MissingOptionException.class, () -> new 
PosixParser().parse(options, new String[0]));
+        assertEquals("Missing required options: f, x", e.getMessage());
     }
 
     @Test
     public void testSimple() {
         final Options options = new Options();
-
         options.addOption("a", false, "toggle -a");
         options.addOption("b", true, "toggle -b");
-
         assertTrue(options.hasOption("a"));
         assertTrue(options.hasOption("b"));
     }
@@ -293,7 +280,6 @@ public class OptionsTest {
         final Options options = new Options();
         options.addOption("f", "foo", true, "Foo");
         options.addOption("b", "bar", false, "Bar");
-
         final String s = options.toString();
         assertNotNull(s, "null string returned");
         assertTrue(s.toLowerCase().contains("foo"), "foo option missing");

Reply via email to