Skip to content

Commit 5397278

Browse files
committed
Use better JRE API
1 parent 8893bc2 commit 5397278

5 files changed

Lines changed: 13 additions & 20 deletions

File tree

src/main/java/org/apache/commons/cli/HelpFormatter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ public int compare(final Option opt1, final Option opt2) {
148148
public String defaultSyntaxPrefix = DEFAULT_SYNTAX_PREFIX;
149149

150150
/**
151-
* the new line string
152-
*
153-
* @deprecated Scope will be made private for next major version - use get/setNewLine methods instead.
154-
*/
151+
* the new line string
152+
*
153+
* @deprecated Scope will be made private for next major version - use get/setNewLine methods instead.
154+
*/
155155
@Deprecated
156-
public String defaultNewLine = System.getProperty("line.separator");
156+
public String defaultNewLine = System.lineSeparator();
157157

158158
/**
159159
* the shortOpt prefix

src/test/java/org/apache/commons/cli/AbstractParserTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public void testOptionAndRequiredOption() throws Exception {
486486
assertEquals("Confirm arg of -b", "file", cl.getOptionValue("b"));
487487
assertTrue("Confirm NO of extra args", cl.getArgList().isEmpty());
488488
}
489-
489+
490490
@Test
491491
public void testOptionGroup() throws Exception {
492492
final OptionGroup group = new OptionGroup();
@@ -1021,12 +1021,12 @@ public void testWithRequiredOption() throws Exception {
10211021
assertEquals("Confirm arg of -b", "file", cl.getOptionValue("b"));
10221022
assertTrue("Confirm NO of extra args", cl.getArgList().isEmpty());
10231023
}
1024-
1024+
10251025
@Test(expected = UnrecognizedOptionException.class)
10261026
public void testAmbiguousArgParsing() throws Exception {
10271027
final String[] args = {"-=-"};
10281028
final Options options = new Options();
1029-
1029+
10301030
final CommandLine cl = parser.parse(options, args);
10311031
}
10321032
}

src/test/java/org/apache/commons/cli/ApplicationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void testMan() {
227227
//@formatter:on
228228

229229
final HelpFormatter hf = new HelpFormatter();
230-
final String eol = System.getProperty("line.separator");
230+
final String eol = System.lineSeparator();
231231
final StringWriter out = new StringWriter();
232232
hf.printHelp(new PrintWriter(out), 60, cmdLine, null, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
233233
//@formatter:off

src/test/java/org/apache/commons/cli/HelpFormatterTest.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2424
import java.io.ByteArrayOutputStream;
2525
import java.io.PrintWriter;
2626
import java.io.StringWriter;
27-
import java.util.Comparator;
2827

2928
import org.junit.Test;
3029

3130
/**
3231
* Test case for the HelpFormatter class.
3332
*/
3433
public class HelpFormatterTest {
35-
private static final String EOL = System.getProperty("line.separator");
34+
private static final String EOL = System.lineSeparator();
3635

3736
@Test
3837
public void testAccessors() {
@@ -271,7 +270,7 @@ public void testOptionWithoutShortFormat2() {
271270
mOptions.addOption(configFile);
272271

273272
final HelpFormatter formatter = new HelpFormatter();
274-
final String eol = System.getProperty("line.separator");
273+
final String eol = System.lineSeparator();
275274
final StringWriter out = new StringWriter();
276275
formatter.printHelp(new PrintWriter(out), 80, "commandline", "header", mOptions, 2, 2, "footer", true);
277276
//@formatter:off
@@ -470,13 +469,7 @@ public void testPrintSortedUsage() {
470469
opts.addOption(new Option("c", "third"));
471470

472471
final HelpFormatter helpFormatter = new HelpFormatter();
473-
helpFormatter.setOptionComparator(new Comparator<Option>() {
474-
@Override
475-
public int compare(final Option opt1, final Option opt2) {
476-
// reverses the functionality of the default comparator
477-
return opt2.getKey().compareToIgnoreCase(opt1.getKey());
478-
}
479-
});
472+
helpFormatter.setOptionComparator((opt1, opt2) -> opt2.getKey().compareToIgnoreCase(opt1.getKey()));
480473

481474
final StringWriter out = new StringWriter();
482475
helpFormatter.printUsage(new PrintWriter(out), 80, "app", opts);

src/test/java/org/apache/commons/cli/bug/BugCLI162Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
public class BugCLI162Test {
3535
/** Constant for the line separator. */
36-
private static final String CR = System.getProperty("line.separator");
36+
private static final String CR = System.lineSeparator();
3737

3838
// Constants used for options
3939
private static final String OPT = "-";

0 commit comments

Comments
 (0)