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 5397278 Use better JRE API
5397278 is described below
commit 53972781993e79eb48f17cb67ac463ba7f1bc4c8
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Sep 15 17:45:14 2023 -0400
Use better JRE API
---
src/main/java/org/apache/commons/cli/HelpFormatter.java | 10 +++++-----
.../java/org/apache/commons/cli/AbstractParserTestCase.java | 6 +++---
src/test/java/org/apache/commons/cli/ApplicationTest.java | 2 +-
src/test/java/org/apache/commons/cli/HelpFormatterTest.java | 13 +++----------
src/test/java/org/apache/commons/cli/bug/BugCLI162Test.java | 2 +-
5 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/src/main/java/org/apache/commons/cli/HelpFormatter.java
b/src/main/java/org/apache/commons/cli/HelpFormatter.java
index b8ef670..7a1b790 100644
--- a/src/main/java/org/apache/commons/cli/HelpFormatter.java
+++ b/src/main/java/org/apache/commons/cli/HelpFormatter.java
@@ -148,12 +148,12 @@ public class HelpFormatter {
public String defaultSyntaxPrefix = DEFAULT_SYNTAX_PREFIX;
/**
- * the new line string
- *
- * @deprecated Scope will be made private for next major version - use
get/setNewLine methods instead.
- */
+ * the new line string
+ *
+ * @deprecated Scope will be made private for next major version - use
get/setNewLine methods instead.
+ */
@Deprecated
- public String defaultNewLine = System.getProperty("line.separator");
+ public String defaultNewLine = System.lineSeparator();
/**
* the shortOpt prefix
diff --git a/src/test/java/org/apache/commons/cli/AbstractParserTestCase.java
b/src/test/java/org/apache/commons/cli/AbstractParserTestCase.java
index 36affcc..bb99237 100644
--- a/src/test/java/org/apache/commons/cli/AbstractParserTestCase.java
+++ b/src/test/java/org/apache/commons/cli/AbstractParserTestCase.java
@@ -486,7 +486,7 @@ public abstract class AbstractParserTestCase {
assertEquals("Confirm arg of -b", "file", cl.getOptionValue("b"));
assertTrue("Confirm NO of extra args", cl.getArgList().isEmpty());
}
-
+
@Test
public void testOptionGroup() throws Exception {
final OptionGroup group = new OptionGroup();
@@ -1021,12 +1021,12 @@ public abstract class AbstractParserTestCase {
assertEquals("Confirm arg of -b", "file", cl.getOptionValue("b"));
assertTrue("Confirm NO of extra args", cl.getArgList().isEmpty());
}
-
+
@Test(expected = UnrecognizedOptionException.class)
public void testAmbiguousArgParsing() throws Exception {
final String[] args = {"-=-"};
final Options options = new Options();
-
+
final CommandLine cl = parser.parse(options, args);
}
}
diff --git a/src/test/java/org/apache/commons/cli/ApplicationTest.java
b/src/test/java/org/apache/commons/cli/ApplicationTest.java
index 32079c7..952d36e 100644
--- a/src/test/java/org/apache/commons/cli/ApplicationTest.java
+++ b/src/test/java/org/apache/commons/cli/ApplicationTest.java
@@ -227,7 +227,7 @@ public class ApplicationTest {
//@formatter:on
final HelpFormatter hf = new HelpFormatter();
- final String eol = System.getProperty("line.separator");
+ final String eol = System.lineSeparator();
final StringWriter out = new StringWriter();
hf.printHelp(new PrintWriter(out), 60, cmdLine, null, options,
HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
//@formatter:off
diff --git a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
index abeb432..5c9264e 100644
--- a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
+++ b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.util.Comparator;
import org.junit.Test;
@@ -32,7 +31,7 @@ import org.junit.Test;
* Test case for the HelpFormatter class.
*/
public class HelpFormatterTest {
- private static final String EOL = System.getProperty("line.separator");
+ private static final String EOL = System.lineSeparator();
@Test
public void testAccessors() {
@@ -271,7 +270,7 @@ public class HelpFormatterTest {
mOptions.addOption(configFile);
final HelpFormatter formatter = new HelpFormatter();
- final String eol = System.getProperty("line.separator");
+ final String eol = System.lineSeparator();
final StringWriter out = new StringWriter();
formatter.printHelp(new PrintWriter(out), 80, "commandline", "header",
mOptions, 2, 2, "footer", true);
//@formatter:off
@@ -470,13 +469,7 @@ public class HelpFormatterTest {
opts.addOption(new Option("c", "third"));
final HelpFormatter helpFormatter = new HelpFormatter();
- helpFormatter.setOptionComparator(new Comparator<Option>() {
- @Override
- public int compare(final Option opt1, final Option opt2) {
- // reverses the functionality of the default comparator
- return opt2.getKey().compareToIgnoreCase(opt1.getKey());
- }
- });
+ helpFormatter.setOptionComparator((opt1, opt2) ->
opt2.getKey().compareToIgnoreCase(opt1.getKey()));
final StringWriter out = new StringWriter();
helpFormatter.printUsage(new PrintWriter(out), 80, "app", opts);
diff --git a/src/test/java/org/apache/commons/cli/bug/BugCLI162Test.java
b/src/test/java/org/apache/commons/cli/bug/BugCLI162Test.java
index 3123d90..db37aac 100644
--- a/src/test/java/org/apache/commons/cli/bug/BugCLI162Test.java
+++ b/src/test/java/org/apache/commons/cli/bug/BugCLI162Test.java
@@ -33,7 +33,7 @@ import org.junit.Test;
public class BugCLI162Test {
/** Constant for the line separator. */
- private static final String CR = System.getProperty("line.separator");
+ private static final String CR = System.lineSeparator();
// Constants used for options
private static final String OPT = "-";