commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r779636 - in /commons/proper/cli/trunk/src/test/org/apache/commons/cli: BasicParserTest.java ParserTestCase.java
Date Thu, 28 May 2009 15:57:50 GMT
Author: ebourg
Date: Thu May 28 15:57:49 2009
New Revision: 779636

URL: http://svn.apache.org/viewvc?rev=779636&view=rev
Log:
Added a test for the -Dflag case

Modified:
    commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java
    commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java?rev=779636&r1=779635&r2=779636&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java Thu May
28 15:57:49 2009
@@ -29,11 +29,16 @@
         parser = new BasicParser();
     }
 
-    public void testPropertiesOption() throws Exception
+    public void testPropertiesOption1() throws Exception
     {
         // not supported by the BasicParser
     }
 
+    public void testPropertiesOption2() throws Exception
+    {
+        // not supported by the BasicParser
+    }    
+
     public void testShortWithEqual() throws Exception
     {
         // not supported by the BasicParser

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java?rev=779636&r1=779635&r2=779636&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java Thu May 28
15:57:49 2009
@@ -19,6 +19,7 @@
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Properties;
 
 import junit.framework.TestCase;
 
@@ -283,7 +284,7 @@
         assertEquals("bar", cl.getOptionValue("foo"));
     }
 
-    public void testPropertiesOption() throws Exception
+    public void testPropertiesOption1() throws Exception
     {
         String[] args = new String[] { "-Jsource=1.5", "-J", "target", "1.5", "foo" };
 
@@ -299,11 +300,31 @@
         assertEquals("value 2", "1.5", values.get(1));
         assertEquals("value 3", "target", values.get(2));
         assertEquals("value 4", "1.5", values.get(3));
+        
         List argsleft = cl.getArgList();
-        assertEquals("Should be 1 arg left",1,argsleft.size());
-        assertEquals("Expecting foo","foo",argsleft.get(0));
+        assertEquals("Should be 1 arg left", 1, argsleft.size());
+        assertEquals("Expecting foo", "foo", argsleft.get(0));
     }
-    
+
+    public void testPropertiesOption2() throws Exception
+    {
+        String[] args = new String[] { "-Dparam1", "-Dparam2=value2", "-D"};
+
+        Options options = new Options();
+        options.addOption(OptionBuilder.withValueSeparator().hasOptionalArgs(2).create('D'));
+
+        CommandLine cl = parser.parse(options, args);
+        
+        Properties props = cl.getOptionProperties("D");
+        assertNotNull("null properties", props);
+        assertEquals("number of properties in " + props, 2, props.size());
+        assertEquals("property 1", "true", props.getProperty("param1"));
+        assertEquals("property 2", "value2", props.getProperty("param2"));
+        
+        List argsleft = cl.getArgList();
+        assertEquals("Should be no arg left", 0, argsleft.size());
+    }
+
     public void testUnambiguousPartialLongOption1() throws Exception
     {
         String[] args = new String[] { "--ver" };



Mime
View raw message