You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2005/09/13 17:35:46 UTC

svn commit: r280577 [1/2] - in /jakarta/commons/proper/cli/trunk/src: java/org/apache/commons/cli2/option/ java/org/apache/commons/cli2/validation/ test/org/apache/commons/cli2/commandline/ test/org/apache/commons/cli2/option/ test/org/apache/commons/c...

Author: jkeyes
Date: Tue Sep 13 08:35:24 2005
New Revision: 280577

URL: http://svn.apache.org/viewcvs?rev=280577&view=rev
Log:
- improved code coverage
- added leniant date parsing to DateValidator

Modified:
    jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java
    jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/GroupImpl.java
    jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java
    jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/DateValidator.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/CommandTest.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTest.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTestCase.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTest.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java Tue Sep 13 08:35:24 2005
@@ -15,8 +15,10 @@
  */
 package org.apache.commons.cli2.option;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Set;
@@ -335,13 +337,7 @@
             return token;
         }
 
-        if (token.startsWith("\"")) {
-            token = token.substring(1, token.length());
-        }
-
-        if (token.endsWith("\"")) {
-            token = token.substring(0, token.length() - 1);
-        }
+        token = token.substring(1, token.length() - 1);
 
         return token;
     }

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/GroupImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/GroupImpl.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/GroupImpl.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/GroupImpl.java Tue Sep 13 08:35:24 2005
@@ -110,7 +110,7 @@
     }
 
     public boolean canProcess(final WriteableCommandLine commandLine,
-                              String arg) {
+                              final String arg) {
         if (arg == null) {
             return false;
         }

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java Tue Sep 13 08:35:24 2005
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright 2003-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,23 +34,19 @@
  * A base implementation of Parent providing limited ground work for further
  * Parent implementations.
  */
-public abstract class ParentImpl extends OptionImpl implements Parent {
-
+public abstract class ParentImpl
+    extends OptionImpl implements Parent {
     private static final char NUL = '\0';
-    
     private final Group children;
-
     private final Argument argument;
-
     private final String description;
 
-    protected ParentImpl(
-        final Argument argument,
-        final Group children,
-        final String description,
-        final int id,
-        final boolean required) {
-        super(id,required);
+    protected ParentImpl(final Argument argument,
+                         final Group children,
+                         final String description,
+                         final int id,
+                         final boolean required) {
+        super(id, required);
         this.children = children;
         this.argument = argument;
         this.description = description;
@@ -58,15 +54,13 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.Option#process(org.apache.commons.cli2.CommandLine,
      *      java.util.ListIterator)
      */
-    public void process(
-        final WriteableCommandLine commandLine,
-        final ListIterator arguments)
+    public void process(final WriteableCommandLine commandLine,
+                        final ListIterator arguments)
         throws OptionException {
-
         if (argument != null) {
             handleInitialSeparator(arguments, argument.getInitialSeparator());
         }
@@ -77,51 +71,49 @@
             argument.processValues(commandLine, arguments, this);
         }
 
-        if (children != null && children.canProcess(commandLine, arguments)) {
+        if ((children != null) && children.canProcess(commandLine, arguments)) {
             children.process(commandLine, arguments);
         }
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.Option#canProcess(java.lang.String)
      */
-    public boolean canProcess(final WriteableCommandLine commandLine, final String arg) {
-
+    public boolean canProcess(final WriteableCommandLine commandLine,
+                              final String arg) {
         final Set triggers = getTriggers();
-        
+
         if (argument != null) {
             final char separator = argument.getInitialSeparator();
-            
+
             // if there is a valid separator character
             if (separator != NUL) {
                 final int initialIndex = arg.indexOf(separator);
-                
+
                 // if there is a separator present
                 if (initialIndex > 0) {
                     return triggers.contains(arg.substring(0, initialIndex));
                 }
             }
         }
-        
+
         return triggers.contains(arg);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.Option#prefixes()
      */
     public Set getPrefixes() {
-        return (children == null)
-            ? Collections.EMPTY_SET
-            : children.getPrefixes();
+        return (children == null) ? Collections.EMPTY_SET : children.getPrefixes();
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.Option#validate(org.apache.commons.cli2.CommandLine)
      */
     public void validate(WriteableCommandLine commandLine)
@@ -139,21 +131,19 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.Option#appendUsage(java.lang.StringBuffer,
      *      java.util.Set, java.util.Comparator)
      */
-    public void appendUsage(
-        final StringBuffer buffer,
-        final Set helpSettings,
-        final Comparator comp) {
-
+    public void appendUsage(final StringBuffer buffer,
+                            final Set helpSettings,
+                            final Comparator comp) {
         final boolean displayArgument =
-            this.argument != null
-                && helpSettings.contains(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
+            (this.argument != null) &&
+            helpSettings.contains(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
         final boolean displayChildren =
-            this.children != null
-                && helpSettings.contains(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+            (this.children != null) &&
+            helpSettings.contains(DisplaySetting.DISPLAY_PARENT_CHILDREN);
 
         if (displayArgument) {
             buffer.append(' ');
@@ -175,24 +165,21 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.Option#helpLines(int, java.util.Set,
      *      java.util.Comparator)
      */
-    public List helpLines(
-        final int depth,
-        final Set helpSettings,
-        final Comparator comp) {
+    public List helpLines(final int depth,
+                          final Set helpSettings,
+                          final Comparator comp) {
         final List helpLines = new ArrayList();
         helpLines.add(new HelpLineImpl(this, depth));
 
-        if (helpSettings.contains(DisplaySetting.DISPLAY_PARENT_ARGUMENT)
-            && argument != null) {
+        if (helpSettings.contains(DisplaySetting.DISPLAY_PARENT_ARGUMENT) && (argument != null)) {
             helpLines.addAll(argument.helpLines(depth + 1, helpSettings, comp));
         }
 
-        if (helpSettings.contains(DisplaySetting.DISPLAY_PARENT_CHILDREN)
-            && children != null) {
+        if (helpSettings.contains(DisplaySetting.DISPLAY_PARENT_CHILDREN) && (children != null)) {
             helpLines.addAll(children.helpLines(depth + 1, helpSettings, comp));
         }
 
@@ -218,46 +205,45 @@
      * @param arguments the current position in the arguments iterator
      * @param separator the separator char to split on
      */
-    private void handleInitialSeparator(
-        final ListIterator arguments, 
-        final char separator) {
-        
+    private void handleInitialSeparator(final ListIterator arguments,
+                                        final char separator) {
         // next token
-        final String newArgument = (String)arguments.next();
-        
+        final String newArgument = (String) arguments.next();
+
         // split the token
         final int initialIndex = newArgument.indexOf(separator);
-        
+
         if (initialIndex > 0) {
             arguments.remove();
             arguments.add(newArgument.substring(0, initialIndex));
             arguments.add(newArgument.substring(initialIndex + 1));
             arguments.previous();
         }
-        arguments.previous();        
+
+        arguments.previous();
+    }
+
+    /*
+     * @see org.apache.commons.cli2.Option#findOption(java.lang.String)
+     */
+    public Option findOption(final String trigger) {
+        final Option found = super.findOption(trigger);
+
+        if ((found == null) && (children != null)) {
+            return children.findOption(trigger);
+        } else {
+            return found;
+        }
     }
-    
-	/*
-	 * @see org.apache.commons.cli2.Option#findOption(java.lang.String)
-	 */
-	public Option findOption(final String trigger) {
-		final Option found = super.findOption(trigger);
-		if(found==null && children!=null){
-			return children.findOption(trigger);
-		}
-		else{
-			return found;
-		}
-	}
-    
+
     public void defaults(final WriteableCommandLine commandLine) {
         super.defaults(commandLine);
-        
-        if(argument!=null) {
-            argument.defaultValues(commandLine,this);
+
+        if (argument != null) {
+            argument.defaultValues(commandLine, this);
         }
-        
-        if(children!=null) {
+
+        if (children != null) {
             children.defaults(commandLine);
         }
     }

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/DateValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/DateValidator.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/DateValidator.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/DateValidator.java Tue Sep 13 08:35:24 2005
@@ -19,6 +19,7 @@
 import java.text.ParsePosition;
 
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 
@@ -72,6 +73,9 @@
     /** maximum Date allowed i.e: a valid date occurs earlier than this date */
     private Date maximum;
 
+    /** leniant parsing */
+    private boolean isLenient;
+
     /**
      * Creates a Validator for the default date/time format
      */
@@ -96,6 +100,10 @@
      *            a List of DateFormats which dates must conform to
      */
     public DateValidator(final List formats) {
+        for (Iterator iter = formats.iterator(); iter.hasNext();) {
+            DateFormat format = (DateFormat) iter.next();
+        }
+
         setFormats(formats);
     }
 
@@ -150,10 +158,6 @@
             for (int f = 0; (f < this.formats.length) && (date == null); ++f) {
                 // reset the parse position
                 pp.setIndex(0);
-
-                // TODO: should we call setLenient(false) on
-                //       each DateFormat or allow the user
-                //       to specify the parsing used
                 date = this.formats[f].parse(value, pp);
 
                 // if the wrong number of characters have been parsed
@@ -178,6 +182,18 @@
         }
     }
 
+    public void setLeniant(final boolean lenient) {
+        for (int i = 0; i < this.formats.length; i++) {
+            this.formats[i].setLenient(lenient);
+        }
+
+        this.isLenient = lenient;
+    }
+
+    public boolean isLeniant() {
+        return this.isLenient;
+    }
+
     /**
      * Returns the maximum date permitted.
      *
@@ -272,6 +288,7 @@
      */
     public void setFormats(final DateFormat[] formats) {
         this.formats = formats;
+        setLeniant(this.isLenient);
     }
 
     /**

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java Tue Sep 13 08:35:24 2005
@@ -26,9 +26,6 @@
 
 /**
  * @author Rob Oxspring
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
  */
 public class DefaultingCommandLineTest
     extends CommandLineTestCase {

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java Tue Sep 13 08:35:24 2005
@@ -16,8 +16,10 @@
 package org.apache.commons.cli2.option;
 
 import java.text.ParseException;
+
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -30,7 +32,10 @@
 import org.apache.commons.cli2.Option;
 import org.apache.commons.cli2.OptionException;
 import org.apache.commons.cli2.WriteableCommandLine;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
 import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;
+import org.apache.commons.cli2.resource.ResourceConstants;
 import org.apache.commons.cli2.resource.ResourceHelper;
 import org.apache.commons.cli2.validation.DateValidator;
 import org.apache.commons.cli2.validation.DateValidatorTest;
@@ -38,95 +43,40 @@
 /**
  * @author Rob Oxspring
  */
-public class ArgumentTest extends ArgumentTestCase {
-
+public class ArgumentTest
+    extends ArgumentTestCase {
     private ResourceHelper resources = ResourceHelper.getResourceHelper();
-    
+
     public static Argument buildUsernameArgument() {
-        return new ArgumentImpl(
-            "username",
-            "The user to connect as",
-            1,
-            1,
-            '\0',
-            '\0',
-            null,
-            ArgumentImpl.DEFAULT_CONSUME_REMAINING,
-            null,
-            0);
+        return new ArgumentImpl("username", "The user to connect as", 1, 1, '\0', '\0', null,
+                                ArgumentImpl.DEFAULT_CONSUME_REMAINING, null, 0);
     }
 
     public static Argument buildHostArgument() {
-        return new ArgumentImpl(
-            "host",
-            "The host name",
-            2,
-            3,
-            '\0',
-            ',',
-            null,
-            null,
-            null,
-            0);
+        return new ArgumentImpl("host", "The host name", 2, 3, '\0', ',', null, null, null, 0);
     }
 
     public static Argument buildPathArgument() {
-        return new ArgumentImpl(
-            "path",
-            "The place to look for files",
-            1,
-            Integer.MAX_VALUE,
-            '=',
-            ';',
-            null,
-            ArgumentImpl.DEFAULT_CONSUME_REMAINING,
-            null,
-            0);
+        return new ArgumentImpl("path", "The place to look for files", 1, Integer.MAX_VALUE, '=',
+                                ';', null, ArgumentImpl.DEFAULT_CONSUME_REMAINING, null, 0);
     }
 
     public static Argument buildDateLimitArgument() {
-        return new ArgumentImpl(
-            "limit",
-            "the last acceptable date",
-            0,
-            1,
-            '=',
-            '\0',
-            new DateValidator(DateValidatorTest.YYYY_MM_YY),
-            null,
-            null,
-            0);
+        return new ArgumentImpl("limit", "the last acceptable date", 0, 1, '=', '\0',
+                                new DateValidator(DateValidatorTest.YYYY_MM_YY), null, null, 0);
     }
 
     public static Argument buildTargetsArgument() {
-        return new ArgumentImpl(
-            "target",
-            "The targets ant should build",
-            0,
-            Integer.MAX_VALUE,
-            '\0',
-            ',',
-            null,
-            null,
-            null,
-            0);
+        return new ArgumentImpl("target", "The targets ant should build", 0, Integer.MAX_VALUE,
+                                '\0', ',', null, null, null, 0);
     }
-    
+
     public static Argument buildSizeArgument() {
         List defaults = new ArrayList();
         defaults.add("10");
 
-        return new ArgumentImpl(
-            "size",
-            "The number of units",
-            1,
-            1,
-            '\0',
-            '\0',
-            null,
-            ArgumentImpl.DEFAULT_CONSUME_REMAINING,
-            defaults,
-            0);
+        return new ArgumentImpl("size", "The number of units", 1, 1, '\0', '\0', null,
+                                ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0);
     }
 
     public static Argument buildBoundsArgument() {
@@ -134,109 +84,55 @@
         defaults.add("5");
         defaults.add("10");
 
-        return new ArgumentImpl(
-            "size",
-            "The number of units",
-            2,
-            2,
-            '\0',
-            '\0',
-            null,
-            ArgumentImpl.DEFAULT_CONSUME_REMAINING,
-            defaults,
-            0);
+        return new ArgumentImpl("size", "The number of units", 2, 2, '\0', '\0', null,
+                                ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0);
     }
 
     public void testNew() {
-        {
-            try {
-                new ArgumentImpl(
-                        "limit",
-                        "the last acceptable date",
-                        10,
-                        5,
-                        '=',
-                        '\0',
-                        new DateValidator(DateValidatorTest.YYYY_MM_YY),
-                        null,
-                        null,
-                        0);
-            } catch (IllegalArgumentException e) {
-                assertEquals(
-                        resources.getMessage("Argument.minimum.exceeds.maximum"),
-                        e.getMessage());
-            }
+        try {
+            new ArgumentImpl("limit", "the last acceptable date", 10, 5, '=', '\0',
+                             new DateValidator(DateValidatorTest.YYYY_MM_YY), null, null, 0);
+        } catch (IllegalArgumentException e) {
+            assertEquals(resources.getMessage("Argument.minimum.exceeds.maximum"), e.getMessage());
         }
+
         {
-            ArgumentImpl arg = new ArgumentImpl(
-                    null,
-                    "the last acceptable date",
-                    5,
-                    5,
-                    '=',
-                    '\0',
-                    new DateValidator(DateValidatorTest.YYYY_MM_YY),
-                    null,
-                    null,
-                    0);
+            ArgumentImpl arg =
+                new ArgumentImpl(null, "the last acceptable date", 5, 5, '=', '\0',
+                                 new DateValidator(DateValidatorTest.YYYY_MM_YY), null, null, 0);
             assertEquals("wrong arg name", "arg", arg.getPreferredName());
         }
 
         {
             List defaults = new ArrayList();
-            
+
             try {
-                new ArgumentImpl(
-                    null,
-                    "the last acceptable date",
-                    1,
-                    1,
-                    '=',
-                    '\0',
-                    new DateValidator(DateValidatorTest.YYYY_MM_YY),
-                    null,
-                    defaults,
-                    0);
-            }
-            catch(IllegalArgumentException exp) {
-                assertEquals(
-                        resources.getMessage("Argument.too.few.defaults"),
-                        exp.getMessage());
+                new ArgumentImpl(null, "the last acceptable date", 1, 1, '=', '\0',
+                                 new DateValidator(DateValidatorTest.YYYY_MM_YY), null, defaults, 0);
+            } catch (IllegalArgumentException exp) {
+                assertEquals(resources.getMessage("Argument.too.few.defaults"), exp.getMessage());
             }
         }
 
-        {
-            try {
-                List defaults = new ArrayList();
-                defaults.add("1");
-                defaults.add("2");
-            
-                new ArgumentImpl(
-                    null,
-                    "the last acceptable date",
-                    1,
-                    1,
-                    '=',
-                    '\0',
-                    new DateValidator(DateValidatorTest.YYYY_MM_YY),
-                    null,
-                    defaults,
-                    0);
-            }
-            catch(IllegalArgumentException exp) {
-                assertEquals(
-                    resources.getMessage("Argument.too.many.defaults"),
-                    exp.getMessage());
-            }
+        try {
+            List defaults = new ArrayList();
+            defaults.add("1");
+            defaults.add("2");
+
+            new ArgumentImpl(null, "the last acceptable date", 1, 1, '=', '\0',
+                             new DateValidator(DateValidatorTest.YYYY_MM_YY), null, defaults, 0);
+        } catch (IllegalArgumentException exp) {
+            assertEquals(resources.getMessage("Argument.too.many.defaults"), exp.getMessage());
         }
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.ArgumentTestCase#testProcessValues()
      */
-    public void testProcessValues() throws OptionException {
+    public void testProcessValues()
+        throws OptionException {
         final Argument option = buildUsernameArgument();
         final List args = list("rob");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -249,7 +145,22 @@
         assertEquals("rob", commandLine.getValue(option));
     }
 
-    public void testProcessValues_SpareValues() throws OptionException {
+    public void testProcessValues_BoundaryQuotes()
+        throws OptionException {
+        final Argument option = buildUsernameArgument();
+        final List args = list("\"rob\"");
+        final WriteableCommandLine commandLine = commandLine(option, args);
+        final ListIterator iterator = args.listIterator();
+        option.processValues(commandLine, iterator, option);
+
+        assertFalse(iterator.hasNext());
+        assertTrue(commandLine.hasOption(option));
+        assertTrue(commandLine.hasOption("username"));
+        assertEquals("rob", commandLine.getValue(option));
+    }
+
+    public void testProcessValues_SpareValues()
+        throws OptionException {
         final Argument option = buildUsernameArgument();
         final List args = list("rob", "secret");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -270,12 +181,9 @@
 
         try {
             option.processValues(commandLine, iterator, option);
-        }
-        catch (final OptionException mve) {
+        } catch (final OptionException mve) {
             assertEquals(option, mve.getOption());
-            assertEquals(
-                "Missing value(s) target [target ...]",
-                mve.getMessage());
+            assertEquals("Missing value(s) target [target ...]", mve.getMessage());
         }
 
         assertFalse(iterator.hasNext());
@@ -284,7 +192,8 @@
         assertTrue(commandLine.getValues(option).isEmpty());
     }
 
-    public void testProcessValues_Multiple() throws OptionException {
+    public void testProcessValues_Multiple()
+        throws OptionException {
         final Argument option = buildTargetsArgument();
         final List args = list("compile", "test", "docs");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -298,7 +207,8 @@
         assertListContentsEqual(args, commandLine.getValues(option));
     }
 
-    public void testProcessValues_Contracted() throws OptionException {
+    public void testProcessValues_Contracted()
+        throws OptionException {
         final Argument option = buildTargetsArgument();
         final List args = list("compile,test,javadoc", "checkstyle,jdepend");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -308,9 +218,8 @@
         assertFalse(iterator.hasNext());
         assertTrue(commandLine.hasOption(option));
         assertTrue(commandLine.hasOption("target"));
-        assertListContentsEqual(
-            list("compile", "test", "javadoc", "checkstyle", "jdepend"),
-            commandLine.getValues(option));
+        assertListContentsEqual(list("compile", "test", "javadoc", "checkstyle", "jdepend"),
+                                commandLine.getValues(option));
     }
 
     public void testProcessValues_ContractedTooFew() {
@@ -318,29 +227,44 @@
         final List args = list("box1");
         final WriteableCommandLine commandLine = commandLine(option, args);
         final ListIterator iterator = args.listIterator();
+
         try {
             option.processValues(commandLine, iterator, option);
             option.validate(commandLine);
             fail("Expected MissingValueException");
+        } catch (OptionException mve) {
+            assertSame(option, mve.getOption());
         }
-        catch (OptionException mve) {
+    }
+
+    public void testProcessValues_ContractedTooMany() {
+        final Argument option = buildHostArgument();
+        final List args = list("box1,box2,box3,box4");
+        final WriteableCommandLine commandLine = commandLine(option, args);
+        final ListIterator iterator = args.listIterator();
+
+        try {
+            option.processValues(commandLine, iterator, option);
+            option.validate(commandLine);
+            fail("Expected MissingValueException");
+        } catch (OptionException mve) {
             assertSame(option, mve.getOption());
         }
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testCanProcess()
      */
     public void testCanProcess() {
         final Argument option = buildTargetsArgument();
-        assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null), "any value"));
+        assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "any value"));
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testPrefixes()
      */
     public void testPrefixes() {
@@ -350,10 +274,11 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testProcess()
      */
-    public void testProcess() throws OptionException {
+    public void testProcess()
+        throws OptionException {
         final Argument option = buildPathArgument();
         final List args = list("-path=/lib;/usr/lib;/usr/local/lib");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -363,14 +288,13 @@
         assertFalse(iterator.hasNext());
         assertTrue(commandLine.hasOption(option));
         assertTrue(commandLine.hasOption("path"));
-        assertListContentsEqual(
-            list("-path=/lib", "/usr/lib", "/usr/local/lib"),
-            commandLine.getValues(option));
+        assertListContentsEqual(list("-path=/lib", "/usr/lib", "/usr/local/lib"),
+                                commandLine.getValues(option));
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testTriggers()
      */
     public void testTriggers() {
@@ -380,10 +304,11 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testValidate()
      */
-    public void testValidate() throws OptionException {
+    public void testValidate()
+        throws OptionException {
         final Argument option = buildUsernameArgument();
         final WriteableCommandLine commandLine = commandLine(option, list());
 
@@ -399,12 +324,25 @@
         try {
             option.validate(commandLine);
             fail("UnexpectedValue");
-        }
-        catch (OptionException mve) {
+        } catch (OptionException mve) {
             assertEquals(option, mve.getOption());
         }
     }
 
+    public void testRequired() {
+        {
+            final Argument arg = buildBoundsArgument();
+
+            assertTrue("not required", arg.isRequired());
+        }
+
+        {
+            final Argument arg = buildTargetsArgument();
+
+            assertFalse("should not be required", arg.isRequired());
+        }
+    }
+
     public void testValidate_Maximum() {
         final Argument option = buildUsernameArgument();
         final WriteableCommandLine commandLine = commandLine(option, list());
@@ -415,8 +353,7 @@
         try {
             option.validate(commandLine);
             fail("UnexpectedValue");
-        }
-        catch (OptionException uve) {
+        } catch (OptionException uve) {
             assertEquals(option, uve.getOption());
         }
     }
@@ -429,16 +366,31 @@
         commandLine.addValue(option, "2004-01-01");
 
         option.validate(commandLine, option);
-        assertContentsEqual(
-            Arrays.asList(
-                new Object[] {
-                     DateValidatorTest.YYYY_MM_YY.parse("2004-01-01")}),
-            commandLine.getValues(option));
+        assertContentsEqual(Arrays.asList(new Object[] {
+                                              DateValidatorTest.YYYY_MM_YY.parse("2004-01-01")
+                                          }), commandLine.getValues(option));
+    }
+
+    public void testValidate_ValidatorInvalidDate()
+        throws OptionException, ParseException {
+        final Argument option = buildDateLimitArgument();
+        final WriteableCommandLine commandLine = commandLine(option, list());
+
+        commandLine.addValue(option, "12-12-2004");
+
+        try {
+            option.validate(commandLine, option);
+        } catch (OptionException exp) {
+            OptionException e =
+                new OptionException(option, ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,
+                                    "12-12-2004");
+            assertEquals("wrong exception message", e.getMessage(), exp.getMessage());
+        }
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage()
      */
     public void testAppendUsage() {
@@ -487,7 +439,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName()
      */
     public void testGetPreferredName() {
@@ -497,7 +449,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetDescription()
      */
     public void testGetDescription() {
@@ -507,7 +459,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testHelpLines()
      */
     public void testHelpLines() {
@@ -515,7 +467,7 @@
         final List lines = option.helpLines(0, DisplaySetting.ALL, null);
         final Iterator i = lines.iterator();
 
-        final HelpLine line1 = (HelpLine)i.next();
+        final HelpLine line1 = (HelpLine) i.next();
         assertEquals(0, line1.getIndent());
         assertEquals(option, line1.getOption());
 
@@ -525,16 +477,18 @@
     public void testCanProcess_ConsumeRemaining() {
         final Option option = buildUsernameArgument();
 
-        assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null), "--"));
+        assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "--"));
     }
 
-    public void testProcess_ConsumeRemaining() throws OptionException {
+    public void testProcess_ConsumeRemaining()
+        throws OptionException {
         final Option option = buildPathArgument();
         final List args = list("options", "--", "--ignored", "-Dprop=val");
         final WriteableCommandLine commandLine = commandLine(option, args);
         final ListIterator iterator = args.listIterator();
 
         option.process(commandLine, iterator);
+
         final List values = commandLine.getValues(option);
         assertTrue(values.contains("options"));
         assertTrue(values.contains("--ignored"));
@@ -553,8 +507,7 @@
             option.process(commandLine, iterator);
             option.validate(commandLine);
             fail("Missing Value!");
-        }
-        catch (OptionException mve) {
+        } catch (OptionException mve) {
             assertEquals(option, mve.getOption());
             assertEquals("Missing value(s) path [path ...]", mve.getMessage());
         }
@@ -563,32 +516,32 @@
         assertFalse(iterator.hasNext());
     }
 
-//    public void testProcess_DefinedDefaultValue() throws OptionException {
-//        final Option size = buildSizeArgument();
-//        final List args = list();
-//        final WriteableCommandLine commandLine = commandLine(size, args);
-//        final ListIterator iterator = args.listIterator();
-//
-//        size.process(commandLine, iterator);
-//
-//        assertEquals("10", commandLine.getValue(size));
-//    }
-//
-//    public void testProcess_DefinedDefaultValues() throws OptionException {
-//        final Option bounds = buildBoundsArgument();
-//        final List args = list();
-//        final WriteableCommandLine commandLine = commandLine(bounds, args);
-//        final ListIterator iterator = args.listIterator();
-//
-//        bounds.process(commandLine, iterator);
-//
-//        List values = new ArrayList();
-//        values.add("5");
-//        values.add("10");
-//        assertEquals(values, commandLine.getValues(bounds));
-//    }
-
-    public void testProcess_InterrogatedDefaultValue() throws OptionException {
+    //    public void testProcess_DefinedDefaultValue() throws OptionException {
+    //        final Option size = buildSizeArgument();
+    //        final List args = list();
+    //        final WriteableCommandLine commandLine = commandLine(size, args);
+    //        final ListIterator iterator = args.listIterator();
+    //
+    //        size.process(commandLine, iterator);
+    //
+    //        assertEquals("10", commandLine.getValue(size));
+    //    }
+    //
+    //    public void testProcess_DefinedDefaultValues() throws OptionException {
+    //        final Option bounds = buildBoundsArgument();
+    //        final List args = list();
+    //        final WriteableCommandLine commandLine = commandLine(bounds, args);
+    //        final ListIterator iterator = args.listIterator();
+    //
+    //        bounds.process(commandLine, iterator);
+    //
+    //        List values = new ArrayList();
+    //        values.add("5");
+    //        values.add("10");
+    //        assertEquals(values, commandLine.getValues(bounds));
+    //    }
+    public void testProcess_InterrogatedDefaultValue()
+        throws OptionException {
         final Option size = buildSizeArgument();
         final List args = list();
         final WriteableCommandLine commandLine = commandLine(size, args);
@@ -596,9 +549,37 @@
 
         size.process(commandLine, iterator);
 
-        assertEquals(
-            new Integer(20),
-            commandLine.getValue(size, new Integer(20)));
+        assertEquals(new Integer(20), commandLine.getValue(size, new Integer(20)));
+    }
+
+    public void testTooFewDefaults() {
+        List defaults = new ArrayList();
+        defaults.add("5");
+
+        try {
+            new ArgumentImpl("size", "The number of units", 2, 2, '\0', '\0', null,
+                             ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.ARGUMENT_TOO_FEW_DEFAULTS),
+                         exp.getMessage());
+        }
+    }
+
+    public void testTooManyDefaults() {
+        List defaults = new ArrayList();
+        defaults.add("5");
+        defaults.add("10");
+        defaults.add("15");
+
+        try {
+            new ArgumentImpl("size", "The number of units", 2, 2, '\0', '\0', null,
+                             ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.ARGUMENT_TOO_MANY_DEFAULTS),
+                         exp.getMessage());
+        }
     }
 
     public void testProcess_InterrogatedDefaultValues()
@@ -614,5 +595,47 @@
         values.add("50");
         values.add("100");
         assertEquals(values, commandLine.getValues(bounds, values));
+    }
+
+    public void testProcess_StripBoundaryQuotes()
+        throws OptionException {
+        final Option bounds = buildBoundsArgument();
+        final List args = list();
+        final WriteableCommandLine commandLine = commandLine(bounds, args);
+        final ListIterator iterator = args.listIterator();
+
+        bounds.process(commandLine, iterator);
+
+        List values = new ArrayList();
+        values.add("50\"");
+        values.add("\"100");
+        assertEquals(values, commandLine.getValues(bounds, values));
+    }
+
+    public void testSourceDestArgument() {
+        final ArgumentBuilder abuilder = new ArgumentBuilder();
+        final GroupBuilder gbuilder = new GroupBuilder();
+        final Argument inputfiles =
+            abuilder.withName("input").withMinimum(0).withMaximum(0).create();
+        final Argument bad_outputfile =
+            abuilder.withName("output").withMinimum(1).withMaximum(2).create();
+
+        try {
+            final Argument targets = new SourceDestArgument(inputfiles, bad_outputfile);
+        } catch (final IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SOURCE_DEST_MUST_ENFORCE_VALUES),
+                         exp.getMessage());
+        }
+
+        final Argument outputfile =
+            abuilder.withName("output").withMinimum(1).withMaximum(1).create();
+
+        final Argument targets = new SourceDestArgument(inputfiles, outputfile);
+        final StringBuffer buffer = new StringBuffer("test content");
+        targets.appendUsage(buffer, Collections.EMPTY_SET, null);
+
+        assertTrue("buffer not added", buffer.toString().startsWith("test content"));
+        assertFalse("space added", buffer.charAt(12) == ' ');
     }
 }

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/CommandTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/CommandTest.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/CommandTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/CommandTest.java Tue Sep 13 08:35:24 2005
@@ -27,54 +27,38 @@
 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 CommandTest extends ParentTestCase {
-
+public class CommandTest
+    extends ParentTestCase {
     public static Command buildStartCommand() {
-        return new Command(
-            "start",
-            "Begins the process",
-            Collections.singleton("go"),
-            false,
-            null,
-            null,
-            0);
+        return new Command("start", "Begins the process", Collections.singleton("go"), false, null,
+                           null, 0);
     }
 
     public static Command buildCommitCommand() {
-        return new Command(
-            "commit",
-            "Commit the changes to the database",
-            null,
-            true,
-            null,
-            null,
-            0);
+        return new Command("commit", "Commit the changes to the database", null, true, null, null, 0);
     }
 
     public static Command buildLoginCommand() {
-        return new Command(
-            "login",
-            "Initiates a session for the user",
-            null,
-            false,
-            ArgumentTest.buildUsernameArgument(),
-            null,
-            0);
+        return new Command("login", "Initiates a session for the user", null, false,
+                           ArgumentTest.buildUsernameArgument(), null, 0);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.ParentTestCase#testProcessParent()
      */
-    public void testProcessParent() throws OptionException {
+    public void testProcessParent()
+        throws OptionException {
         final Command option = buildStartCommand();
         final List args = list("go");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -88,7 +72,8 @@
         assertTrue(commandLine.getValues(option).isEmpty());
     }
 
-    public void testProcessParent_Spare() throws OptionException {
+    public void testProcessParent_Spare()
+        throws OptionException {
         final Command option = buildLoginCommand();
         final List args = list("login", "rob");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -104,27 +89,27 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testCanProcess()
      */
     public void testCanProcess() {
         final Command option = buildStartCommand();
-        assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null), "start"));
+        assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "start"));
     }
 
     public void testCanProcess_BadMatch() {
         final Command option = buildStartCommand();
-        assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null), "stop"));
+        assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), "stop"));
     }
 
     public void testCanProcess_Alias() {
         final Command option = buildStartCommand();
-        assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null), "go"));
+        assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "go"));
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testPrefixes()
      */
     public void testPrefixes() {
@@ -134,10 +119,11 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testProcess()
      */
-    public void testProcess() throws OptionException {
+    public void testProcess()
+        throws OptionException {
         final Command option = buildLoginCommand();
         final List args = list("login", "rob");
         final WriteableCommandLine commandLine = commandLine(option, args);
@@ -152,7 +138,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testTriggers()
      */
     public void testTriggers() {
@@ -163,7 +149,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testValidate()
      */
     public void testValidate() {
@@ -173,15 +159,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() {
@@ -192,6 +177,26 @@
         assertEquals("[start (go)]", buffer.toString());
     }
 
+    public void testNullPreferredName() {
+        try {
+            new Command(null, "", Collections.singleton("go"), false, null, null, 0);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception name",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.COMMAND_PREFERRED_NAME_TOO_SHORT),
+                         exp.getMessage());
+        }
+    }
+
+    public void testEmotyPreferredName() {
+        try {
+            new Command("", "", Collections.singleton("go"), false, null, null, 0);
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception name",
+                         ResourceHelper.getResourceHelper().getMessage(ResourceConstants.COMMAND_PREFERRED_NAME_TOO_SHORT),
+                         exp.getMessage());
+        }
+    }
+
     public void testAppendUsage_NoOptional() {
         final Option option = buildStartCommand();
         final StringBuffer buffer = new StringBuffer();
@@ -214,7 +219,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName()
      */
     public void testGetPreferredName() {
@@ -224,22 +229,20 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetDescription()
      */
     public void testGetDescription() {
         final Option option = buildLoginCommand();
-        assertEquals(
-            "Initiates a session for the user",
-            option.getDescription());
+        assertEquals("Initiates a session for the user", option.getDescription());
     }
+
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testHelpLines()
      */
     public void testHelpLines() {
         // TODO Auto-generated method stub
-
     }
 }

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTest.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTest.java Tue Sep 13 08:35:24 2005
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright 2003-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,30 +35,17 @@
 /**
  * @author Rob Oxspring
  */
-public class GroupTest extends GroupTestCase {
-
+public class GroupTest
+    extends GroupTestCase {
     public static final Command COMMAND_START =
         new Command("start", "Starts the server", null, false, null, null, 0);
     public static final Command COMMAND_STOP =
         new Command("stop", "Stops the server", null, false, null, null, 0);
     public static final Command COMMAND_RESTART =
-        new Command(
-            "restart",
-            "Stops and starts the server",
-            null,
-            false,
-            null,
-            null,
-            0);
+        new Command("restart", "Stops and starts the server", null, false, null, null, 0);
     public static final Command COMMAND_GRACEFUL =
-        new Command(
-            "graceful",
-            "Restarts the server without interruption",
-            null,
-            false,
-            null,
-            null,
-            0);
+        new Command("graceful", "Restarts the server without interruption", null, false, null,
+                    null, 0);
 
     public static Group buildApacheCommandGroup() {
         final List options = new ArrayList();
@@ -66,44 +53,34 @@
         options.add(COMMAND_RESTART);
         options.add(COMMAND_START);
         options.add(COMMAND_STOP);
-        return new GroupImpl(
-            options,
-            "httpd-cmds",
-            "The command to pass to the server",
-            1,
-            1);
+
+        return new GroupImpl(options, "httpd-cmds", "The command to pass to the server", 1, 1);
     }
 
     public static Group buildApachectlGroup() {
         final List options = new ArrayList();
         options.add(DefaultOptionTest.buildHelpOption());
         options.add(ParentTest.buildKParent());
-        return new GroupImpl(
-            options,
-            "apachectl",
-            "Controls the apache http deamon",
-            0,
-            Integer.MAX_VALUE);
+
+        return new GroupImpl(options, "apachectl", "Controls the apache http deamon", 0,
+                             Integer.MAX_VALUE);
     }
 
     public static Group buildAntGroup() {
         final List options = new ArrayList();
         options.add(DefaultOptionTest.buildHelpOption());
         options.add(ArgumentTest.buildTargetsArgument());
-        return new GroupImpl(
-            options,
-            "ant",
-            "The options for ant",
-            0,
-            Integer.MAX_VALUE);
+
+        return new GroupImpl(options, "ant", "The options for ant", 0, Integer.MAX_VALUE);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.GroupTestCase#testProcessAnonymousArguments()
      */
-    public void testProcessAnonymousArguments() throws OptionException {
+    public void testProcessAnonymousArguments()
+        throws OptionException {
         final Group option = buildAntGroup();
         final List args = list("compile,test", "dist");
         final ListIterator iterator = args.listIterator();
@@ -118,10 +95,11 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.GroupTestCase#testProcessOptions()
      */
-    public void testProcessOptions() throws OptionException {
+    public void testProcessOptions()
+        throws OptionException {
         final Group option = buildApachectlGroup();
         final List args = list("-?", "-k");
         final ListIterator iterator = args.listIterator();
@@ -137,22 +115,27 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testCanProcess()
      */
     public void testCanProcess() {
         final Group option = buildApacheCommandGroup();
-        assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null), "start"));
+        assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "start"));
     }
 
     public void testCanProcess_BadMatch() {
         final Group option = buildApacheCommandGroup();
-        assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null), "begin"));
+        assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), "begin"));
+    }
+
+    public void testCanProcess_NullMatch() {
+        final Group option = buildApacheCommandGroup();
+        assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), (String) null));
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testPrefixes()
      */
     public void testPrefixes() {
@@ -162,10 +145,11 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testProcess()
      */
-    public void testProcess() throws OptionException {
+    public void testProcess()
+        throws OptionException {
         final Group option = buildAntGroup();
         final List args = list("--help", "compile,test", "dist");
         final ListIterator iterator = args.listIterator();
@@ -174,12 +158,11 @@
 
         assertFalse(iterator.hasNext());
         assertTrue(commandLine.hasOption("-?"));
-        assertListContentsEqual(
-            list("compile", "test", "dist"),
-            commandLine.getValues("target"));
+        assertListContentsEqual(list("compile", "test", "dist"), commandLine.getValues("target"));
     }
 
-    public void testProcess_Nested() throws OptionException {
+    public void testProcess_Nested()
+        throws OptionException {
         final Group option = buildApachectlGroup();
         final List args = list("-h", "-k", "graceful");
         final ListIterator iterator = args.listIterator();
@@ -197,22 +180,21 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testTriggers()
      */
     public void testTriggers() {
         final Group option = buildApachectlGroup();
-        assertContentsEqual(
-            list("--help", "-?", "-h", "-k"),
-            option.getTriggers());
+        assertContentsEqual(list("--help", "-?", "-h", "-k"), option.getTriggers());
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testValidate()
      */
-    public void testValidate() throws OptionException {
+    public void testValidate()
+        throws OptionException {
         final Group option = buildApacheCommandGroup();
         final WriteableCommandLine commandLine = commandLine(option, list());
 
@@ -231,8 +213,7 @@
         try {
             option.validate(commandLine);
             fail("Too many options");
-        }
-        catch (OptionException uoe) {
+        } catch (OptionException uoe) {
             assertEquals(option, uoe.getOption());
         }
     }
@@ -244,63 +225,60 @@
         try {
             option.validate(commandLine);
             fail("Missing an option");
-        }
-        catch (OptionException moe) {
+        } catch (OptionException moe) {
             assertEquals(option, moe.getOption());
         }
     }
-    
-    public void testValidate_RequiredChild() throws OptionException {
-        final Option required = new DefaultOptionBuilder().withLongName("required").withRequired(true).create();
-        final Option optional = new DefaultOptionBuilder().withLongName("optional").withRequired(false).create();
-        final Group group = new GroupBuilder()
-            .withOption(required)
-            .withOption(optional)
-            .withMinimum(1)
-            .create();
+
+    public void testValidate_RequiredChild()
+        throws OptionException {
+        final Option required =
+            new DefaultOptionBuilder().withLongName("required").withRequired(true).create();
+        final Option optional =
+            new DefaultOptionBuilder().withLongName("optional").withRequired(false).create();
+        final Group group =
+            new GroupBuilder().withOption(required).withOption(optional).withMinimum(1).create();
 
         WriteableCommandLine commandLine;
-        
+
         commandLine = commandLine(group, list());
+
         try {
             group.validate(commandLine);
             fail("Missing option 'required'");
-        }
-        catch (OptionException moe) {
+        } catch (OptionException moe) {
             assertEquals(required, moe.getOption());
         }
-        
+
         commandLine = commandLine(group, list());
         commandLine.addOption(optional);
+
         try {
             group.validate(commandLine);
             fail("Missing option 'required'");
-        }
-        catch (OptionException moe) {
+        } catch (OptionException moe) {
             assertEquals(required, moe.getOption());
         }
-        
+
         commandLine = commandLine(group, list());
         commandLine.addOption(required);
         group.validate(commandLine);
-        
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage()
      */
     public void testAppendUsage() {
         final Option option = buildApacheCommandGroup();
         final StringBuffer buffer = new StringBuffer();
         final Set settings = new HashSet(DisplaySetting.ALL);
+
         //settings.remove(DisplaySetting.DISPLAY_ARGUMENT_NUMBERED);
         option.appendUsage(buffer, settings, null);
 
-        assertEquals(
-            "httpd-cmds (graceful|restart|start|stop)",
-            buffer.toString());
+        assertEquals("httpd-cmds (graceful|restart|start|stop)", buffer.toString());
     }
 
     public void testAppendUsage_NoOptional() {
@@ -310,9 +288,7 @@
         settings.remove(DisplaySetting.DISPLAY_OPTIONAL);
         option.appendUsage(buffer, settings, null);
 
-        assertEquals(
-            "httpd-cmds (graceful|restart|start|stop)",
-            buffer.toString());
+        assertEquals("httpd-cmds (graceful|restart|start|stop)", buffer.toString());
     }
 
     public void testAppendUsage_NoExpand() {
@@ -353,14 +329,12 @@
         settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER);
         option.appendUsage(buffer, settings, null);
 
-        assertEquals(
-            "[ant (--help (-?,-h)) [<target1> [<target2> ...]]]",
-            buffer.toString());
+        assertEquals("[ant (--help (-?,-h)) [<target1> [<target2> ...]]]", buffer.toString());
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName()
      */
     public void testGetPreferredName() {
@@ -370,19 +344,17 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testGetDescription()
      */
     public void testGetDescription() {
         final Option option = buildApachectlGroup();
-        assertEquals(
-            "Controls the apache http deamon",
-            option.getDescription());
+        assertEquals("Controls the apache http deamon", option.getDescription());
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testHelpLines()
      */
     public void testHelpLines() {
@@ -390,23 +362,23 @@
         final List lines = option.helpLines(0, DisplaySetting.ALL, null);
         final Iterator i = lines.iterator();
 
-        final HelpLine line1 = (HelpLine)i.next();
+        final HelpLine line1 = (HelpLine) i.next();
         assertEquals(0, line1.getIndent());
         assertEquals(option, line1.getOption());
 
-        final HelpLine line2 = (HelpLine)i.next();
+        final HelpLine line2 = (HelpLine) i.next();
         assertEquals(1, line2.getIndent());
         assertEquals(COMMAND_GRACEFUL, line2.getOption());
 
-        final HelpLine line3 = (HelpLine)i.next();
+        final HelpLine line3 = (HelpLine) i.next();
         assertEquals(1, line3.getIndent());
         assertEquals(COMMAND_RESTART, line3.getOption());
 
-        final HelpLine line4 = (HelpLine)i.next();
+        final HelpLine line4 = (HelpLine) i.next();
         assertEquals(1, line4.getIndent());
         assertEquals(COMMAND_START, line4.getOption());
 
-        final HelpLine line5 = (HelpLine)i.next();
+        final HelpLine line5 = (HelpLine) i.next();
         assertEquals(1, line5.getIndent());
         assertEquals(COMMAND_STOP, line5.getOption());
 
@@ -415,17 +387,18 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testHelpLines()
      */
     public void testHelpLines_NoExpanded() {
         final Option option = buildApacheCommandGroup();
         final Set settings = new HashSet(DisplaySetting.ALL);
         settings.remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
+
         final List lines = option.helpLines(0, settings, null);
         final Iterator i = lines.iterator();
 
-        final HelpLine line1 = (HelpLine)i.next();
+        final HelpLine line1 = (HelpLine) i.next();
         assertEquals(0, line1.getIndent());
         assertEquals(option, line1.getOption());
 
@@ -434,29 +407,30 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.commons.cli2.OptionTestCase#testHelpLines()
      */
     public void testHelpLines_NoName() {
         final Option option = buildApacheCommandGroup();
         final Set settings = new HashSet(DisplaySetting.ALL);
         settings.remove(DisplaySetting.DISPLAY_GROUP_NAME);
+
         final List lines = option.helpLines(0, settings, null);
         final Iterator i = lines.iterator();
 
-        final HelpLine line2 = (HelpLine)i.next();
+        final HelpLine line2 = (HelpLine) i.next();
         assertEquals(1, line2.getIndent());
         assertEquals(COMMAND_GRACEFUL, line2.getOption());
 
-        final HelpLine line3 = (HelpLine)i.next();
+        final HelpLine line3 = (HelpLine) i.next();
         assertEquals(1, line3.getIndent());
         assertEquals(COMMAND_RESTART, line3.getOption());
 
-        final HelpLine line4 = (HelpLine)i.next();
+        final HelpLine line4 = (HelpLine) i.next();
         assertEquals(1, line4.getIndent());
         assertEquals(COMMAND_START, line4.getOption());
 
-        final HelpLine line5 = (HelpLine)i.next();
+        final HelpLine line5 = (HelpLine) i.next();
         assertEquals(1, line5.getIndent());
         assertEquals(COMMAND_STOP, line5.getOption());
 

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTestCase.java?rev=280577&r1=280576&r2=280577&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTestCase.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/GroupTestCase.java Tue Sep 13 08:35:24 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2003-2004 The Apache Software Foundation
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,12 +19,11 @@
 
 /**
  * @author Rob Oxspring
- * 
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
  */
-public abstract class GroupTestCase extends OptionTestCase {
-    public abstract void testProcessOptions() throws OptionException;
+public abstract class GroupTestCase
+    extends OptionTestCase {
+    public abstract void testProcessOptions()
+        throws OptionException;
 
     public abstract void testProcessAnonymousArguments()
         throws OptionException;



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