You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/04/08 13:13:10 UTC

(commons-cli) branch master updated (b87725f -> 9ff24a0)

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

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git


    from b87725f  Add missing API test
     new d4610ab  Add missing test for the deprecated handler
     new 58b98b4  Add missing test
     new 248a6cf  Add missing API test
     new 2028b84  Clean up exception message
     new 4fde00c  Add missing API test
     new 9d09134  Add missing test
     new ee0f911  Add missing API test
     new 9aee5d9  Make default constructor private
     new 7be99b5  Add missing test branch
     new db8c828  Javadoc
     new 76c70a0  Use assertThrows()
     new 9ff24a0  Add missing test branch

The 12 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/commons/cli/HelpFormatter.java | 24 ++++++-------
 src/main/java/org/apache/commons/cli/Option.java   |  2 +-
 src/main/java/org/apache/commons/cli/Util.java     |  4 +++
 .../org/apache/commons/cli/CommandLineTest.java    | 14 ++++++++
 .../org/apache/commons/cli/HelpFormatterTest.java  | 19 ++++-------
 .../java/org/apache/commons/cli/OptionTest.java    | 39 ++++++++++++++++++++++
 src/test/java/org/apache/commons/cli/UtilTest.java |  3 ++
 .../java/org/apache/commons/cli/bug/BugsTest.java  |  3 ++
 8 files changed, 82 insertions(+), 26 deletions(-)


(commons-cli) 12/12: Add missing test branch

Posted by gg...@apache.org.
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 9ff24a036f06f34c7490017dabd7ac918985c559
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 09:13:04 2024 -0400

    Add missing test branch
---
 src/test/java/org/apache/commons/cli/HelpFormatterTest.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
