Skip to content

Commit 0cebfb4

Browse files
committed
Added a test for the -Dflag case
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@779636 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3972aca commit 0cebfb4

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ public void setUp()
2929
parser = new BasicParser();
3030
}
3131

32-
public void testPropertiesOption() throws Exception
32+
public void testPropertiesOption1() throws Exception
3333
{
3434
// not supported by the BasicParser
3535
}
3636

37+
public void testPropertiesOption2() throws Exception
38+
{
39+
// not supported by the BasicParser
40+
}
41+
3742
public void testShortWithEqual() throws Exception
3843
{
3944
// not supported by the BasicParser

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.Arrays;
2121
import java.util.List;
22+
import java.util.Properties;
2223

2324
import junit.framework.TestCase;
2425

@@ -283,7 +284,7 @@ public void testLongWithEqualSingleDash() throws Exception
283284
assertEquals("bar", cl.getOptionValue("foo"));
284285
}
285286

286-
public void testPropertiesOption() throws Exception
287+
public void testPropertiesOption1() throws Exception
287288
{
288289
String[] args = new String[] { "-Jsource=1.5", "-J", "target", "1.5", "foo" };
289290

@@ -299,11 +300,31 @@ public void testPropertiesOption() throws Exception
299300
assertEquals("value 2", "1.5", values.get(1));
300301
assertEquals("value 3", "target", values.get(2));
301302
assertEquals("value 4", "1.5", values.get(3));
303+
302304
List argsleft = cl.getArgList();
303-
assertEquals("Should be 1 arg left",1,argsleft.size());
304-
assertEquals("Expecting foo","foo",argsleft.get(0));
305+
assertEquals("Should be 1 arg left", 1, argsleft.size());
306+
assertEquals("Expecting foo", "foo", argsleft.get(0));
305307
}
306-
308+
309+
public void testPropertiesOption2() throws Exception
310+
{
311+
String[] args = new String[] { "-Dparam1", "-Dparam2=value2", "-D"};
312+
313+
Options options = new Options();
314+
options.addOption(OptionBuilder.withValueSeparator().hasOptionalArgs(2).create('D'));
315+
316+
CommandLine cl = parser.parse(options, args);
317+
318+
Properties props = cl.getOptionProperties("D");
319+
assertNotNull("null properties", props);
320+
assertEquals("number of properties in " + props, 2, props.size());
321+
assertEquals("property 1", "true", props.getProperty("param1"));
322+
assertEquals("property 2", "value2", props.getProperty("param2"));
323+
324+
List argsleft = cl.getArgList();
325+
assertEquals("Should be no arg left", 0, argsleft.size());
326+
}
327+
307328
public void testUnambiguousPartialLongOption1() throws Exception
308329
{
309330
String[] args = new String[] { "--ver" };

0 commit comments

Comments
 (0)