commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r661726 - /commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java
Date Fri, 30 May 2008 14:11:33 GMT
Author: ebourg
Date: Fri May 30 07:11:32 2008
New Revision: 661726

URL: http://svn.apache.org/viewvc?rev=661726&view=rev
Log:
More tests for the Option class covering the hasArgs, hasArgName and getValue methods

Modified:
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java?rev=661726&r1=661725&r2=661726&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java Fri
May 30 07:11:32 2008
@@ -22,29 +22,35 @@
 /**
  * @author brianegge
  */
-public class OptionTest extends TestCase {
-
-   private static class TestOption extends Option {
-        public TestOption(String opt, boolean hasArg, String description) throws IllegalArgumentException
{
+public class OptionTest extends TestCase
+{
+    private static class TestOption extends Option
+    {
+        public TestOption(String opt, boolean hasArg, String description) throws IllegalArgumentException
+        {
             super(opt, hasArg, description);
         }
-        public boolean addValue(String value) {
+
+        public boolean addValue(String value)
+        {
             addValueForProcessing(value);
             return true;
         }
-   }
+    }
 
-   public void testClear() {
-       TestOption option = new TestOption("x", true, "");
-       assertEquals(0, option.getValuesList().size());
-       option.addValue("a");
-       assertEquals(1, option.getValuesList().size());
-       option.clearValues();
-       assertEquals(0, option.getValuesList().size());
-   }
+    public void testClear()
+    {
+        TestOption option = new TestOption("x", true, "");
+        assertEquals(0, option.getValuesList().size());
+        option.addValue("a");
+        assertEquals(1, option.getValuesList().size());
+        option.clearValues();
+        assertEquals(0, option.getValuesList().size());
+    }
 
     // See http://issues.apache.org/jira/browse/CLI-21
-    public void testClone() throws CloneNotSupportedException {
+    public void testClone() throws CloneNotSupportedException
+    {
         TestOption a = new TestOption("a", true, "");
         TestOption b = (TestOption) a.clone();
         assertEquals(a, b);
@@ -59,25 +65,76 @@
         assertEquals(2, b.getValues().length);
     }
 
-    private static class DefaultOption extends Option {
-
+    private static class DefaultOption extends Option
+    {
         private final String defaultValue;
 
-        public DefaultOption(String opt, String description, String defaultValue) throws
IllegalArgumentException {
+        public DefaultOption(String opt, String description, String defaultValue) throws
IllegalArgumentException
+        {
             super(opt, true, description);
             this.defaultValue = defaultValue;
         }
 
-        public String getValue() {
+        public String getValue()
+        {
             return super.getValue() != null ? super.getValue() : defaultValue;
         }
     }
 
-    public void testSubclass() throws CloneNotSupportedException {
+    public void testSubclass() throws CloneNotSupportedException
+    {
         Option option = new DefaultOption("f", "file", "myfile.txt");
         Option clone = (Option) option.clone();
         assertEquals("myfile.txt", clone.getValue());
         assertEquals(DefaultOption.class, clone.getClass());
     }
 
+    public void testHasArgName()
+    {
+        Option option = new Option("f", null);
+
+        option.setArgName(null);
+        assertFalse(option.hasArgName());
+
+        option.setArgName("");
+        assertFalse(option.hasArgName());
+
+        option.setArgName("file");
+        assertTrue(option.hasArgName());
+    }
+
+    public void testHasArgs()
+    {
+        Option option = new Option("f", null);
+
+        option.setArgs(0);
+        assertFalse(option.hasArgs());
+
+        option.setArgs(1);
+        assertFalse(option.hasArgs());
+
+        option.setArgs(10);
+        assertTrue(option.hasArgs());
+
+        option.setArgs(Option.UNLIMITED_VALUES);
+        assertTrue(option.hasArgs());
+
+        option.setArgs(Option.UNINITIALIZED);
+        assertFalse(option.hasArgs());
+    }
+
+    public void testGetValue()
+    {
+        Option option = new Option("f", null);
+        option.setArgs(Option.UNLIMITED_VALUES);
+
+        assertEquals("default", option.getValue("default"));
+        assertEquals(null, option.getValue(0));
+
+        option.addValueForProcessing("foo");
+        
+        assertEquals("foo", option.getValue());
+        assertEquals("foo", option.getValue(0));
+        assertEquals("foo", option.getValue("default"));
+    }
 }



Mime
View raw message