Skip to content

Commit 7e8c875

Browse files
committed
More tests
1 parent 50b9c7e commit 7e8c875

9 files changed

Lines changed: 126 additions & 101 deletions

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3535

3636
/**
3737
* Abstract test case testing common parser features.
38+
*
39+
* TODO Needs a rework using JUnit parameterized tests.
3840
*/
3941
public abstract class AbstractParserTestCase {
4042

@@ -499,6 +501,9 @@ public void testOptionalArgsOptionDotBuilder() throws Exception {
499501
assertTrue(cmd.hasOption("i"));
500502
assertArrayEquals(new String[] { "paper", "scissors" }, cmd.getOptionValues("i"));
501503
assertArrayEquals(new String[] { "rock" }, cmd.getArgs());
504+
505+
options.addOption(Option.builder("j").numberOfArgs(3).optionalArg(true).build());
506+
cmd = parse(parser, options, new String[] { "-j" }, properties);
502507
}
503508

504509
@Test

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2121
import org.junit.jupiter.api.Disabled;
2222
import org.junit.jupiter.api.Test;
2323

24+
/**
25+
* TODO Needs a rework using JUnit parameterized tests.
26+
*/
2427
@SuppressWarnings("deprecation") // tests some deprecated classes
2528
public class BasicParserTest extends AbstractParserTestCase {
2629
@Override

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,29 @@ public void testBuilderNullOption() {
6969
}
7070

7171
@Test
72-
public void testDeprecatedOption() {
72+
public void testDeprecatedDefaultOption() {
7373
final CommandLine.Builder builder = new CommandLine.Builder();
7474
builder.addArg("foo").addArg("bar");
7575
final Option opt = Option.builder().option("T").deprecated().build();
7676
builder.addOption(opt);
7777
final AtomicReference<Option> handler = new AtomicReference<>();
78-
final CommandLine cmd = builder.setDeprecatedHandler(handler::set).build();
78+
final CommandLine cmd = builder.build();
7979
cmd.getOptionValue(opt.getOpt());
80-
assertSame(opt, handler.get());
8180
handler.set(null);
8281
cmd.getOptionValue("Nope");
8382
assertNull(handler.get());
8483
}
8584

8685
@Test
87-
public void testDeprecatedDefaultOption() {
86+
public void testDeprecatedOption() {
8887
final CommandLine.Builder builder = new CommandLine.Builder();
8988
builder.addArg("foo").addArg("bar");
9089
final Option opt = Option.builder().option("T").deprecated().build();
9190
builder.addOption(opt);
9291
final AtomicReference<Option> handler = new AtomicReference<>();
93-
final CommandLine cmd = builder.build();
92+
final CommandLine cmd = builder.setDeprecatedHandler(handler::set).build();
9493
cmd.getOptionValue(opt.getOpt());
94+
assertSame(opt, handler.get());
9595
handler.set(null);
9696
cmd.getOptionValue("Nope");
9797
assertNull(handler.get());

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2727
import org.junit.jupiter.api.BeforeEach;
2828
import org.junit.jupiter.api.Test;
2929

30+
/**
31+
* TODO Needs a rework using JUnit parameterized tests.
32+
*/
3033
public class DefaultParserTest extends AbstractParserTestCase {
3134

3235
@Override

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2121
import org.junit.jupiter.api.Disabled;
2222
import org.junit.jupiter.api.Test;
2323

24+
/**
25+
* TODO Needs a rework using JUnit parameterized tests.
26+
*/
2427
@SuppressWarnings("deprecation") // tests some deprecated classes
2528
public class GnuParserTest extends AbstractParserTestCase {
2629
@Override

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2323

2424
/**
2525
* Test case for the PosixParser.
26+
*
27+
* TODO Needs a rework using JUnit parameterized tests.
2628
*/
2729
public class PosixParserTest extends AbstractParserTestCase {
2830
@Override

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ public void testCreateFile() {
186186
assertEquals(file, TypeHandler.createFile(file.toString()));
187187
}
188188

189-
@Test
190-
public void testOpenFile() throws ParseException, IOException {
191-
try (FileInputStream fis = TypeHandler.openFile("src/test/resources/org/apache/commons/cli/existing-readable.file")) {
192-
IOUtils.consume(fis);
193-
}
194-
}
195-
196189
@Test
197190
public void testCreateFiles() {
198191
assertThrows(UnsupportedOperationException.class, () -> TypeHandler.createFiles(null));
@@ -220,7 +213,7 @@ public void testCreateURL() throws ParseException, MalformedURLException {
220213
@MethodSource("createValueTestParameters")
221214
public void testCreateValue(final String str, final Class<?> type, final Object expected) throws Exception {
222215
@SuppressWarnings("cast")
223-
final Object objectApiTest = (Object) type; // KEEP this cast
216+
final Object objectApiTest = type; // KEEP this cast
224217
if (expected instanceof Class<?> && Throwable.class.isAssignableFrom((Class<?>) expected)) {
225218
assertThrows((Class<Throwable>) expected, () -> TypeHandler.createValue(str, type));
226219
assertThrows((Class<Throwable>) expected, () -> TypeHandler.createValue(str, objectApiTest));
@@ -244,6 +237,13 @@ public void testnstantiableEquals() {
244237
assertEquals(new Instantiable(), new Instantiable());
245238
}
246239

240+
@Test
241+
public void testOpenFile() throws ParseException, IOException {
242+
try (FileInputStream fis = TypeHandler.openFile("src/test/resources/org/apache/commons/cli/existing-readable.file")) {
243+
IOUtils.consume(fis);
244+
}
245+
}
246+
247247
@Test
248248
public void testRegister() {
249249
final Map<Class<?>, Converter<?, ? extends Throwable>> map = TypeHandler.createDefaultMap();

0 commit comments

Comments
 (0)