commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject svn commit: r280462 [3/4] - in /jakarta/commons/proper/cli/trunk/src: java/org/apache/commons/cli2/ java/org/apache/commons/cli2/builder/ java/org/apache/commons/cli2/commandline/ java/org/apache/commons/cli2/option/ java/org/apache/commons/cli2/resour...
Date Tue, 13 Sep 2005 02:33:02 GMT
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=280462&r1=280461&r2=280462&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 Mon Sep 12 19:32:04 2005
@@ -17,45 +17,51 @@
 
 import java.text.DateFormat;
 import java.text.ParsePosition;
+
 import java.util.Date;
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
 /**
  * The <code>DateValidator</code> validates the argument values
  * are date or time value(s).
  *
  * The following example shows how to validate that
- * an argument value(s) is a Date of the following 
+ * an argument value(s) is a Date of the following
  * type: d/M/yy (see {@link java.text.DateFormat}).
  *
  * <pre>
  * DateFormat date = new SimpleDateFormat("d/M/yy");
  * ...
  * ArgumentBuilder builder = new ArgumentBuilder();
- * Argument dateFormat = 
+ * Argument dateFormat =
  *     builder.withName("date");
  *            .withValidator(new DateValidator(dateFormat));
  * </pre>
  *
  * The following example shows how to validate that
- * an argument value(s) is a time of the following 
+ * an argument value(s) is a time of the following
  * type: HH:mm:ss (see {@link java.text.DateFormat}).
  *
  * <pre>
  * DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
  * ...
  * ArgumentBuilder builder = new ArgumentBuilder();
- * Argument time = 
+ * Argument time =
  *     builder.withName("time");
  *            .withValidator(new DateValidator(timeFormat));
  * </pre>
- * 
+ *
  * @author John Keyes
  *
  * @see java.text.DateFormat
  */
 public class DateValidator implements Validator {
+    /** i18n */
+    private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
 
     /** an array of permitted DateFormats */
     private DateFormat[] formats;
@@ -67,33 +73,6 @@
     private Date maximum;
 
     /**
-     * Creates a Validator for dates.
-     * 
-     * @return DateValidator a Validator for dates
-     */
-    public static DateValidator getDateInstance() {
-        return new DateValidator(DateFormat.getDateInstance());
-    }
-
-    /**
-     * Creates a Validator for times.
-     * 
-     * @return DateValidator a Validator for times
-     */
-    public static DateValidator getTimeInstance() {
-        return new DateValidator(DateFormat.getTimeInstance());
-    }
-
-    /**
-     * Creates a Validator for date/times
-     * 
-     * @return DateValidator a Validator for date/times
-     */
-    public static DateValidator getDateTimeInstance() {
-        return new DateValidator(DateFormat.getDateTimeInstance());
-    }
-
-    /**
      * Creates a Validator for the default date/time format
      */
     public DateValidator() {
@@ -102,7 +81,7 @@
 
     /**
      * Creates a Validator for the specified DateFormat.
-     * 
+     *
      * @param format
      *            a DateFormat which dates must conform to
      */
@@ -112,29 +91,55 @@
 
     /**
      * Creates a Validator for the List of specified DateFormats.
-     * 
+     *
      * @param formats
      *            a List of DateFormats which dates must conform to
      */
     public DateValidator(final List formats) {
-    	setFormats(formats);
+        setFormats(formats);
+    }
+
+    /**
+     * Creates a Validator for dates.
+     *
+     * @return DateValidator a Validator for dates
+     */
+    public static DateValidator getDateInstance() {
+        return new DateValidator(DateFormat.getDateInstance());
+    }
+
+    /**
+     * Creates a Validator for times.
+     *
+     * @return DateValidator a Validator for times
+     */
+    public static DateValidator getTimeInstance() {
+        return new DateValidator(DateFormat.getTimeInstance());
+    }
+
+    /**
+     * Creates a Validator for date/times
+     *
+     * @return DateValidator a Validator for date/times
+     */
+    public static DateValidator getDateTimeInstance() {
+        return new DateValidator(DateFormat.getDateTimeInstance());
     }
 
     /**
      * Validate each String value in the specified List against this instances
      * permitted DateFormats.
-     * 
+     *
      * If a value is valid then it's <code>String</code> value in the list is
      * replaced with it's <code>Date</code> value.
-     * 
+     *
      * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
      */
-    public void validate(final List values) throws InvalidArgumentException {
-
+    public void validate(final List values)
+        throws InvalidArgumentException {
         // for each value
         for (final ListIterator i = values.listIterator(); i.hasNext();) {
-
-            final String value = (String)i.next();
+            final String value = (String) i.next();
 
             Date date = null;
 
@@ -142,8 +147,7 @@
             final ParsePosition pp = new ParsePosition(0);
 
             // for each permitted DateFormat
-            for (int f = 0; f < this.formats.length && date == null; ++f) {
-
+            for (int f = 0; (f < this.formats.length) && (date == null); ++f) {
                 // reset the parse position
                 pp.setIndex(0);
 
@@ -165,7 +169,8 @@
 
             // if the date is outside the bounds
             if (isDateEarlier(date) || isDateLater(date)) {
-                throw new InvalidArgumentException("Out of range: " + value);
+                throw new InvalidArgumentException(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
+                                                                        value));
             }
 
             // replace the value in the list with the actual Date
@@ -175,7 +180,7 @@
 
     /**
      * Returns the maximum date permitted.
-     * 
+     *
      * @return Date the maximum date permitted. If no maximum date has been
      *         specified then return <code>null</code>.
      */
@@ -185,7 +190,7 @@
 
     /**
      * Sets the maximum Date to the specified value.
-     * 
+     *
      * @param maximum
      *            the maximum Date permitted
      */
@@ -195,7 +200,7 @@
 
     /**
      * Returns the minimum date permitted.
-     * 
+     *
      * @return Date the minimum date permitted. If no minimum date has been
      *         specified then return <code>null</code>.
      */
@@ -205,7 +210,7 @@
 
     /**
      * Sets the minimum Date to the specified value.
-     * 
+     *
      * @param minimum
      *            the minimum Date permitted
      */
@@ -215,67 +220,66 @@
 
     /**
      * Returns whether the specified Date is later than the maximum date.
-     * 
+     *
      * @param date
      *            the Date to evaluate
-     * 
+     *
      * @return boolean whether <code>date</code> is earlier than the maximum
      *         date
      */
     private boolean isDateLater(Date date) {
-        return maximum != null && date.getTime() > maximum.getTime();
+        return (maximum != null) && (date.getTime() > maximum.getTime());
     }
 
     /**
      * Returns whether the specified Date is earlier than the minimum date.
-     * 
+     *
      * @param date
      *            the Date to evaluate
-     * 
+     *
      * @return boolean whether <code>date</code> is earlier than the minimum
      *         date
      */
     private boolean isDateEarlier(Date date) {
-        return minimum != null && date.getTime() < minimum.getTime();
+        return (minimum != null) && (date.getTime() < minimum.getTime());
     }
-    
+
     /**
      * Sets the date format permitted.
-     * 
-     * @param format 
+     *
+     * @param format
      *              the format to use
      */
     public void setFormat(final DateFormat format) {
-    	setFormats(new DateFormat[]{format});
+        setFormats(new DateFormat[] { format });
     }
-    
+
     /**
      * Sets the date formats permitted.
-     * 
-     * @param formats 
+     *
+     * @param formats
      *               the List of DateFormats to use
      */
     public void setFormats(final List formats) {
-    	setFormats((DateFormat[])formats.toArray(new DateFormat[formats.size()]));
+        setFormats((DateFormat[]) formats.toArray(new DateFormat[formats.size()]));
     }
-    
+
     /**
      * Sets the date formats permitted.
-     * 
-     * @param formats 
+     *
+     * @param formats
      *               the array of DateFormats to use
      */
     public void setFormats(final DateFormat[] formats) {
-    	this.formats = formats;
+        this.formats = formats;
     }
-    
+
     /**
      * Gets the date formats permitted.
      *
      * @return the permitted formats
      */
     public DateFormat[] getFormats() {
-    	return this.formats;
+        return this.formats;
     }
-    
 }

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/EnumValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/EnumValidator.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/EnumValidator.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/EnumValidator.java Mon Sep 12 19:32:04 2005
@@ -19,6 +19,9 @@
 import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
 /**
  * The <code>EnumValidator</code> validates the string argument
  * values are valid.
@@ -33,21 +36,20 @@
  * values.add("blue");
  * ...
  * ArgumentBuilder builder = new ArgumentBuilder();
- * Argument color = 
+ * Argument color =
  *     builder.withName("color");
  *            .withValidator(new EnumValidator(values));
  * </pre>
- * 
+ *
  * @author John Keyes
  */
 public class EnumValidator implements Validator {
-
     /** List of permitted values */
     private Set validValues;
 
     /**
      * Creates a new EnumValidator for the specified values.
-     * 
+     *
      * @param values The list of permitted values
      */
     public EnumValidator(final Set values) {
@@ -56,37 +58,35 @@
 
     /**
      * Validate the list of values against the list of permitted values.
-     * 
+     *
      * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
      */
-    public void validate(final List values) throws InvalidArgumentException {
+    public void validate(final List values)
+        throws InvalidArgumentException {
         for (final Iterator iter = values.iterator(); iter.hasNext();) {
-            final String value = (String)iter.next();
+            final String value = (String) iter.next();
 
             if (!this.validValues.contains(value)) {
-                throw new InvalidArgumentException(
-                    "'"
-                        + value
-                        + "' is not allowed.  Permitted values are:"
-                        + getValuesAsString());
+                throw new InvalidArgumentException(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.ENUM_ILLEGAL_VALUE,
+                                                                                                 new Object[] {
+                                                                                                     value,
+                                                                                                     getValuesAsString()
+                                                                                                 }));
             }
         }
     }
 
     /**
      * Returns the permitted values in a comma separated String
-     * 
+     *
      * @return String formatted list of values
      */
-    private String getValuesAsString() {
+    String getValuesAsString() {
         final StringBuffer buff = new StringBuffer();
 
         buff.append("[");
 
-        for (final Iterator iter = this.validValues.iterator();
-            iter.hasNext();
-            ) {
-
+        for (final Iterator iter = this.validValues.iterator(); iter.hasNext();) {
             buff.append("'").append(iter.next()).append("'");
 
             if (iter.hasNext()) {

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/NumberValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/NumberValidator.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/NumberValidator.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/NumberValidator.java Mon Sep 12 19:32:04 2005
@@ -17,17 +17,21 @@
 
 import java.text.NumberFormat;
 import java.text.ParsePosition;
+
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
 /**
  * The <code>NumberValidator</code> validates the string argument
  * values are numbers.  If the value is a number, the string value in
  * the {@link java.util.List} of values is replaced with the
  * {@link java.lang.Number} instance.
  *
- * A maximum and minimum value can also be specified using 
- * the {@link #setMaximum setMaximum}, and the 
+ * A maximum and minimum value can also be specified using
+ * the {@link #setMaximum setMaximum}, and the
  * {@link #setMinimum setMinimum} methods.
  *
  * The following example shows how to limit the valid values
@@ -38,21 +42,37 @@
  * ArgumentBuilder builder = new ArgumentBuilder();
  * NumberValidator validator = NumberValidator.getIntegerInstance();
  * validator.setMaximum(new Integer(100));
- * 
- * Argument age = 
+ *
+ * Argument age =
  *     builder.withName("age");
  *            .withValidator(validator);
  * </pre>
- * 
+ *
  * @author Rob Oxspring
  * @author John Keyes
  */
 public class NumberValidator implements Validator {
+    /** the <code>NumberFormat</code> being used. */
+    private NumberFormat format;
+
+    /** the lower bound for argument values. */
+    private Number minimum = null;
+
+    /** the upper bound for argument values */
+    private Number maximum = null;
+
+    /**
+     * Creates a new NumberValidator based on the specified NumberFormat
+     * @param format the format of numbers to accept
+     */
+    public NumberValidator(final NumberFormat format) {
+        setFormat(format);
+    }
 
     /**
-     * Returns a <code>NumberValidator</code> for a currency format 
+     * Returns a <code>NumberValidator</code> for a currency format
      * for the current default locale.
-     * @return a <code>NumberValidator</code> for a currency format 
+     * @return a <code>NumberValidator</code> for a currency format
      * for the current default locale.
      */
     public static NumberValidator getCurrencyInstance() {
@@ -60,21 +80,22 @@
     }
 
     /**
-     * Returns a <code>NumberValidator</code> for an integer number format 
+     * Returns a <code>NumberValidator</code> for an integer number format
      * for the current default locale.
-     * @return a <code>NumberValidator</code> for an integer number format 
+     * @return a <code>NumberValidator</code> for an integer number format
      * for the current default locale.
      */
     public static NumberValidator getIntegerInstance() {
         final NumberFormat format = NumberFormat.getNumberInstance();
         format.setParseIntegerOnly(true);
+
         return new NumberValidator(format);
     }
 
     /**
-     * Returns a <code>NumberValidator</code> for a percentage format 
+     * Returns a <code>NumberValidator</code> for a percentage format
      * for the current default locale.
-     * @return a <code>NumberValidator</code> for a percentage format 
+     * @return a <code>NumberValidator</code> for a percentage format
      * for the current default locale.
      */
     public static NumberValidator getPercentInstance() {
@@ -82,54 +103,40 @@
     }
 
     /**
-     * Returns a <code>NumberValidator</code> for a general-purpose 
+     * Returns a <code>NumberValidator</code> for a general-purpose
      * number format for the current default locale.
-     * @return a <code>NumberValidator</code> for a general-purpose 
+     * @return a <code>NumberValidator</code> for a general-purpose
      * number format for the current default locale.
      */
     public static NumberValidator getNumberInstance() {
         return new NumberValidator(NumberFormat.getNumberInstance());
     }
 
-    /** the <code>NumberFormat</code> being used. */
-    private NumberFormat format;
-
-    /** the lower bound for argument values. */
-    private Number minimum = null;
-    
-    /** the upper bound for argument values */
-    private Number maximum = null;
-
-    /**
-     * Creates a new NumberValidator based on the specified NumberFormat
-     * @param format the format of numbers to accept
-     */
-    public NumberValidator(final NumberFormat format) {
-        setFormat(format);
-    }
-
     /**
      * Validate the list of values against the list of permitted values.
      * If a value is valid, replace the string in the <code>values</code>
      * {@link java.util.List} with the {@link java.lang.Number} instance.
-     * 
+     *
      * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
      */
-    public void validate(final List values) throws InvalidArgumentException {
+    public void validate(final List values)
+        throws InvalidArgumentException {
         for (final ListIterator i = values.listIterator(); i.hasNext();) {
             final String value = (String) i.next();
 
             final ParsePosition pp = new ParsePosition(0);
             final Number number = format.parse(value, pp);
+
             if (pp.getIndex() < value.length()) {
                 throw new InvalidArgumentException(value);
             }
 
-            if ((minimum != null
-                && number.doubleValue() < minimum.doubleValue())
-                || (maximum != null
-                    && number.doubleValue() > maximum.doubleValue())) {
-                throw new InvalidArgumentException("Out of range: " + value);
+            if (((minimum != null) && (number.doubleValue() < minimum.doubleValue())) ||
+                    ((maximum != null) && (number.doubleValue() > maximum.doubleValue()))) {
+                throw new InvalidArgumentException(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE,
+                                                                                                 new Object[] {
+                                                                                                     value
+                                                                                                 }));
             }
 
             i.set(number);
@@ -153,7 +160,7 @@
     protected void setFormat(NumberFormat format) {
         this.format = format;
     }
-    
+
     /**
      * Return the maximum value allowed for an argument value.
      *

Modified: jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/UrlValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/UrlValidator.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/UrlValidator.java (original)
+++ jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/UrlValidator.java Mon Sep 12 19:32:04 2005
@@ -17,16 +17,20 @@
 
 import java.net.MalformedURLException;
 import java.net.URL;
+
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
 /**
  * The <code>UrlValidator</code> validates the string argument
  * values are URLs.  If the value is a URL, the string value in
  * the {@link java.util.List} of values is replaced with the
  * {@link java.net.URL} instance.
  *
- * URLs can also be validated based on their scheme by using 
+ * URLs can also be validated based on their scheme by using
  * the {@link #setProtocol setProtocol} method, or by using the specified
  * {@link #UrlValidator(java.lang.String) constructor}.
  *
@@ -36,16 +40,15 @@
  * <pre>
  * ...
  * ArgumentBuilder builder = new ArgumentBuilder();
- * Argument site = 
+ * Argument site =
  *     builder.withName("site");
  *            .withValidator(new URLValidator("https"));
  * </pre>
- * 
+ *
  * @author Rob Oxspring
  * @author John Keyes
  */
 public class UrlValidator implements Validator {
-
     /** allowed protocol */
     private String protocol = null;
 
@@ -66,24 +69,27 @@
      * Validate the list of values against the list of permitted values.
      * If a value is valid, replace the string in the <code>values</code>
      * {@link java.util.List} with the { java.net.URL} instance.
-     * 
+     *
      * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
      */
-    public void validate(final List values) throws InvalidArgumentException {
+    public void validate(final List values)
+        throws InvalidArgumentException {
         for (final ListIterator i = values.listIterator(); i.hasNext();) {
-            final String name = (String)i.next();
+            final String name = (String) i.next();
+
             try {
                 final URL url = new URL(name);
 
-                if (protocol != null && !protocol.equals(url.getProtocol())) {
+                if ((protocol != null) && !protocol.equals(url.getProtocol())) {
                     throw new InvalidArgumentException(name);
                 }
 
                 i.set(url);
-            }
-            catch (final MalformedURLException mue) {
-                throw new InvalidArgumentException(
-                    "Cannot understand url: " + name);
+            } catch (final MalformedURLException mue) {
+                throw new InvalidArgumentException(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.URLVALIDATOR_MALFORMED_URL,
+                                                                                                 new Object[] {
+                                                                                                     name
+                                                                                                 }));
             }
         }
     }
@@ -105,5 +111,4 @@
     public void setProtocol(String protocol) {
         this.protocol = protocol;
     }
-
 }

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java Mon Sep 12 19:32:04 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.
@@ -29,219 +29,251 @@
 import org.apache.commons.cli2.option.OptionTestCase;
 import org.apache.commons.cli2.option.PropertyOption;
 import org.apache.commons.cli2.option.SwitchTest;
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
 
-public abstract class CommandLineTestCase extends CLITestCase {
-	
-	protected abstract CommandLine createCommandLine();
-	
-	public final Option present = new DefaultOptionBuilder().withLongName("present").withLongName("alsopresent").create();
-	public final Option missing = new DefaultOptionBuilder().withLongName("missing").create();
-	public final Option multiple = new DefaultOptionBuilder().withLongName("multiple").create();
-	public final Option bool = new DefaultOptionBuilder().withLongName("bool").create();
-	
-	public final Option root = new GroupBuilder().withOption(present).withOption(missing).withOption(multiple).withOption(bool).create();
-	
-	private CommandLine commandLine;
-	
-	/*
-	 * @see TestCase#setUp()
-	 */
-	public void setUp() throws Exception {
-		super.setUp();
-		commandLine = createCommandLine();
-	}
-	/*
-	 * Class to test for boolean hasOption(String)
-	 */
-	public final void testHasOptionString() {
-		assertTrue(commandLine.hasOption("--present"));
-		assertTrue(commandLine.hasOption("--alsopresent"));
-		assertFalse(commandLine.hasOption("--missing"));
-	}
-	
-	/*
-	 * Class to test for boolean hasOption(Option)
-	 */
-	public final void testHasOptionOption() {
-		assertTrue(commandLine.hasOption(present));
-		assertFalse(commandLine.hasOption(missing));
-	}
-	public final void testGetOption() {
-		assertSame(present,commandLine.getOption("--present"));
-		assertSame(present,commandLine.getOption("--alsopresent"));
-		//TODO decide whether the following assertion is valid
-		//assertSame(missing,commandLine.getOption("--missing"));
-	}
-	/*
-	 * Class to test for List getValues(String)
-	 */
-	public final void testGetValuesString() {
-		assertListContentsEqual(list("present value"),commandLine.getValues("--present"));
-		assertListContentsEqual(list("value 1","value 2","value 3"),commandLine.getValues("--multiple"));
-		assertTrue(commandLine.getValues("--missing").isEmpty());
-	}
-	/*
-	 * Class to test for List getValues(String, List)
-	 */
-	public final void testGetValuesStringList() {
-		assertListContentsEqual(list("present value"),commandLine.getValues("--present",null));
-		assertListContentsEqual(list("present value"),commandLine.getValues("--alsopresent",null));
-		assertSame(commandLine.getValues("--missing",Collections.EMPTY_LIST),Collections.EMPTY_LIST);
-		final List def = Collections.singletonList("default value");
-		assertSame(def,commandLine.getValues("--missing",def));
-	}
-	/*
-	 * Class to test for List getValues(Option)
-	 */
-	public final void testGetValuesOption() {
-		assertListContentsEqual(list("present value"),commandLine.getValues(present));
-		assertTrue(commandLine.getValues(missing).isEmpty());
-	}
-	/*
-	 * Class to test for List getValues(Option, List)
-	 */
-	public final void testGetValuesOptionList() {
-		assertListContentsEqual(list("present value"),commandLine.getValues(present));
-		assertSame(commandLine.getValues(missing,Collections.EMPTY_LIST),Collections.EMPTY_LIST);
-		final List defs = Collections.singletonList("custom default");
-		assertSame(defs,commandLine.getValues(missing,defs));
-	}
-	/*
-	 * Class to test for Object getValue(String)
-	 */
-	public final void testGetValueString() {
-		assertEquals("present value",commandLine.getValue("--present"));
-		assertEquals("present value",commandLine.getValue("--alsopresent"));
-		assertNull(commandLine.getValue("--missing"));
-		try{
-			commandLine.getValue("--multiple");
-			fail("expected IllegalStateException");
-		}
-		catch(IllegalStateException e){
-			assertEquals("More than one value was supplied",e.getMessage());
-		}
-	}
-	/*
-	 * Class to test for Object getValue(String, Object)
-	 */
-	public final void testGetValueStringObject() {
-		assertEquals("present value",commandLine.getValue("--present","default value"));
-		assertEquals("present value",commandLine.getValue("--alsopresent","default value"));
-		assertEquals("default value",commandLine.getValue("--missing","default value"));
-		try{
-			commandLine.getValue("--multiple");
-			fail("expected IllegalStateException");
-		}
-		catch(IllegalStateException e){
-			assertEquals("More than one value was supplied",e.getMessage());
-		}
-	}
-	/*
-	 * Class to test for Object getValue(Option)
-	 */
-	public final void testGetValueOption() {
-		assertEquals("present value",commandLine.getValue(present));
-		assertNull(commandLine.getValue(missing));
-		try{
-			commandLine.getValue(multiple);
-			fail("expected IllegalStateException");
-		}
-		catch(IllegalStateException e){
-			assertEquals("More than one value was supplied",e.getMessage());
-		}
-	}
-	/*
-	 * Class to test for Object getValue(Option, Object)
-	 */
-	public final void testGetValueOptionObject() {
-		assertEquals("present value",commandLine.getValue(present,"default value"));
-		assertEquals("default value",commandLine.getValue(missing,"default value"));
-		try{
-			commandLine.getValue(multiple);
-			fail("expected IllegalStateException");
-		}
-		catch(IllegalStateException e){
-			assertEquals("More than one value was supplied",e.getMessage());
-		}
-	}
-	/*
-	 * Class to test for Boolean getSwitch(String)
-	 */
-	public final void testGetSwitchString() {
-		assertEquals(Boolean.TRUE,commandLine.getSwitch("--bool"));
-		assertNull(commandLine.getSwitch("--missing"));
-	}
-	/*
-	 * Class to test for Boolean getSwitch(String, Boolean)
-	 */
-	public final void testGetSwitchStringBoolean() {
-		assertEquals(Boolean.TRUE,commandLine.getSwitch("--bool",Boolean.FALSE));
-		assertEquals(Boolean.FALSE,commandLine.getSwitch("--missing",Boolean.FALSE));
-	}
-	/*
-	 * Class to test for Boolean getSwitch(Option)
-	 */
-	public final void testGetSwitchOption() {
-		assertEquals(Boolean.TRUE,commandLine.getSwitch(bool));
-		assertNull(commandLine.getSwitch(missing));
-	}
-	/*
-	 * Class to test for Boolean getSwitch(Option, Boolean)
-	 */
-	public final void testGetSwitchOptionBoolean() {
-		assertEquals(Boolean.TRUE,commandLine.getSwitch(bool,Boolean.FALSE));
-		assertEquals(Boolean.FALSE,commandLine.getSwitch(missing,Boolean.FALSE));
-	}
-	/*
-	 * Class to test for String getProperty(String)
-	 */
-	public final void testGetPropertyString() {
-		assertEquals("present property",commandLine.getProperty("present"));
-		assertNull(commandLine.getProperty("missing"));
-	}
-	/*
-	 * Class to test for String getProperty(String, String)
-	 */
-	public final void testGetPropertyStringString() {
-		assertEquals("present property",commandLine.getProperty("present","default property"));
-		assertEquals("default property",commandLine.getProperty("missing","default property"));
-	}
-	public final void testGetProperties() {
-		assertTrue(commandLine.getProperties().containsAll(list("present")));
-	}
-	/*
-	 * Class to test for int getOptionCount(String)
-	 */
-	public final void testGetOptionCountString() {
-		// one option, one switch
-		assertTrue(1<=commandLine.getOptionCount("--present"));
-		assertTrue(1<=commandLine.getOptionCount("--bool"));
-		assertEquals(0,commandLine.getOptionCount("--missing"));
-	}
-	/*
-	 * Class to test for int getOptionCount(Option)
-	 */
-	public final void testGetOptionCountOption() {
-		// one option, one switch
-		assertTrue(1<=commandLine.getOptionCount(present));
-		assertTrue(1<=commandLine.getOptionCount(bool));
-		assertEquals(0,commandLine.getOptionCount(missing));
-	}
-	public final void testGetOptions() {
-		//TODO Implement getOptions().
-	}
-	public final void testGetOptionTriggers() {
-		//TODO Implement getOptionTriggers().
-	}
-	
-	
-	// OLD TESTS FOLLOW
+public abstract class CommandLineTestCase
+    extends CLITestCase {
+    private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
+    public final Option present =
+        new DefaultOptionBuilder().withLongName("present").withLongName("alsopresent").create();
+    public final Option missing = new DefaultOptionBuilder().withLongName("missing").create();
+    public final Option multiple = new DefaultOptionBuilder().withLongName("multiple").create();
+    public final Option bool = new DefaultOptionBuilder().withLongName("bool").create();
+    public final Option root =
+        new GroupBuilder().withOption(present).withOption(missing).withOption(multiple)
+                          .withOption(bool).create();
+    private CommandLine commandLine;
+
+    protected abstract CommandLine createCommandLine();
+
+    /*
+     * @see TestCase#setUp()
+     */
+    public void setUp()
+        throws Exception {
+        super.setUp();
+        commandLine = createCommandLine();
+    }
+
+    /*
+     * Class to test for boolean hasOption(String)
+     */
+    public final void testHasOptionString() {
+        assertTrue(commandLine.hasOption("--present"));
+        assertTrue(commandLine.hasOption("--alsopresent"));
+        assertFalse(commandLine.hasOption("--missing"));
+    }
+
+    /*
+     * Class to test for boolean hasOption(Option)
+     */
+    public final void testHasOptionOption() {
+        assertTrue(commandLine.hasOption(present));
+        assertFalse(commandLine.hasOption(missing));
+    }
+
+    public final void testGetOption() {
+        assertSame(present, commandLine.getOption("--present"));
+        assertSame(present, commandLine.getOption("--alsopresent"));
+
+        //TODO decide whether the following assertion is valid
+        //assertSame(missing,commandLine.getOption("--missing"));
+    }
+
+    /*
+     * Class to test for List getValues(String)
+     */
+    public final void testGetValuesString() {
+        assertListContentsEqual(list("present value"), commandLine.getValues("--present"));
+        assertListContentsEqual(list("value 1", "value 2", "value 3"),
+                                commandLine.getValues("--multiple"));
+        assertTrue(commandLine.getValues("--missing").isEmpty());
+    }
+
+    /*
+     * Class to test for List getValues(String, List)
+     */
+    public final void testGetValuesStringList() {
+        assertListContentsEqual(list("present value"), commandLine.getValues("--present", null));
+        assertListContentsEqual(list("present value"), commandLine.getValues("--alsopresent", null));
+        assertSame(commandLine.getValues("--missing", Collections.EMPTY_LIST),
+                   Collections.EMPTY_LIST);
+
+        final List def = Collections.singletonList("default value");
+        assertSame(def, commandLine.getValues("--missing", def));
+    }
+
+    /*
+     * Class to test for List getValues(Option)
+     */
+    public final void testGetValuesOption() {
+        assertListContentsEqual(list("present value"), commandLine.getValues(present));
+        assertTrue(commandLine.getValues(missing).isEmpty());
+    }
+
+    /*
+     * Class to test for List getValues(Option, List)
+     */
+    public final void testGetValuesOptionList() {
+        assertListContentsEqual(list("present value"), commandLine.getValues(present));
+        assertSame(commandLine.getValues(missing, Collections.EMPTY_LIST), Collections.EMPTY_LIST);
+
+        final List defs = Collections.singletonList("custom default");
+        assertSame(defs, commandLine.getValues(missing, defs));
+    }
 
+    /*
+     * Class to test for Object getValue(String)
+     */
+    public final void testGetValueString() {
+        assertEquals("present value", commandLine.getValue("--present"));
+        assertEquals("present value", commandLine.getValue("--alsopresent"));
+        assertNull(commandLine.getValue("--missing"));
+
+        try {
+            commandLine.getValue("--multiple");
+            fail("expected IllegalStateException");
+        } catch (IllegalStateException e) {
+            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
+                         e.getMessage());
+        }
+    }
+
+    /*
+     * Class to test for Object getValue(String, Object)
+     */
+    public final void testGetValueStringObject() {
+        assertEquals("present value", commandLine.getValue("--present", "default value"));
+        assertEquals("present value", commandLine.getValue("--alsopresent", "default value"));
+        assertEquals("default value", commandLine.getValue("--missing", "default value"));
+
+        try {
+            commandLine.getValue("--multiple");
+            fail("expected IllegalStateException");
+        } catch (IllegalStateException e) {
+            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
+                         e.getMessage());
+        }
+    }
+
+    /*
+     * Class to test for Object getValue(Option)
+     */
+    public final void testGetValueOption() {
+        assertEquals("present value", commandLine.getValue(present));
+        assertNull(commandLine.getValue(missing));
+
+        try {
+            commandLine.getValue(multiple);
+            fail("expected IllegalStateException");
+        } catch (IllegalStateException e) {
+            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
+                         e.getMessage());
+        }
+    }
+
+    /*
+     * Class to test for Object getValue(Option, Object)
+     */
+    public final void testGetValueOptionObject() {
+        assertEquals("present value", commandLine.getValue(present, "default value"));
+        assertEquals("default value", commandLine.getValue(missing, "default value"));
+
+        try {
+            commandLine.getValue(multiple);
+            fail("expected IllegalStateException");
+        } catch (IllegalStateException e) {
+            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
+                         e.getMessage());
+        }
+    }
+
+    /*
+     * Class to test for Boolean getSwitch(String)
+     */
+    public final void testGetSwitchString() {
+        assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool"));
+        assertNull(commandLine.getSwitch("--missing"));
+    }
+
+    /*
+     * Class to test for Boolean getSwitch(String, Boolean)
+     */
+    public final void testGetSwitchStringBoolean() {
+        assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool", Boolean.FALSE));
+        assertEquals(Boolean.FALSE, commandLine.getSwitch("--missing", Boolean.FALSE));
+    }
+
+    /*
+     * Class to test for Boolean getSwitch(Option)
+     */
+    public final void testGetSwitchOption() {
+        assertEquals(Boolean.TRUE, commandLine.getSwitch(bool));
+        assertNull(commandLine.getSwitch(missing));
+    }
+
+    /*
+     * Class to test for Boolean getSwitch(Option, Boolean)
+     */
+    public final void testGetSwitchOptionBoolean() {
+        assertEquals(Boolean.TRUE, commandLine.getSwitch(bool, Boolean.FALSE));
+        assertEquals(Boolean.FALSE, commandLine.getSwitch(missing, Boolean.FALSE));
+    }
+
+    /*
+     * Class to test for String getProperty(String)
+     */
+    public final void testGetPropertyString() {
+        assertEquals("present property", commandLine.getProperty("present"));
+        assertNull(commandLine.getProperty("missing"));
+    }
+
+    /*
+     * Class to test for String getProperty(String, String)
+     */
+    public final void testGetPropertyStringString() {
+        assertEquals("present property", commandLine.getProperty("present", "default property"));
+        assertEquals("default property", commandLine.getProperty("missing", "default property"));
+    }
+
+    public final void testGetProperties() {
+        assertTrue(commandLine.getProperties().containsAll(list("present")));
+    }
+
+    /*
+     * Class to test for int getOptionCount(String)
+     */
+    public final void testGetOptionCountString() {
+        // one option, one switch
+        assertTrue(1 <= commandLine.getOptionCount("--present"));
+        assertTrue(1 <= commandLine.getOptionCount("--bool"));
+        assertEquals(0, commandLine.getOptionCount("--missing"));
+    }
+
+    /*
+     * Class to test for int getOptionCount(Option)
+     */
+    public final void testGetOptionCountOption() {
+        // one option, one switch
+        assertTrue(1 <= commandLine.getOptionCount(present));
+        assertTrue(1 <= commandLine.getOptionCount(bool));
+        assertEquals(0, commandLine.getOptionCount(missing));
+    }
+
+    public final void testGetOptions() {
+        //TODO Implement getOptions().
+    }
+
+    public final void testGetOptionTriggers() {
+        //TODO Implement getOptionTriggers().
+    }
+
+    // OLD TESTS FOLLOW
     public final void testProperties() {
         final Option option = new PropertyOption();
         final List args = CLITestCase.list();
-        final WriteableCommandLine writeable =
-            OptionTestCase.commandLine(option, args);
+        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
 
         assertTrue(writeable.getProperties().isEmpty());
 
@@ -261,8 +293,7 @@
     public final void testOptions() {
         final Option option = new PropertyOption();
         final List args = CLITestCase.list();
-        final WriteableCommandLine writeable =
-            OptionTestCase.commandLine(option, args);
+        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
 
         final Option start = CommandTest.buildStartCommand();
 
@@ -280,8 +311,7 @@
     public final void testValues() {
         final Option option = new PropertyOption();
         final List args = CLITestCase.list();
-        final WriteableCommandLine writeable =
-            OptionTestCase.commandLine(option, args);
+        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
 
         final Option start = CommandTest.buildStartCommand();
 
@@ -309,17 +339,17 @@
         try {
             writeable.getValue(start);
             fail("Cannot get single value if multiple are present");
-        }
-        catch (IllegalStateException ise) {
-            assertEquals("More than one value was supplied", ise.getMessage());
+        } catch (IllegalStateException ise) {
+            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
+                         ise.getMessage());
         }
 
         try {
             writeable.getValue("start");
             fail("Cannot get single value if multiple are present");
-        }
-        catch (IllegalStateException ise) {
-            assertEquals("More than one value was supplied", ise.getMessage());
+        } catch (IllegalStateException ise) {
+            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
+                         ise.getMessage());
         }
 
         writeable.getValues(start).add("file3");
@@ -328,8 +358,7 @@
     public final void testSwitches() {
         final Option option = new PropertyOption();
         final List args = CLITestCase.list();
-        final WriteableCommandLine writeable =
-            OptionTestCase.commandLine(option, args);
+        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
 
         final Option start = CommandTest.buildStartCommand();
 
@@ -338,20 +367,20 @@
         assertNull(writeable.getSwitch("go"));
 
         writeable.addSwitch(start, true);
+
         try {
             writeable.addSwitch(start, false);
             fail("Switch cannot be changed");
-        }
-        catch (IllegalStateException ise) {
-            assertEquals("Switch already set", ise.getMessage());
+        } catch (IllegalStateException ise) {
+            assertEquals(resources.getMessage(ResourceConstants.SWITCH_ALREADY_SET),
+                         ise.getMessage());
         }
     }
 
     public final void testSwitches_True() {
         final Option option = new PropertyOption();
         final List args = CLITestCase.list();
-        final WriteableCommandLine writeable =
-            OptionTestCase.commandLine(option, args);
+        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
 
         final Option start = CommandTest.buildStartCommand();
 
@@ -362,8 +391,7 @@
     public final void testSwitches_False() {
         final Option option = new PropertyOption();
         final List args = CLITestCase.list();
-        final WriteableCommandLine writeable =
-            OptionTestCase.commandLine(option, args);
+        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
 
         final Option start = CommandTest.buildStartCommand();
 
@@ -371,44 +399,35 @@
         assertSame(Boolean.FALSE, writeable.getSwitch(start));
     }
 
-//    public final void testLooksLikeOption() {
-//        final Option option = new PropertyOption();
-//        final List args = OptionTestCase.list();
-//        final WriteableCommandLine commandLine =
-//            OptionTestCase.commandLine(option, args);
-//
-//        assertTrue(commandLine.looksLikeOption("-D"));
-//        assertFalse(commandLine.looksLikeOption("--help"));
-//        assertFalse(commandLine.looksLikeOption("+display"));
-//        assertFalse(commandLine.looksLikeOption("myprefix"));
-//        assertFalse(commandLine.looksLikeOption("myprefix2"));
-//        assertFalse(commandLine.looksLikeOption("myprefference"));
-//        assertFalse(commandLine.looksLikeOption("/SCANDISK"));
-//        assertFalse(commandLine.looksLikeOption("update"));
-//    }
-
-    public final void testGetOptions_Order() throws OptionException {
+    //    public final void testLooksLikeOption() {
+    //        final Option option = new PropertyOption();
+    //        final List args = OptionTestCase.list();
+    //        final WriteableCommandLine commandLine =
+    //            OptionTestCase.commandLine(option, args);
+    //
+    //        assertTrue(commandLine.looksLikeOption("-D"));
+    //        assertFalse(commandLine.looksLikeOption("--help"));
+    //        assertFalse(commandLine.looksLikeOption("+display"));
+    //        assertFalse(commandLine.looksLikeOption("myprefix"));
+    //        assertFalse(commandLine.looksLikeOption("myprefix2"));
+    //        assertFalse(commandLine.looksLikeOption("myprefference"));
+    //        assertFalse(commandLine.looksLikeOption("/SCANDISK"));
+    //        assertFalse(commandLine.looksLikeOption("update"));
+    //    }
+    public final void testGetOptions_Order()
+        throws OptionException {
         final Option help = DefaultOptionTest.buildHelpOption();
         final Option login = CommandTest.buildLoginCommand();
         final Option targets = ArgumentTest.buildTargetsArgument();
 
         final Group group =
-            new GroupBuilder()
-                .withOption(help)
-                .withOption(login)
-                .withOption(targets)
-                .create();
+            new GroupBuilder().withOption(help).withOption(login).withOption(targets).create();
 
         final Parser parser = new Parser();
         parser.setGroup(group);
+
         final CommandLine cl =
-            parser.parse(
-                new String[] {
-                    "login",
-                    "rob",
-                    "--help",
-                    "target1",
-                    "target2" });
+            parser.parse(new String[] { "login", "rob", "--help", "target1", "target2" });
 
         final Iterator i = cl.getOptions().iterator();
 
@@ -419,33 +438,25 @@
         assertFalse(i.hasNext());
     }
 
-    public final void testGetOptionCount() throws OptionException {
+    public final void testGetOptionCount()
+        throws OptionException {
         final Option help = DefaultOptionTest.buildHelpOption();
         final Option login = CommandTest.buildLoginCommand();
         final Option targets = ArgumentTest.buildTargetsArgument();
         final Option display = SwitchTest.buildDisplaySwitch();
 
         final Group group =
-            new GroupBuilder()
-                .withOption(help)
-                .withOption(login)
-                .withOption(targets)
-                .withOption(display)
-                .create();
+            new GroupBuilder().withOption(help).withOption(login).withOption(targets)
+                              .withOption(display).create();
 
         final Parser parser = new Parser();
         parser.setGroup(group);
+
         final CommandLine cl =
-            parser.parse(
-                new String[] {
-                    "--help",
-                    "login",
-                    "rob",
-                    "+display",
-                    "--help",
-                    "--help",
-                    "target1",
-                    "target2" });
+            parser.parse(new String[] {
+                             "--help", "login", "rob", "+display", "--help", "--help", "target1",
+                             "target2"
+                         });
 
         assertEquals(1, cl.getOptionCount(login));
         assertEquals(3, cl.getOptionCount(help));
@@ -453,58 +464,44 @@
         assertEquals(1, cl.getOptionCount(display));
     }
 
-    public final void testGetOptionCount_Strings() throws OptionException {
+    public final void testGetOptionCount_Strings()
+        throws OptionException {
         final Option help = DefaultOptionTest.buildHelpOption();
         final Option login = CommandTest.buildLoginCommand();
         final Option targets = ArgumentTest.buildTargetsArgument();
         final Option display = SwitchTest.buildDisplaySwitch();
 
         final Group group =
-            new GroupBuilder()
-                .withOption(help)
-                .withOption(login)
-                .withOption(targets)
-                .withOption(display)
-                .create();
+            new GroupBuilder().withOption(help).withOption(login).withOption(targets)
+                              .withOption(display).create();
 
         final Parser parser = new Parser();
         parser.setGroup(group);
+
         final CommandLine cl =
-            parser.parse(
-                new String[] {
-                    "--help",
-                    "login",
-                    "rob",
-                    "+display",
-                    "--help",
-                    "--help",
-                    "target1",
-                    "target2" });
+            parser.parse(new String[] {
+                             "--help", "login", "rob", "+display", "--help", "--help", "target1",
+                             "target2"
+                         });
 
         assertEquals(1, cl.getOptionCount("login"));
         assertEquals(3, cl.getOptionCount("-?"));
         assertEquals(1, cl.getOptionCount("+display"));
     }
 
-    public final void testOptionAsArgument() throws OptionException {
-    	final Option p = new DefaultOptionBuilder().withShortName("p").create();
-    	final Argument argument = new ArgumentBuilder().create();
-    	final Option withArgument = new DefaultOptionBuilder().withShortName("attr").withArgument(argument).create();
-
-    	final Group group =
-            new GroupBuilder()
-                .withOption(p)
-                .withOption(withArgument)
-                .create();
+    public final void testOptionAsArgument()
+        throws OptionException {
+        final Option p = new DefaultOptionBuilder().withShortName("p").create();
+        final Argument argument = new ArgumentBuilder().create();
+        final Option withArgument =
+            new DefaultOptionBuilder().withShortName("attr").withArgument(argument).create();
+
+        final Group group = new GroupBuilder().withOption(p).withOption(withArgument).create();
 
         final Parser parser = new Parser();
         parser.setGroup(group);
-        final CommandLine cl =
-            parser.parse(
-                new String[] {
-                    "-p",
-                    "-attr",
-                    "p" });
+
+        final CommandLine cl = parser.parse(new String[] { "-p", "-attr", "p" });
 
         assertEquals(1, cl.getOptionCount("-p"));
         assertTrue(cl.hasOption("-p"));

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java Mon Sep 12 19:32:04 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2004 The Apache Software Foundation
+/*
+ * Copyright 2004-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.
@@ -20,16 +20,19 @@
 import org.apache.commons.cli2.Argument;
 import org.apache.commons.cli2.Group;
 import org.apache.commons.cli2.option.DefaultOption;
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
 
-
-public class DefaultOptionBuilderTest extends TestCase {
-
+public class DefaultOptionBuilderTest
+    extends TestCase {
+    private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
     private DefaultOptionBuilder defaultOptionBuilder;
-    
+
     /*
      * @see TestCase#setUp()
      */
-    protected void setUp() throws Exception {
+    protected void setUp()
+        throws Exception {
         this.defaultOptionBuilder = new DefaultOptionBuilder();
     }
 
@@ -38,12 +41,11 @@
      */
     public void testNew_NullShortPrefix() {
         try {
-            new DefaultOptionBuilder(null, null,
-                    false);
+            new DefaultOptionBuilder(null, null, false);
             fail("null short prefix is not permitted");
-        }
-        catch(IllegalArgumentException e) {
-            assertEquals("shortPrefix should be at least 1 character long",e.getMessage());
+        } catch (IllegalArgumentException e) {
+            assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX),
+                         e.getMessage());
         }
     }
 
@@ -52,12 +54,11 @@
      */
     public void testNew_EmptyShortPrefix() {
         try {
-            new DefaultOptionBuilder("", null,
-                    false);
+            new DefaultOptionBuilder("", null, false);
             fail("empty short prefix is not permitted");
-        }
-        catch(IllegalArgumentException e) {
-            assertEquals("shortPrefix should be at least 1 character long",e.getMessage());
+        } catch (IllegalArgumentException e) {
+            assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX),
+                         e.getMessage());
         }
     }
 
@@ -66,12 +67,11 @@
      */
     public void testNew_NullLongPrefix() {
         try {
-            new DefaultOptionBuilder("-", null,
-                    false);
+            new DefaultOptionBuilder("-", null, false);
             fail("null long prefix is not permitted");
-        }
-        catch(IllegalArgumentException e) {
-            assertEquals("longPrefix should be at least 1 character long",e.getMessage());
+        } catch (IllegalArgumentException e) {
+            assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX),
+                         e.getMessage());
         }
     }
 
@@ -80,12 +80,11 @@
      */
     public void testNew_EmptyLongPrefix() {
         try {
-            new DefaultOptionBuilder("-", "",
-                    false);
+            new DefaultOptionBuilder("-", "", false);
             fail("empty long prefix is not permitted");
-        }
-        catch(IllegalArgumentException e) {
-            assertEquals("longPrefix should be at least 1 character long",e.getMessage());
+        } catch (IllegalArgumentException e) {
+            assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX),
+                         e.getMessage());
         }
     }
 
@@ -93,24 +92,17 @@
         try {
             this.defaultOptionBuilder.create();
             fail("options must have a name");
-        }
-        catch (IllegalStateException e) {
-            assertEquals("Options must have at least one name",e.getMessage());
-        }
-        
-        {
-            this.defaultOptionBuilder.withShortName("j");
-            this.defaultOptionBuilder.create();
-        }
-        
-        {
-            this.defaultOptionBuilder.withLongName("jkeyes");
-            this.defaultOptionBuilder.create();
+        } catch (IllegalStateException e) {
+            assertEquals(resources.getMessage(ResourceConstants.OPTION_NO_NAME), e.getMessage());
         }
 
+        this.defaultOptionBuilder.withShortName("j");
+        this.defaultOptionBuilder.create();
+        this.defaultOptionBuilder.withLongName("jkeyes");
+        this.defaultOptionBuilder.create();
+
         {
-            DefaultOptionBuilder builder = new DefaultOptionBuilder("-", "--",
-                    true);
+            DefaultOptionBuilder builder = new DefaultOptionBuilder("-", "--", true);
             builder.withShortName("mx");
         }
     }
@@ -121,28 +113,25 @@
             this.defaultOptionBuilder.withShortName("a");
             this.defaultOptionBuilder.withLongName("apples");
         }
-
         // withShortName && this.preferred != null
         {
             this.defaultOptionBuilder.withLongName("apples");
             this.defaultOptionBuilder.withShortName("a");
         }
-
         // withShortName && this.preferred != null
         {
             this.defaultOptionBuilder.withLongName("apples");
             this.defaultOptionBuilder.withShortName("a");
         }
-
     }
 
     public void testWithDescription() {
         String description = "desc";
         this.defaultOptionBuilder.withShortName("a");
         this.defaultOptionBuilder.withDescription(description);
+
         DefaultOption opt = this.defaultOptionBuilder.create();
-        assertEquals("wrong description found", description, 
-                opt.getDescription());
+        assertEquals("wrong description found", description, opt.getDescription());
     }
 
     public void testWithRequired() {
@@ -150,35 +139,35 @@
             boolean required = false;
             this.defaultOptionBuilder.withShortName("a");
             this.defaultOptionBuilder.withRequired(required);
+
             DefaultOption opt = this.defaultOptionBuilder.create();
-            assertEquals("wrong required found", required, 
-                    opt.isRequired());
+            assertEquals("wrong required found", required, opt.isRequired());
         }
 
         {
             boolean required = true;
             this.defaultOptionBuilder.withShortName("a");
             this.defaultOptionBuilder.withRequired(required);
+
             DefaultOption opt = this.defaultOptionBuilder.create();
-            assertEquals("wrong required found", required, 
-                    opt.isRequired());
+            assertEquals("wrong required found", required, opt.isRequired());
         }
-}
+    }
 
     public void testWithChildren() {
         GroupBuilder gbuilder = new GroupBuilder();
-        
+
         this.defaultOptionBuilder.withShortName("a");
         this.defaultOptionBuilder.withRequired(true);
+
         DefaultOption opt = this.defaultOptionBuilder.create();
 
-        Group group = 
-            gbuilder.withName("withchildren")
-                .withOption(opt)
-                .create();
+        Group group = gbuilder.withName("withchildren").withOption(opt).create();
+
         {
             this.defaultOptionBuilder.withShortName("b");
             this.defaultOptionBuilder.withChildren(group);
+
             DefaultOption option = this.defaultOptionBuilder.create();
             assertEquals("wrong children found", group, option.getChildren());
         }
@@ -187,11 +176,13 @@
     public void testWithArgument() {
         ArgumentBuilder abuilder = new ArgumentBuilder();
         abuilder.withName("myarg");
+
         Argument arg = abuilder.create();
-        
+
         this.defaultOptionBuilder.withShortName("a");
         this.defaultOptionBuilder.withRequired(true);
         this.defaultOptionBuilder.withArgument(arg);
+
         DefaultOption opt = this.defaultOptionBuilder.create();
 
         assertEquals("wrong argument found", arg, opt.getArgument());
@@ -200,9 +191,9 @@
     public void testWithId() {
         this.defaultOptionBuilder.withShortName("a");
         this.defaultOptionBuilder.withId(0);
+
         DefaultOption opt = this.defaultOptionBuilder.create();
 
         assertEquals("wrong id found", 0, opt.getId());
     }
-
 }

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=280462&r1=280461&r2=280462&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 Mon Sep 12 19:32:04 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2004 The Apache Software Foundation
+/*
+ * Copyright 2004-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.
@@ -30,101 +30,102 @@
  * To change the template for this generated type comment go to
  * Window - Preferences - Java - Code Generation - Code and Comments
  */
-public class DefaultingCommandLineTest extends CommandLineTestCase {
-	
-	private CommandLine first;
-	private CommandLine second;
-	
-	private Option inFirst = new DefaultOptionBuilder().withLongName("infirst").create(); 
-	private Option inBoth = new DefaultOptionBuilder().withLongName("inboth").create(); 
-	private Option inSecond = new DefaultOptionBuilder().withLongName("insecond").create(); 
-	
-	/* (non-Javadoc)
-	 * @see org.apache.commons.cli2.CommandLineTest#createCommandLine()
-	 */
-	protected final CommandLine createCommandLine() {
-		final WriteableCommandLine writeable = new WriteableCommandLineImpl(root,new ArrayList());
-		writeable.addOption(present);
-		writeable.addProperty("present","present property");
-		writeable.addSwitch(bool,true);
-		writeable.addValue(present,"present value");
-		writeable.addOption(multiple);
-		writeable.addValue(multiple,"value 1");
-		writeable.addValue(multiple,"value 2");
-		writeable.addValue(multiple,"value 3");
-		
-		final DefaultingCommandLine defaults = new DefaultingCommandLine();
-		defaults.appendCommandLine(writeable);
-		return defaults;
-	}
-	
-	public void setUp() throws Exception{
-		super.setUp();
-		
-		WriteableCommandLine writeable;
-		
-		writeable = new WriteableCommandLineImpl(root,new ArrayList());
-		writeable.addOption(inFirst);
-		writeable.addOption(inBoth);
-		writeable.addProperty("infirst","infirst first value");
-		writeable.addProperty("inboth","inboth first value");
-		writeable.addSwitch(inFirst,true);
-		writeable.addSwitch(inBoth,true);
-		writeable.addValue(inFirst,"infirst first value 1");
-		writeable.addValue(inFirst,"infirst first value 2");
-		writeable.addValue(inBoth,"inboth first value 1");
-		writeable.addValue(inBoth,"inboth first value 2");
-		first = writeable;
-		
-		writeable = new WriteableCommandLineImpl(root,new ArrayList());
-		writeable.addOption(inSecond);
-		writeable.addOption(inBoth);
-		writeable.addProperty("insecond","insecond second value");
-		writeable.addProperty("inboth","inboth second value");
-		writeable.addSwitch(inSecond,true);
-		writeable.addSwitch(inBoth,true);
-		writeable.addValue(inSecond,"insecond second value 1");
-		writeable.addValue(inSecond,"insecond second value 2");
-		writeable.addValue(inBoth,"inboth second value 1");
-		writeable.addValue(inBoth,"inboth second value 2");
-		second = writeable;
-	}
-	
-	public final void testAppendCommandLine() {
-		final DefaultingCommandLine defaults = new DefaultingCommandLine();
-		Iterator i;
-		
-		i = defaults.commandLines();
-		assertFalse(i.hasNext());
-		
-		defaults.appendCommandLine(first);
-		i = defaults.commandLines();
-		assertSame(first,i.next());
-		assertFalse(i.hasNext());
-		
-		defaults.appendCommandLine(second);
-		i = defaults.commandLines();
-		assertSame(first,i.next());
-		assertSame(second,i.next());
-		assertFalse(i.hasNext());
-	}
-	
-	public final void testInsertCommandLine() {
-		final DefaultingCommandLine defaults = new DefaultingCommandLine();
-		Iterator i;
-		
-		i = defaults.commandLines();
-		assertFalse(i.hasNext());
-		
-		defaults.insertCommandLine(0,first);
-		i = defaults.commandLines();
-		assertSame(first,i.next());
-		assertFalse(i.hasNext());
-		
-		defaults.insertCommandLine(0,second);
-		i = defaults.commandLines();
-		assertSame(second,i.next());
-		assertSame(first,i.next());
-		assertFalse(i.hasNext());
-	}
+public class DefaultingCommandLineTest
+    extends CommandLineTestCase {
+    private CommandLine first;
+    private CommandLine second;
+    private Option inFirst = new DefaultOptionBuilder().withLongName("infirst").create();
+    private Option inBoth = new DefaultOptionBuilder().withLongName("inboth").create();
+    private Option inSecond = new DefaultOptionBuilder().withLongName("insecond").create();
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.cli2.CommandLineTest#createCommandLine()
+     */
+    protected final CommandLine createCommandLine() {
+        final WriteableCommandLine writeable = new WriteableCommandLineImpl(root, new ArrayList());
+        writeable.addOption(present);
+        writeable.addProperty("present", "present property");
+        writeable.addSwitch(bool, true);
+        writeable.addValue(present, "present value");
+        writeable.addOption(multiple);
+        writeable.addValue(multiple, "value 1");
+        writeable.addValue(multiple, "value 2");
+        writeable.addValue(multiple, "value 3");
+
+        final DefaultingCommandLine defaults = new DefaultingCommandLine();
+        defaults.appendCommandLine(writeable);
+
+        return defaults;
+    }
+
+    public void setUp()
+        throws Exception {
+        super.setUp();
+
+        WriteableCommandLine writeable;
+
+        writeable = new WriteableCommandLineImpl(root, new ArrayList());
+        writeable.addOption(inFirst);
+        writeable.addOption(inBoth);
+        writeable.addProperty("infirst", "infirst first value");
+        writeable.addProperty("inboth", "inboth first value");
+        writeable.addSwitch(inFirst, true);
+        writeable.addSwitch(inBoth, true);
+        writeable.addValue(inFirst, "infirst first value 1");
+        writeable.addValue(inFirst, "infirst first value 2");
+        writeable.addValue(inBoth, "inboth first value 1");
+        writeable.addValue(inBoth, "inboth first value 2");
+        first = writeable;
+
+        writeable = new WriteableCommandLineImpl(root, new ArrayList());
+        writeable.addOption(inSecond);
+        writeable.addOption(inBoth);
+        writeable.addProperty("insecond", "insecond second value");
+        writeable.addProperty("inboth", "inboth second value");
+        writeable.addSwitch(inSecond, true);
+        writeable.addSwitch(inBoth, true);
+        writeable.addValue(inSecond, "insecond second value 1");
+        writeable.addValue(inSecond, "insecond second value 2");
+        writeable.addValue(inBoth, "inboth second value 1");
+        writeable.addValue(inBoth, "inboth second value 2");
+        second = writeable;
+    }
+
+    public final void testAppendCommandLine() {
+        final DefaultingCommandLine defaults = new DefaultingCommandLine();
+        Iterator i;
+
+        i = defaults.commandLines();
+        assertFalse(i.hasNext());
+
+        defaults.appendCommandLine(first);
+        i = defaults.commandLines();
+        assertSame(first, i.next());
+        assertFalse(i.hasNext());
+
+        defaults.appendCommandLine(second);
+        i = defaults.commandLines();
+        assertSame(first, i.next());
+        assertSame(second, i.next());
+        assertFalse(i.hasNext());
+    }
+
+    public final void testInsertCommandLine() {
+        final DefaultingCommandLine defaults = new DefaultingCommandLine();
+        Iterator i;
+
+        i = defaults.commandLines();
+        assertFalse(i.hasNext());
+
+        defaults.insertCommandLine(0, first);
+        i = defaults.commandLines();
+        assertSame(first, i.next());
+        assertFalse(i.hasNext());
+
+        defaults.insertCommandLine(0, second);
+        i = defaults.commandLines();
+        assertSame(second, i.next());
+        assertSame(first, i.next());
+        assertFalse(i.hasNext());
+    }
 }

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java Mon Sep 12 19:32:04 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2004 The Apache Software Foundation
+/*
+ * Copyright 2004-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.
@@ -22,9 +22,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 PreferencesCommandLineTest extends CommandLineTestCase {
 	

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java Mon Sep 12 19:32:04 2005
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright 2004-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,29 +22,27 @@
 
 /**
  * @author Rob Oxspring
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
  */
-public class PropertiesCommandLineTest extends CommandLineTestCase {
-	
-	private Properties props = null;
-	
-	/* (non-Javadoc)
-	 * @see org.apache.commons.cli2.CommandLineTest#createCommandLine()
-	 */
-	protected CommandLine createCommandLine() {
-		props = new Properties();
-		props.setProperty("--present","present value");
-		props.setProperty("--alsopresent","");
-		props.setProperty("--multiple","value 1|value 2|value 3");
-		props.setProperty("--bool","true");
-		
-		props.setProperty("present","present property");
-		return new PropertiesCommandLine(root,props,'|');
-	}
-	
-	public void testToMakeEclipseSpotTheTestCase(){
-		// nothing to test
-	}
+public class PropertiesCommandLineTest
+    extends CommandLineTestCase {
+    private Properties props = null;
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.cli2.CommandLineTest#createCommandLine()
+     */
+    protected CommandLine createCommandLine() {
+        props = new Properties();
+        props.setProperty("--present", "present value");
+        props.setProperty("--alsopresent", "");
+        props.setProperty("--multiple", "value 1|value 2|value 3");
+        props.setProperty("--bool", "true");
+
+        props.setProperty("present", "present property");
+
+        return new PropertiesCommandLine(root, props, '|');
+    }
+
+    public void testToMakeEclipseSpotTheTestCase() {
+        // nothing to test
+    }
 }

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java Mon Sep 12 19:32:04 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2004 The Apache Software Foundation
+/*
+ * Copyright 2004-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.
@@ -20,16 +20,16 @@
 import org.apache.commons.cli2.WriteableCommandLine;
 import org.apache.commons.cli2.WriteableCommandLineTestCase;
 
-public class WriteableCommandLineImplTest extends WriteableCommandLineTestCase {
+public class WriteableCommandLineImplTest
+    extends WriteableCommandLineTestCase {
+    /* (non-Javadoc)
+     * @see org.apache.commons.cli2.WriteableCommandLineTest#createWriteableCommandLine()
+     */
+    protected WriteableCommandLine createWriteableCommandLine() {
+        return new WriteableCommandLineImpl(root, new ArrayList());
+    }
 
-	/* (non-Javadoc)
-	 * @see org.apache.commons.cli2.WriteableCommandLineTest#createWriteableCommandLine()
-	 */
-	protected WriteableCommandLine createWriteableCommandLine() {
-		return new WriteableCommandLineImpl(root,new ArrayList());
-	}
-	
-	public void testToMakeEclipseSpotTheTestCase(){
-		// nothing to test
-	}
+    public void testToMakeEclipseSpotTheTestCase() {
+        // nothing to test
+    }
 }

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=280462&r1=280461&r2=280462&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 Mon Sep 12 19:32:04 2005
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright 2003-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,7 +40,7 @@
  */
 public class ArgumentTest extends ArgumentTestCase {
 
-    private ResourceHelper resources = ResourceHelper.getResourceHelper(ArgumentTest.class);
+    private ResourceHelper resources = ResourceHelper.getResourceHelper();
     
     public static Argument buildUsernameArgument() {
         return new ArgumentImpl(
@@ -163,7 +163,7 @@
                         0);
             } catch (IllegalArgumentException e) {
                 assertEquals(
-                        resources.getMessage("cli.error.minimum.exceeds.maximum"),
+                        resources.getMessage("Argument.minimum.exceeds.maximum"),
                         e.getMessage());
             }
         }
@@ -200,7 +200,7 @@
             }
             catch(IllegalArgumentException exp) {
                 assertEquals(
-                        resources.getMessage("cli.error.too.few.defaults"),
+                        resources.getMessage("Argument.too.few.defaults"),
                         exp.getMessage());
             }
         }
@@ -225,7 +225,7 @@
             }
             catch(IllegalArgumentException exp) {
                 assertEquals(
-                    resources.getMessage("cli.error.too.many.defaults"),
+                    resources.getMessage("Argument.too.many.defaults"),
                     exp.getMessage());
             }
         }



---------------------------------------------------------------------
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