This is an automated email from the ASF dual-hosted git repository.

garydgregory 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 d959de8f Add 
DefaultParserTest.testPropertiesPreserveExistingOptionValue()
d959de8f is described below

commit d959de8fb66f8aee8964dd3080920dfb9cdfcdc3
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Oct 28 09:07:05 2026 -0400

    Add DefaultParserTest.testPropertiesPreserveExistingOptionValue()
---
 .../java/org/apache/commons/cli/DefaultParserTest.java    | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/DefaultParserTest.java 
b/src/test/java/org/apache/commons/cli/DefaultParserTest.java
index c162323f..eb21171f 100644
--- a/src/test/java/org/apache/commons/cli/DefaultParserTest.java
+++ b/src/test/java/org/apache/commons/cli/DefaultParserTest.java
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.HashSet;
+import java.util.Properties;
 import java.util.Set;
 import java.util.stream.Stream;
 
@@ -400,6 +401,20 @@ class DefaultParserTest extends AbstractParserTestCase {
         assertTrue(e.getMessage().contains("-d"));
     }
 
+    @Test
+    void testPropertiesPreserveExistingOptionValue() throws ParseException {
+        final Option option = Option.builder("o").hasArg().get();
+        option.getValuesList().add("preset");
+        final Options options = new Options().addOption(option);
+        final Properties properties = new Properties();
+        properties.setProperty("o", "fallback");
+
+        final CommandLine cmd = new DefaultParser().parse(options, new 
String[0], properties);
+
+        assertEquals("preset", cmd.getOptionValue("o"));
+        assertEquals("preset", option.getValue());
+    }
+
     @Override
     @Test
     @Disabled("Test case handled in the parameterized tests as \"DEFAULT 
behavior\"")

Reply via email to