Skip to content

Commit 859d5e5

Browse files
committed
[CLI-343] OptionFormatter.getBothOpt() lacks validation for Options
without opt or longOpt Add tests
1 parent ea9e408 commit 859d5e5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1717
package org.apache.commons.cli.help;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2021

2122
import java.util.ArrayList;
2223
import java.util.List;
@@ -132,6 +133,18 @@ void testAsSyntaxOption() {
132133
assertEquals("[-ot <arg>]", underTest.toSyntaxOption(), "optional multi char opt arg failed");
133134
}
134135

136+
@Test
137+
void testCli343Part1() {
138+
assertThrows(IllegalStateException.class, () -> Option.builder().required(false).build());
139+
assertThrows(IllegalStateException.class, () -> Option.builder().required(false).get());
140+
}
141+
142+
@Test
143+
void testCli343Part2() {
144+
assertThrows(IllegalStateException.class, () -> Option.builder().desc("description").build());
145+
assertThrows(IllegalStateException.class, () -> Option.builder().desc("description").get());
146+
}
147+
135148
@ParameterizedTest(name = "{index} {0}")
136149
@MethodSource("deprecatedAttributesData")
137150
void testComplexDeprecationFormat(final DeprecatedAttributes da, final String expected) {

0 commit comments

Comments
 (0)