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
The following commit(s) were added to refs/heads/master by this push:
new cd3f2c49 Sort members
cd3f2c49 is described below
commit cd3f2c49866f73f27a494de5155a5c9a99f33a32
Author: Gary D. Gregory <[email protected]>
AuthorDate: Tue Jul 29 11:22:03 2025 -0400
Sort members
---
src/main/java/org/apache/commons/cli/Option.java | 26 +++++++++----------
.../java/org/apache/commons/cli/OptionsTest.java | 30 +++++++++++-----------
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/main/java/org/apache/commons/cli/Option.java
b/src/main/java/org/apache/commons/cli/Option.java
index 3ee0133b..675f802f 100644
--- a/src/main/java/org/apache/commons/cli/Option.java
+++ b/src/main/java/org/apache/commons/cli/Option.java
@@ -136,19 +136,6 @@ public class Option implements Cloneable, Serializable {
return get();
}
- /**
- * Constructs an Option with the values declared by this {@link
Builder}.
- *
- * @return the new {@link Option}.
- * @throws IllegalArgumentException if neither {@code opt} or {@code
longOpt} has been set.
- */
- public Option get() {
- if (option == null && longOption == null) {
- throw new IllegalArgumentException("Either opt or longOpt must
be specified");
- }
- return new Option(this);
- }
-
/**
* Sets the converter for the option.
* <p>
@@ -197,6 +184,19 @@ public class Option implements Cloneable, Serializable {
return this;
}
+ /**
+ * Constructs an Option with the values declared by this {@link
Builder}.
+ *
+ * @return the new {@link Option}.
+ * @throws IllegalArgumentException if neither {@code opt} or {@code
longOpt} has been set.
+ */
+ public Option get() {
+ if (option == null && longOption == null) {
+ throw new IllegalArgumentException("Either opt or longOpt must
be specified");
+ }
+ return new Option(this);
+ }
+
/**
* Tests whether the Option will require an argument.
*
diff --git a/src/test/java/org/apache/commons/cli/OptionsTest.java
b/src/test/java/org/apache/commons/cli/OptionsTest.java
index 1ce1c211..9727988e 100644
--- a/src/test/java/org/apache/commons/cli/OptionsTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionsTest.java
@@ -36,21 +36,6 @@ import org.junit.jupiter.api.Test;
@SuppressWarnings("deprecation") // tests some deprecated classes
class OptionsTest {
- @Test
- void testRequiredOptionInGroupShouldNotBeInRequiredList() {
- final String key = "a";
- final Option option = new Option(key, "along", false, "Option A");
- option.setRequired(true);
- final Options options = new Options();
- options.addOption(option);
- assertTrue(options.getRequiredOptions().contains(key));
- final OptionGroup optionGroup = new OptionGroup();
- optionGroup.addOption(option);
- options.addOptionGroup(optionGroup);
- assertFalse(options.getOption(key).isRequired());
- assertFalse(options.getRequiredOptions().contains(key), "Option in
group shouldn't be in required options list.");
- }
-
private void assertToStrings(final Option option) {
// Should never throw.
// Should return a String, not null.
@@ -280,6 +265,21 @@ class OptionsTest {
assertEquals("Missing required options: f, x", e.getMessage());
}
+ @Test
+ void testRequiredOptionInGroupShouldNotBeInRequiredList() {
+ final String key = "a";
+ final Option option = new Option(key, "along", false, "Option A");
+ option.setRequired(true);
+ final Options options = new Options();
+ options.addOption(option);
+ assertTrue(options.getRequiredOptions().contains(key));
+ final OptionGroup optionGroup = new OptionGroup();
+ optionGroup.addOption(option);
+ options.addOptionGroup(optionGroup);
+ assertFalse(options.getOption(key).isRequired());
+ assertFalse(options.getRequiredOptions().contains(key), "Option in
group shouldn't be in required options list.");
+ }
+
@Test
void testSimple() {
final Options options = new Options();