1919
2020import java .util .Arrays ;
2121import java .util .List ;
22+ import java .util .Properties ;
2223
2324import 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