commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject svn commit: r278640 - in /jakarta/commons/proper/cli/trunk/src: java/org/apache/commons/cli2/validation/ test/data/ test/org/apache/commons/cli2/validation/
Date Sun, 04 Sep 2005 22:59:17 GMT
Author: jkeyes
Date: Sun Sep  4 15:58:52 2005
New Revision: 278640

URL: http://svn.apache.org/viewcvs?rev=278640&view=rev
Log: (empty)

Added:
    jakarta/commons/proper/cli/trunk/src/test/data/
    jakarta/commons/proper/cli/trunk/src/test/data/hidden.txt
    jakarta/commons/proper/cli/trunk/src/test/data/readable.txt
    jakarta/commons/proper/cli/trunk/src/test/data/writable.txt
Modified:
    jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/EnumValidator.java
    jakarta/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/validation/NumberValidator.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java

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=278640&r1=278639&r2=278640&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
Sun Sep  4 15:58:52 2005
@@ -51,7 +51,7 @@
      * @param values The list of permitted values
      */
     public EnumValidator(final Set values) {
-        this.validValues = values;
+        setValidValues(values);
     }
 
     /**
@@ -113,7 +113,7 @@
      *
      * @param validValues The Set of valid argument values.
      */
-    public void setValidValues(Set validValues) {
+    protected void setValidValues(Set validValues) {
         this.validValues = validValues;
     }
 }

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=278640&r1=278639&r2=278640&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
Sun Sep  4 15:58:52 2005
@@ -101,18 +101,11 @@
     private Number maximum = null;
 
     /**
-     * Creates a new NumberValidator.
-     */
-    public NumberValidator() {
-        this(NumberFormat.getInstance());
-    }
-
-    /**
      * Creates a new NumberValidator based on the specified NumberFormat
      * @param format the format of numbers to accept
      */
     public NumberValidator(final NumberFormat format) {
-        this.format = format;
+        setFormat(format);
     }
 
     /**
@@ -124,7 +117,7 @@
      */
     public void validate(final List values) throws InvalidArgumentException {
         for (final ListIterator i = values.listIterator(); i.hasNext();) {
-            final String value = (String)i.next();
+            final String value = (String) i.next();
 
             final ParsePosition pp = new ParsePosition(0);
             final Number number = format.parse(value, pp);
@@ -157,7 +150,7 @@
      *
      * @param format the format being used to validate argument values against.
      */
-    public void setFormat(NumberFormat format) {
+    protected void setFormat(NumberFormat format) {
         this.format = format;
     }
     

Added: jakarta/commons/proper/cli/trunk/src/test/data/hidden.txt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/data/hidden.txt?rev=278640&view=auto
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/data/hidden.txt (added)
+++ jakarta/commons/proper/cli/trunk/src/test/data/hidden.txt Sun Sep  4 15:58:52 2005
@@ -0,0 +1 @@
+Hidden text file.

Added: jakarta/commons/proper/cli/trunk/src/test/data/readable.txt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/data/readable.txt?rev=278640&view=auto
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/data/readable.txt (added)
+++ jakarta/commons/proper/cli/trunk/src/test/data/readable.txt Sun Sep  4 15:58:52 2005
@@ -0,0 +1 @@
+Readable text file.

Added: jakarta/commons/proper/cli/trunk/src/test/data/writable.txt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/data/writable.txt?rev=278640&view=auto
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/data/writable.txt (added)
+++ jakarta/commons/proper/cli/trunk/src/test/data/writable.txt Sun Sep  4 15:58:52 2005
@@ -0,0 +1 @@
+Writable text file.

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java?rev=278640&r1=278639&r2=278640&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java
(original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java
Sun Sep  4 15:58:52 2005
@@ -149,7 +149,12 @@
 
     public void testFormats() throws InvalidArgumentException {
         final DateValidator validator = new DateValidator(formats);
-        assertEquals("date formats are incorrect", formats, validator.getFormats());
+        assertEquals("date format is incorrect", 
+                     ((SimpleDateFormat)formats.get(0)).toPattern(), 
+                     ((SimpleDateFormat)validator.getFormats()[0]).toPattern());
+        assertEquals("date format is incorrect", 
+                     ((SimpleDateFormat)formats.get(1)).toPattern(), 
+                     ((SimpleDateFormat)validator.getFormats()[1]).toPattern());
     }
 
     public void testMaximumBounds() throws InvalidArgumentException {

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java?rev=278640&r1=278639&r2=278640&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java
(original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java
Sun Sep  4 15:58:52 2005
@@ -27,20 +27,22 @@
     private final Set enumSet = new TreeSet(
             Arrays.asList(
                     new Object[]{"red", "green", "blue"}));
-    
+
     public void testValidate() throws InvalidArgumentException {
         final Object[] array = new Object[] { "red", "green"};
-        final List list = Arrays.asList(array);
-        final Validator validator = new EnumValidator(enumSet);
-
-        validator.validate(list);
+        {
+            final List list = Arrays.asList(array);        
+            final EnumValidator validator = new EnumValidator(enumSet);
+            assertEquals("valid values are incorrect", enumSet, validator.getValidValues());
+            validator.validate(list);
 
-        final Iterator i = list.iterator();
-        assertEquals("red", i.next());
-        assertEquals("green", i.next());
-        assertFalse(i.hasNext());
+            final Iterator i = list.iterator();
+            assertEquals("red", i.next());
+            assertEquals("green", i.next());
+            assertFalse(i.hasNext());
+        }
     }
-    
+
     public void testNonMember() {
         final Object[] array = new Object[] { "red", "pink"};
         final List list = Arrays.asList(array);

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java?rev=278640&r1=278639&r2=278640&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java
(original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java
Sun Sep  4 15:58:52 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.
@@ -22,6 +22,12 @@
 
 import junit.framework.TestCase;
 
+/**
+ * JUnit test case for NumberValidator.
+ *
+ * @author Rob Oxspring
+ * @author John Keyes
+ */
 public class NumberValidatorTest extends TestCase {
     
     public void testValidate_Number() throws InvalidArgumentException {
@@ -29,20 +35,22 @@
         
         final Object[] array = 
             new Object[] { 
-                format.format(1d), 
-                format.format(1.07d), 
-                format.format(-.45d)};
-        
-        final List list = Arrays.asList(array);
-        final Validator validator = NumberValidator.getNumberInstance();
+            format.format(1d), 
+            format.format(1.07d), 
+            format.format(-.45d)};
+
+        {
+            final List list = Arrays.asList(array);
+            final Validator validator = NumberValidator.getNumberInstance();
 
-        validator.validate(list);
+            validator.validate(list);
 
-        final Iterator i = list.iterator();
-        assertEquals(1d, ((Number)i.next()).doubleValue(), 0.0001);
-        assertEquals(1.07d, ((Number)i.next()).doubleValue(), 0.0001);
-        assertEquals(-.45d, ((Number)i.next()).doubleValue(), 0.0001);
-        assertFalse(i.hasNext());
+            final Iterator i = list.iterator();
+            assertEquals(1d, ((Number)i.next()).doubleValue(), 0.0001);
+            assertEquals(1.07d, ((Number)i.next()).doubleValue(), 0.0001);
+            assertEquals(-.45d, ((Number)i.next()).doubleValue(), 0.0001);
+            assertFalse(i.hasNext());
+        }
     }
 
     public void testValidate_Currency() throws InvalidArgumentException {
@@ -53,7 +61,9 @@
                 format.format(1.07),
                 format.format(-0.45)};
         final List list = Arrays.asList(array);
-        final Validator validator = NumberValidator.getCurrencyInstance();
+        
+        final NumberValidator validator = NumberValidator.getCurrencyInstance();
+        assertEquals("incorrect currency format", format, validator.getFormat());
 
         validator.validate(list);
 
@@ -118,7 +128,12 @@
         final Object[] array = new Object[] { "1", "107" };
         final List list = Arrays.asList(array);
         final NumberValidator validator = NumberValidator.getIntegerInstance();
-        validator.setMaximum(new Integer(100));
+        Integer max = new Integer(100);
+
+        validator.setMaximum(max);
+
+        assertTrue("no minimum set", validator.getMinimum() == null);
+        assertEquals("incorrect maximum value", max, validator.getMaximum());
 
         try {
             validator.validate(list);
@@ -133,7 +148,11 @@
         final Object[] array = new Object[] { "107", "1" };
         final List list = Arrays.asList(array);
         final NumberValidator validator = NumberValidator.getIntegerInstance();
-        validator.setMinimum(new Integer(100));
+        Integer min = new Integer(100);
+        validator.setMinimum(min);
+
+        assertTrue("no maximum set", validator.getMaximum() == null);
+        assertEquals("incorrect minimum value", min, validator.getMinimum());
 
         try {
             validator.validate(list);



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