index d23f943..563aea8 100644
--- a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
+++ b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
@@ -351,7 +351,10 @@ public class HelpFormatterTest {
     public void testPrintHelpWithEmptySyntax() {
         final HelpFormatter formatter = new HelpFormatter();
         assertThrows(IllegalArgumentException.class, () -> formatter.printHelp(null, new Options()), "null command line syntax should be rejected");
-        assertThrows(IllegalArgumentException.class, () -> formatter.printHelp("", new Options()), "null command line syntax should be rejected");
+        assertThrows(IllegalArgumentException.class, () -> formatter.printHelp(null, new Options(), true), "null command line syntax should be rejected");
+        assertThrows(IllegalArgumentException.class, () -> formatter.printHelp(null, new Options(), false), "null command line syntax should be rejected");
+        assertThrows(IllegalArgumentException.class, () -> formatter.printHelp("", new Options(), true), "null command line syntax should be rejected");
+        assertThrows(IllegalArgumentException.class, () -> formatter.printHelp("", new Options(), false), "null command line syntax should be rejected");
     }
 
     @Test


(commons-cli) 09/12: Add missing test branch

Posted by gg...@apache.org.
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 7be99b5144e2a3b615e70cefa09f80232d799451
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 09:06:58 2024 -0400

    Add missing test branch
---
 src/test/java/org/apache/commons/cli/UtilTest.java | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/UtilTest.java b/src/test/java/org/apache/commons/cli/UtilTest.java
index beb57a5..8f24ff1 100644
--- a/src/test/java/org/apache/commons/cli/UtilTest.java
+++ b/src/test/java/org/apache/commons/cli/UtilTest.java
@@ -23,8 +23,11 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 import org.junit.jupiter.api.Test;
 
 public class UtilTest {
+
     @Test
     public void testStripLeadingAndTrailingQuotes() {
+        assertNull(Util.stripLeadingAndTrailingQuotes(null));
+        assertEquals("", Util.stripLeadingAndTrailingQuotes(""));
         assertEquals("foo", Util.stripLeadingAndTrailingQuotes("\"foo\""));
         assertEquals("foo \"bar\"", Util.stripLeadingAndTrailingQuotes("foo \"bar\""));
         assertEquals("\"foo\" bar", Util.stripLeadingAndTrailingQuotes("\"foo\" bar"));


(commons-cli) 05/12: Add missing API test

Posted by gg...@apache.org.
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 4fde00ce02011854dc500a51bdfd54d3b6c5b18c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 08:55:51 2024 -0400

    Add missing API test
---
 src/test/java/org/apache/commons/cli/OptionTest.java | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java b/src/test/java/org/apache/commons/cli/OptionTest.java
index 61f47cd..a2328c7 100644
--- a/src/test/java/org/apache/commons/cli/OptionTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionTest.java
@@ -104,6 +104,12 @@ public class OptionTest {
         return (Option) ois.readObject();
     }
 
+    @Test
+    public void testAddValue() {
+        final Option option = new Option("f", null);
+        assertThrows(UnsupportedOperationException.class, () -> option.addValue(""));
+    }
+
     @Test
     public void testBuilderInsufficientParams1() {
         assertThrows(IllegalArgumentException.class, () -> Option.builder().desc("desc").build());


(commons-cli) 02/12: Add missing test

Posted by gg...@apache.org.
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 58b98b46cc1d3412195c48e3caaa863141b4979e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 08:50:41 2024 -0400

    Add missing test
---
 src/test/java/org/apache/commons/cli/OptionTest.java | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java b/src/test/java/org/apache/commons/cli/OptionTest.java
index d56fd7e..61f47cd 100644
--- a/src/test/java/org/apache/commons/cli/OptionTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionTest.java
@@ -295,4 +295,22 @@ public class OptionTest {
         assertEquals("myfile.txt", clone.getValue());
         assertEquals(DefaultOption.class, clone.getClass());
     }
+
+    @Test
+    public void testTypeClass() {
+        final Option option = new Option("f", null);
+        assertEquals(String.class, option.getType());
+        option.setType(CharSequence.class);
+        assertEquals(CharSequence.class, option.getType());
+    }
+
+    @Test
+    public void testTypeObject() {
+        final Option option = new Option("f", null);
+        assertEquals(String.class, option.getType());
+        @SuppressWarnings("cast")
+        final Object type = (Object) CharSequence.class; // Do NOT remove cast
+        option.setType(type);
+        assertEquals(CharSequence.class, option.getType());
+    }
 }


(commons-cli) 04/12: Clean up exception message

Posted by gg...@apache.org.
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 2028b84219d2171f2758cee765305c74a2d2037a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 08:53:53 2024 -0400

    Clean up exception message
---
 src/main/java/org/apache/commons/cli/Option.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/cli/Option.java b/src/main/java/org/apache/commons/cli/Option.java
index 593a418..f403052 100644
--- a/src/main/java/org/apache/commons/cli/Option.java
+++ b/src/main/java/org/apache/commons/cli/Option.java
@@ -494,7 +494,7 @@ public class Option implements Cloneable, Serializable {
     @Deprecated
     public boolean addValue(final String value) {
         throw new UnsupportedOperationException(
-                "The addValue method is not intended for client use. " + "Subclasses should use the addValueForProcessing method instead. ");
+                "The addValue method is not intended for client use. Subclasses should use the addValueForProcessing method instead.");
     }
 
     /**


(commons-cli) 10/12: Javadoc

Posted by gg...@apache.org.
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 db8c8281d3a540f385c65bbc82cddab971ffb8db
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 09:09:49 2024 -0400

    Javadoc
---
 .../java/org/apache/commons/cli/HelpFormatter.java | 24 +++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/cli/HelpFormatter.java b/src/main/java/org/apache/commons/cli/HelpFormatter.java
index e445e1e..4979583 100644
--- a/src/main/java/org/apache/commons/cli/HelpFormatter.java
+++ b/src/main/java/org/apache/commons/cli/HelpFormatter.java
@@ -313,7 +313,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Return a String of padding of length {@code len}.
+     * Creates a String of padding of length {@code len}.
      *
      * @param len The length of the String of padding to create.
      *
@@ -459,7 +459,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax. This method prints help information
+     * Prints the help for {@code options} with the specified command line syntax. This method prints help information
      * to System.out.
      *
      * @param width the number of characters to be displayed on each line
@@ -473,7 +473,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax. This method prints help information
+     * Prints the help for {@code options} with the specified command line syntax. This method prints help information
      * to System.out.
      *
      * @param width the number of characters to be displayed on each line
@@ -491,7 +491,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax.
+     * Prints the help for {@code options} with the specified command line syntax.
      *
      * @param pw the writer to which the help will be written
      * @param width the number of characters to be displayed on each line
@@ -510,7 +510,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax.
+     * Prints the help for {@code options} with the specified command line syntax.
      *
      * @param pw the writer to which the help will be written
      * @param width the number of characters to be displayed on each line
@@ -544,7 +544,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax. This method prints help information
+     * Prints the help for {@code options} with the specified command line syntax. This method prints help information
      * to System.out.
      *
      * @param cmdLineSyntax the syntax for this application
@@ -555,7 +555,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax. This method prints help information
+     * Prints the help for {@code options} with the specified command line syntax. This method prints help information
      * to System.out.
      *
      * @param cmdLineSyntax the syntax for this application
@@ -567,7 +567,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax. This method prints help information
+     * Prints the help for {@code options} with the specified command line syntax. This method prints help information
      * to System.out.
      *
      * @param cmdLineSyntax the syntax for this application
@@ -580,7 +580,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for {@code options} with the specified command line syntax. This method prints help information
+     * Prints the help for {@code options} with the specified command line syntax. This method prints help information
      * to System.out.
      *
      * @param cmdLineSyntax the syntax for this application
@@ -594,7 +594,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the help for the specified Options to the specified writer, using the specified width, left padding and
+     * Prints the help for the specified Options to the specified writer, using the specified width, left padding and
      * description padding.
      *
      * @param pw The printWriter to write the help to
@@ -610,7 +610,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the cmdLineSyntax to the specified writer, using the specified width.
+     * Prints the cmdLineSyntax to the specified writer, using the specified width.
      *
      * @param pw The printWriter to write the help to
      * @param width The number of characters per line for the usage statement.
@@ -670,7 +670,7 @@ public class HelpFormatter {
     }
 
     /**
-     * Print the specified text to the specified PrintWriter.
+     * Prints the specified text to the specified PrintWriter.
      *
      * @param pw The printWriter to write the help to
      * @param width The number of characters to display per line


(commons-cli) 08/12: Make default constructor private

Posted by gg...@apache.org.
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 9aee5d941a9fe3177e3619870d05c404d1cef4ea
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 09:05:08 2024 -0400

    Make default constructor private
---
 src/main/java/org/apache/commons/cli/Util.java | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/main/java/org/apache/commons/cli/Util.java b/src/main/java/org/apache/commons/cli/Util.java
index f43b8c7..caf25bc 100644
--- a/src/main/java/org/apache/commons/cli/Util.java
+++ b/src/main/java/org/apache/commons/cli/Util.java
@@ -72,4 +72,8 @@ final class Util {
         }
         return str;
     }
+
+    private Util() {
+        // no instances
+    }
 }


(commons-cli) 01/12: Add missing test for the deprecated handler

Posted by gg...@apache.org.
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 d4610ab06b464b9ac1d74b1d595dd80455c0c0ec
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 08:50:26 2024 -0400

    Add missing test for the deprecated handler
---
 src/test/java/org/apache/commons/cli/CommandLineTest.java | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/CommandLineTest.java b/src/test/java/org/apache/commons/cli/CommandLineTest.java
index 861e736..49f146e 100644
--- a/src/test/java/org/apache/commons/cli/CommandLineTest.java
+++ b/src/test/java/org/apache/commons/cli/CommandLineTest.java
@@ -83,6 +83,20 @@ public class CommandLineTest {
         assertNull(handler.get());
     }
 
+    @Test
+    public void testDeprecatedDefaultOption() {
+        final CommandLine.Builder builder = new CommandLine.Builder();
+        builder.addArg("foo").addArg("bar");
+        final Option opt = Option.builder().option("T").deprecated().build();
+        builder.addOption(opt);
+        final AtomicReference<Option> handler = new AtomicReference<>();
+        final CommandLine cmd = builder.build();
+        cmd.getOptionValue(opt.getOpt());
+        handler.set(null);
+        cmd.getOptionValue("Nope");
+        assertNull(handler.get());
+    }
+
     @Test
     public void testGetOptionProperties() throws Exception {
         final String[] args = {"-Dparam1=value1", "-Dparam2=value2", "-Dparam3", "-Dparam4=value4", "-D", "--property", "foo=bar"};


(commons-cli) 11/12: Use assertThrows()

Posted by gg...@apache.org.
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 76c70a057583e3d9d5208c479b6cd04120c68105
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 09:11:54 2024 -0400

    Use assertThrows()
---
 .../java/org/apache/commons/cli/HelpFormatterTest.java   | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
index 97242a4..d23f943 100644
--- a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
+++ b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.cli;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.ByteArrayOutputStream;
@@ -349,19 +350,8 @@ public class HelpFormatterTest {
     @Test
     public void testPrintHelpWithEmptySyntax() {
         final HelpFormatter formatter = new HelpFormatter();
-        try {
-            formatter.printHelp(null, new Options());
-            fail("null command line syntax should be rejected");
-        } catch (final IllegalArgumentException e) {
-            // expected
-        }
-
-        try {
-            formatter.printHelp("", new Options());
-            fail("empty command line syntax should be rejected");
-        } catch (final IllegalArgumentException e) {
-            // expected
-        }
+        assertThrows(IllegalArgumentException.class, () -> formatter.printHelp(null, new Options()), "null command line syntax should be rejected");
+        assertThrows(IllegalArgumentException.class, () -> formatter.printHelp("", new Options()), "null command line syntax should be rejected");
     }
 
     @Test


(commons-cli) 07/12: Add missing API test

Posted by gg...@apache.org.
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 ee0f9111babdf079aea6441cdf28b7c41223192a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 09:00:20 2024 -0400

    Add missing API test
---
 src/test/java/org/apache/commons/cli/OptionTest.java | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java b/src/test/java/org/apache/commons/cli/OptionTest.java
index e496c8b..fe7caac 100644
--- a/src/test/java/org/apache/commons/cli/OptionTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionTest.java
@@ -220,6 +220,20 @@ public class OptionTest {
         assertEquals(2, b.getValues().length);
     }
 
+    @Test
+    public void testEquals() {
+        final Option option1a = new Option("1", null);
+        final Option option1b = new Option("1", null);
+        final Option option2 = new Option("2", null);
+        assertEquals(option1a, option1a);
+        assertEquals(option1a, option1b);
+        assertEquals(option1b, option1a);
+        assertNotEquals(option1a, option2);
+        assertNotEquals(option1b, option2);
+        assertNotEquals(option2, option1a);
+        assertNotEquals(option2, "");
+    }
+
     @Test
     public void testGetValue() {
         final Option option = new Option("f", null);


(commons-cli) 03/12: Add missing API test

Posted by gg...@apache.org.
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 248a6cf0fe4437a6ac9daba89c40640027bc1c76
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 08:52:05 2024 -0400

    Add missing API test
---
 src/test/java/org/apache/commons/cli/bug/BugsTest.java | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/bug/BugsTest.java b/src/test/java/org/apache/commons/cli/bug/BugsTest.java
index c8c2aa9..b4dd49f 100644
--- a/src/test/java/org/apache/commons/cli/bug/BugsTest.java
+++ b/src/test/java/org/apache/commons/cli/bug/BugsTest.java
@@ -134,6 +134,9 @@ public class BugsTest {
         // 1.7.0 API:
         cmd.getOptionValue(optionF, () -> "default f");
         cmd.getOptionValue(optionM, () -> "default m");
+        // 1.7.0 API:
+        cmd.getOptionValue('f', () -> "default f");
+        cmd.getOptionValue('m', () -> "default m");
         // 1.5.0 API:
         cmd.getOptionValue(optionF, "default f");
         cmd.getOptionValue(optionM, "default m");


(commons-cli) 06/12: Add missing test

Posted by gg...@apache.org.
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 9d09134743d794becb496f01c39b121e6e0fd40a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 8 08:57:13 2024 -0400

    Add missing test
---
 src/test/java/org/apache/commons/cli/OptionTest.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java b/src/test/java/org/apache/commons/cli/OptionTest.java
index a2328c7..e496c8b 100644
--- a/src/test/java/org/apache/commons/cli/OptionTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionTest.java
@@ -108,6 +108,7 @@ public class OptionTest {
     public void testAddValue() {
         final Option option = new Option("f", null);
         assertThrows(UnsupportedOperationException.class, () -> option.addValue(""));
+        assertThrows(IllegalArgumentException.class, () -> option.addValueForProcessing(""));
     }
 
     @Test