commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject svn commit: r280580 - in /jakarta/commons/proper/cli/trunk/src: java/org/apache/commons/cli2/option/Switch.java test/org/apache/commons/cli2/option/SwitchTest.java
Date Tue, 13 Sep 2005 15:57:22 GMT
Author: jkeyes
Date: Tue Sep 13 08:57:07 2005
New Revision: 280580

URL: http://svn.apache.org/viewcvs?rev=280580&view=rev
Log:
- improved code coverage

Modified:
    jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/Switch.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/Switch.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/Switch.java?rev=280580&r1=280579&r2=280580&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/Switch.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/Switch.java Tue
Sep 13 08:57:07 2005
@@ -89,15 +89,15 @@
         }
 
         if (disabledPrefix == null) {
-            throw new IllegalArgumentException(ResourceConstants.SWITCH_NO_DISABLED_PREFIX);
+            throw new IllegalArgumentException(resources.getMessage(ResourceConstants.SWITCH_NO_DISABLED_PREFIX));
         }
 
         if (enabledPrefix.startsWith(disabledPrefix)) {
-            throw new IllegalArgumentException(ResourceConstants.SWITCH_ENABLED_STARTS_WITH_DISABLED);
+            throw new IllegalArgumentException(resources.getMessage(ResourceConstants.SWITCH_ENABLED_STARTS_WITH_DISABLED));
         }
 
         if (disabledPrefix.startsWith(enabledPrefix)) {
-            throw new IllegalArgumentException(ResourceConstants.SWITCH_DISABLED_STARTWS_WITH_ENABLED);
+            throw new IllegalArgumentException(resources.getMessage(ResourceConstants.SWITCH_DISABLED_STARTWS_WITH_ENABLED));
         }
 
         this.enabledPrefix = enabledPrefix;
@@ -105,7 +105,7 @@
         this.preferredName = preferredName;
 
         if ((preferredName == null) || (preferredName.length() < 1)) {
-            throw new IllegalArgumentException(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT);
+            throw new IllegalArgumentException(resources.getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT));
         }
 
         final Set newTriggers = new HashSet();

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java?rev=280580&r1=280579&r2=280580&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java
(original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java
Tue Sep 13 08:57:07 2005
@@ -26,38 +26,33 @@
 import org.apache.commons.cli2.Parent;
 import org.apache.commons.cli2.WriteableCommandLine;
 import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
 
 /**
  * @author Rob Oxspring
- * 
+ *
  * To change the template for this generated type comment go to
  * Window>Preferences>Java>Code Generation>Code and Comments
  */
-public class SwitchTest extends ParentTestCase {
-
+public class SwitchTest
+    extends ParentTestCase {
     public static Switch buildDisplaySwitch() {
         final Set aliases = new HashSet();
         aliases.add("d");
         aliases.add("disp");
-        return new Switch(
-            "+",
-            "-",
-            "display",
-            aliases,
-            "Sets whether to display to screen",
-            true,
-            null,
-            null,
-            'd',
-            null);
+
+        return new Switch("+", "-", "display", aliases, "Sets whether to display to screen",
true,
+                          null, null, 'd', null);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.ParentTestCase#testProcessParent()
      */
-    public void testProcessParent() throws OptionException {
+    public void testProcessParent()
+        throws OptionException {
         final Switch option = buildDisplaySwitch();
         final List args = list("+d");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -72,7 +67,8 @@
         assertTrue(commandLine.getValues(option).isEmpty());
     }
 
-    public void testProcessParent_Disabled() throws OptionException {
+    public void testProcessParent_Disabled()
+        throws OptionException {
         final Switch option = buildDisplaySwitch();
         final List args = list("-disp");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -89,22 +85,22 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testCanProcess()
      */
     public void testCanProcess() {
         final Switch option = buildDisplaySwitch();
-        assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null),"+d"));
+        assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "+d"));
     }
 
     public void testCanProcess_BadMatch() {
         final Switch option = buildDisplaySwitch();
-        assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null),"-dont"));
+        assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), "-dont"));
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testPrefixes()
      */
     public void testPrefixes() {
@@ -114,29 +110,27 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testProcess()
      */
     public void testProcess() {
         // TODO Auto-generated method stub
-
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testTriggers()
      */
     public void testTriggers() {
         final Switch option = buildDisplaySwitch();
-        assertContentsEqual(
-            list("-d", "+d", "-disp", "+disp", "+display", "-display"),
-            option.getTriggers());
+        assertContentsEqual(list("-d", "+d", "-disp", "+disp", "+display", "-display"),
+                            option.getTriggers());
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testValidate()
      */
     public void testValidate() {
@@ -146,15 +140,14 @@
         try {
             option.validate(commandLine);
             fail("Missing an option");
-        }
-        catch (OptionException moe) {
+        } catch (OptionException moe) {
             assertSame(option, moe.getOption());
         }
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage()
      */
     public void testAppendUsage() {
@@ -162,9 +155,7 @@
         final StringBuffer buffer = new StringBuffer();
         option.appendUsage(buffer, DisplaySetting.ALL, null);
 
-        assertEquals(
-            "+display|-display (+d|-d,+disp|-disp)",
-            buffer.toString());
+        assertEquals("+display|-display (+d|-d,+disp|-disp)", buffer.toString());
     }
 
     public void testAppendUsage_NoAlias() {
@@ -210,7 +201,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName()
      */
     public void testGetPreferredName() {
@@ -220,22 +211,97 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetDescription()
      */
     public void testGetDescription() {
         final Option option = buildDisplaySwitch();
-        assertEquals(
-            "Sets whether to display to screen",
-            option.getDescription());
+        assertEquals("Sets whether to display to screen", option.getDescription());
+    }
+
+    public void testNullPreferredName() {
+        try {
+            new Switch("+", "-", null, null, "Sets whether to display to screen", true, null,
null,
+                       'd', null);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT),
+                         exp.getMessage());
+        }
+    }
+
+    public void testEmptyPreferredName() {
+        try {
+            new Switch("+", "-", "", null, "Sets whether to display to screen", true, null,
null,
+                       'd', null);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT),
+                         exp.getMessage());
+        }
+    }
+
+    public void testNullAliases() {
+        try {
+            new Switch("+", "-", "display", null, "Sets whether to display to screen", true,
null,
+                       null, 'd', null);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT),
+                         exp.getMessage());
+        }
+    }
+
+    public void testNullEnablePrefix() {
+        try {
+            new Switch(null, "-", "display", null, "Sets whether to display to screen", true,
null,
+                       null, 'd', null);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_ENABLED_PREFIX),
+                         exp.getMessage());
+        }
     }
+
+    public void testNullDisablePrefix() {
+        try {
+            new Switch("+", null, "display", null, "Sets whether to display to screen", true,
null,
+                       null, 'd', null);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_DISABLED_PREFIX),
+                         exp.getMessage());
+        }
+    }
+
+    public void testEnabledPrefixStartsWithDisabledPrefix() {
+        try {
+            new Switch("-", "-", "display", null, "Sets whether to display to screen", true,
null,
+                       null, 'd', null);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_ENABLED_STARTS_WITH_DISABLED),
+                         exp.getMessage());
+        }
+    }
+
+    public void testDisabledPrefixStartsWithEnabledPrefix() {
+        try {
+            new Switch("o", "on", "display", null, "Sets whether to display to screen", true,
null,
+                       null, 'd', null);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_DISABLED_STARTWS_WITH_ENABLED),
+                         exp.getMessage());
+        }
+    }
+
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testHelpLines()
      */
     public void testHelpLines() {
         // TODO Auto-generated method stub
-
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message