commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r370397 [3/4] - in /jakarta/commons/proper/validator/trunk: ./ src/share/org/apache/commons/validator/routines/ src/test/org/apache/commons/validator/routines/
Date Thu, 19 Jan 2006 06:38:52 GMT
Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,228 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import junit.framework.TestCase;
+import java.util.Date;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Base Calendar Test Case.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class BaseCalendarValidatorTest extends TestCase {
+
+    protected AbstractCalendarValidator validator;
+
+    protected static final TimeZone GMT = TimeZone.getTimeZone("GMT"); // 0 offset
+    protected static final TimeZone EST = TimeZone.getTimeZone("EST"); // - 5 hours
+    protected static final TimeZone EET = TimeZone.getTimeZone("EET"); // + 2 hours
+
+    protected String[] patternValid = new String[] {
+                       "2005-01-01" 
+                      ,"2005-12-31"
+                      ,"2004-02-29"    // valid leap
+                      ,"2005-04-30" 
+                      ,"05-12-31"
+                      ,"2005-1-1"
+                      ,"05-1-1"};
+    protected String[] localeValid = new String[] {
+                       "01/01/2005" 
+                      ,"12/31/2005"
+                      ,"02/29/2004"    // valid leap
+                      ,"04/30/2005" 
+                      ,"12/31/05"
+                      ,"1/1/2005"
+                      ,"1/1/05"};
+    protected Date[] patternExpect = new Date[] {
+                      createDate(null, 20050101, 0)
+                     ,createDate(null, 20051231, 0)
+                     ,createDate(null, 20040229, 0)
+                     ,createDate(null, 20050430, 0)
+                     ,createDate(null, 20051231, 0)
+                     ,createDate(null, 20050101, 0)
+                     ,createDate(null, 20050101, 0)};
+    protected String[] patternInvalid = new String[] {
+                         "2005-00-01"  // zero month
+                        ,"2005-01-00"  // zero day 
+                        ,"2005-13-03"  // month invalid
+                        ,"2005-04-31"  // invalid day 
+                        ,"2005-03-32"  // invalid day 
+                        ,"2005-02-29"  // invalid leap
+                        ,"200X-01-01"  // invalid char
+                        ,"2005-0X-01"  // invalid char
+                        ,"2005-01-0X"  // invalid char
+                        ,"01/01/2005"  // invalid pattern
+                        ,"2005-01"     // invalid pattern
+                        ,"2005--01"    // invalid pattern
+                        ,"2005-01-"};  // invalid pattern
+    protected String[] localeInvalid = new String[] {
+                         "01/00/2005"  // zero month
+                        ,"00/01/2005"  // zero day 
+                        ,"13/01/2005"  // month invalid
+                        ,"04/31/2005"  // invalid day 
+                        ,"03/32/2005"  // invalid day 
+                        ,"02/29/2005"  // invalid leap
+                        ,"01/01/200X"  // invalid char
+                        ,"01/0X/2005"  // invalid char
+                        ,"0X/01/2005"  // invalid char
+                        ,"01-01-2005"  // invalid pattern
+                        ,"01/2005"     // invalid pattern
+       // --------      ,"/01/2005"    ---- passes on some JDK
+                        ,"01//2005"};  // invalid pattern
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public BaseCalendarValidatorTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Set Up.
+     * @throws Exception
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    /**
+     * Tear down
+     * @throws Exception
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        validator = null;
+    }
+
+    /**
+     * Test Valid Dates with "pattern" validation
+     */
+    public void testPatternValid() {
+        for (int i = 0; i < patternValid.length; i++) {
+            String text = i + " value=[" +patternValid[i]+"] failed ";
+            Object date = validator.validateObj(patternValid[i], "yy-MM-dd");
+            assertNotNull("validateObj() " + text + date,  date);
+            assertTrue("isValid() " + text,  validator.isValid(patternValid[i], "yy-MM-dd"));
+            if (date instanceof Calendar) {
+                date = ((Calendar)date).getTime();
+            }
+            assertEquals("compare " + text, patternExpect[i], date);
+        }
+    }
+
+    /**
+     * Test Invalid Dates with "pattern" validation
+     */
+    public void testPatternInvalid() {
+        for (int i = 0; i < patternInvalid.length; i++) {
+            String text = i + " value=[" +patternInvalid[i]+"] passed ";
+            Object date = validator.validateObj(patternInvalid[i], "yy-MM-dd");
+            assertNull("validateObj() " + text + date,  date);
+            assertFalse("isValid() " + text,  validator.isValid(patternInvalid[i], "yy-MM-dd"));
+        }
+    }
+
+    /**
+     * Test Valid Dates with "locale" validation
+     */
+    public void testLocaleValid() {
+        for (int i = 0; i < localeValid.length; i++) {
+            String text = i + " value=[" +localeValid[i]+"] failed ";
+            Object date = validator.validateObj(localeValid[i], Locale.US);
+            assertNotNull("validateObj() " + text + date,  date);
+            assertTrue("isValid() " + text,  validator.isValid(localeValid[i], Locale.US));
+            if (date instanceof Calendar) {
+                date = ((Calendar)date).getTime();
+            }
+            assertEquals("compare " + text, patternExpect[i], date);
+        }
+    }
+
+    /**
+     * Test Invalid Dates with "locale" validation
+     */
+    public void testLocaleInvalid() {
+        for (int i = 0; i < localeInvalid.length; i++) {
+            String text = i + " value=[" +localeInvalid[i]+"] passed ";
+            Object date = validator.validateObj(localeInvalid[i], Locale.US);
+            assertNull("validateObj() " + text + date,  date);
+            assertFalse("isValid() " + text,  validator.isValid(localeInvalid[i], Locale.US));
+        }
+    }
+
+    /**
+     * Test Invalid Dates with "locale" validation
+     */
+    public void testFormat() {
+
+        // Create a Date or Calendar
+        Object test = validator.validateObj("2005-11-28", "yyyy-MM-dd");
+        assertNotNull("Test Date ", test);
+        assertEquals("Format pattern", "28.11.05", validator.format(test, "dd.MM.yy"));
+        assertEquals("Format locale",  "11/28/05", validator.format(test, Locale.US));
+    }
+
+    /**
+     * Create a calendar instance for a specified time zone, date and time.
+     * 
+     * @param zone The time zone
+     * @param date The date in yyyyMMdd format
+     * @param time the time in HH:mm:ss format
+     * @return the new Calendar instance.
+     */
+    protected static Calendar createCalendar(TimeZone zone, int date, int time) {
+        Calendar calendar = zone == null ? Calendar.getInstance()
+                                         : Calendar.getInstance(zone);
+        int year = ((date / 10000) * 10000);
+        int mth  = ((date / 100) * 100) - year;
+        int day = date - (year + mth);
+        int hour = ((time / 10000) * 10000);
+        int min  = ((time / 100) * 100) - hour;
+        int sec  = time - (hour + min);
+        calendar.set(Calendar.YEAR,  (year / 10000));
+        calendar.set(Calendar.MONTH, ((mth / 100) - 1));
+        calendar.set(Calendar.DATE,  day);
+        calendar.set(Calendar.HOUR_OF_DAY,  (hour / 10000));
+        calendar.set(Calendar.MINUTE, (min / 100));
+        calendar.set(Calendar.SECOND,  sec);
+        calendar.set(Calendar.MILLISECOND,  0);
+        return calendar;
+    }
+
+    /**
+     * Create a date instance for a specified time zone, date and time.
+     * 
+     * @param zone The time zone
+     * @param date The date in yyyyMMdd format
+     * @param time the time in HH:mm:ss format
+     * @return the new Date instance.
+     */
+    protected static Date createDate(TimeZone zone, int date, int time) {
+        Calendar calendar = createCalendar(zone, date, time);
+        return calendar.getTime();
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,207 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+import java.text.DecimalFormat;
+import java.math.BigDecimal;
+/**
+ * Base Number Test Case.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class BaseNumberValidatorTest extends TestCase {
+
+    protected AbstractNumberValidator validator;
+    protected AbstractNumberValidator strictValidator;
+
+    protected Number max;
+    protected Number maxPlusOne;
+    protected Number min;
+    protected Number minMinusOne;
+    protected String[] invalid;
+    protected String[] valid;
+    protected Number[] validCompare;
+
+    protected String[] invalidStrict;
+    protected String[] validStrict;
+    protected Number[] validStrictCompare;
+
+    protected String testPattern;
+    protected Number testNumber;
+    protected Number testZero;
+    protected String testStringUS;
+    protected String testStringDE;
+
+    protected String localeValue;
+    protected String localePattern;
+    protected Locale testLocale;
+    protected Number localeExpected;
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public BaseNumberValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        Locale.setDefault(Locale.US);
+
+    }
+
+    /**
+     * Tear down
+     * @throws Exception
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        validator = null;
+        strictValidator = null;
+    }
+
+    /**
+     * Test Min/Max values allowed
+     */
+    public void testValidateMinMax() {
+        DecimalFormat fmt = new DecimalFormat("#");
+        if (max != null) {
+            assertEquals("Test Max",   max, validator.validateObj(fmt.format(max)));
+            assertNull("Test Max + 1",      validator.validateObj(fmt.format(maxPlusOne)));
+            assertEquals("Test Min",   min, validator.validateObj(fmt.format(min)));
+            assertNull("Test min - 1",      validator.validateObj(fmt.format(minMinusOne)));
+        }
+    }
+
+    /**
+     * Test Invalid, strict=true
+     */
+    public void testInvalidStrict() {
+        for (int i = 0; i < invalidStrict.length; i++) {
+            String text = "idx=["+i+"] value=[" + invalidStrict[i] + "]";
+            assertNull("(A) "  + text, strictValidator.validateObj(invalidStrict[i], Locale.US));
+            assertFalse("(B) " + text, strictValidator.isValid(invalidStrict[i], Locale.US));
+            assertNull("(C) "  + text, strictValidator.validateObj(invalidStrict[i], testPattern));
+            assertFalse("(D) " + text, strictValidator.isValid(invalidStrict[i], testPattern));
+        }
+    }
+
+    /**
+     * Test Invalid, strict=false
+     */
+    public void testInvalidNotStrict() {
+        for (int i = 0; i < invalid.length; i++) {
+            String text = "idx=["+i+"] value=[" + invalid[i] + "]";
+            assertNull("(A) "  + text, validator.validateObj(invalid[i], Locale.US));
+            assertFalse("(B) " + text, validator.isValid(invalid[i], Locale.US));
+            assertNull("(C) "  + text, validator.validateObj(invalid[i], testPattern));
+            assertFalse("(D) " + text, validator.isValid(invalid[i], testPattern));
+        }
+    }
+
+    /**
+     * Test Valid, strict=true
+     */
+    public void testValidStrict() {
+        for (int i = 0; i < validStrict.length; i++) {
+            String text = "idx=["+i+"] value=[" + validStrictCompare[i] + "]";
+            assertEquals("(A) "  + text, validStrictCompare[i], strictValidator.validateObj(validStrict[i], Locale.US));
+            assertTrue("(B) "    + text,                        strictValidator.isValid(validStrict[i], Locale.US));
+            assertEquals("(C) "  + text, validStrictCompare[i], strictValidator.validateObj(validStrict[i], testPattern));
+            assertTrue("(D) "    + text,                        strictValidator.isValid(validStrict[i], testPattern));
+        }
+    }
+
+    /**
+     * Test Valid, strict=false
+     */
+    public void testValidNotStrict() {
+        for (int i = 0; i < valid.length; i++) {
+            String text = "idx=["+i+"] value=[" + validCompare[i] + "]";
+            assertEquals("(A) "  + text, validCompare[i], validator.validateObj(valid[i], Locale.US));
+            assertTrue("(B) "    + text,                  validator.isValid(valid[i], Locale.US));
+            assertEquals("(C) "  + text, validCompare[i], validator.validateObj(valid[i], testPattern));
+            assertTrue("(D) "    + text,                  validator.isValid(valid[i], testPattern));
+        }
+    }
+
+    /**
+     * Test different Locale
+     */
+    public void testValidateLocale() {
+
+        assertEquals("US Locale, US Format", testNumber, strictValidator.validateObj(testStringUS, Locale.US));
+        assertNull("US Locale, DE Format", strictValidator.validateObj(testStringDE, Locale.US));
+
+        // Default German Locale
+        assertEquals("DE Locale, DE Format", testNumber, strictValidator.validateObj(testStringDE, Locale.GERMAN));
+        assertNull("DE Locale, US Format", strictValidator.validateObj(testStringUS, Locale.GERMAN));
+
+        // Default Locale has been set to Locale.US in setup()
+        assertEquals("Default Locale, US Format", testNumber, strictValidator.validateObj(testStringUS));
+        assertNull("Default Locale, DE Format", strictValidator.validateObj(testStringDE));
+    }
+
+    /**
+     * Test format() methods
+     */
+    public void testFormat() {
+        Number number = new BigDecimal("1234.5");
+        assertEquals("US Locale, US Format", "1,234.5", strictValidator.format(number, Locale.US));
+        assertEquals("DE Locale, DE Format", "1.234,5", strictValidator.format(number, Locale.GERMAN));
+        assertEquals("Pattern #,#0.00", "12,34.50",  strictValidator.format(number, "#,#0.00"));
+    }
+
+    /**
+     * Test Range/Min/Max
+     */
+    public void testRangeMinMax() {
+        Number number9 = new Integer(9);
+        Number number10 = new Integer(10);
+        Number number11 = new Integer(11);
+        Number number19 = new Integer(19);
+        Number number20 = new Integer(20);
+        Number number21 = new Integer(21);
+
+        // Test isInRange()
+        assertFalse("isInRange() < min",   strictValidator.isInRange(number9 ,  number10, number20));
+        assertTrue("isInRange() = min",    strictValidator.isInRange(number10 , number10, number20));
+        assertTrue("isInRange() in range", strictValidator.isInRange(number11 , number10, number20));
+        assertTrue("isInRange() = max",    strictValidator.isInRange(number20 , number10, number20));
+        assertFalse("isInRange() > max",   strictValidator.isInRange(number21 , number10, number20));
+
+        // Test minValue()
+        assertFalse("minValue() < min",    strictValidator.minValue(number9 ,  number10));
+        assertTrue("minValue() = min",     strictValidator.minValue(number10 , number10));
+        assertTrue("minValue() > min",     strictValidator.minValue(number11 , number10));
+
+        // Test minValue()
+        assertTrue("maxValue() < max",     strictValidator.maxValue(number19 , number20));
+        assertTrue("maxValue() = max",     strictValidator.maxValue(number20 , number20));
+        assertFalse("maxValue() > max",    strictValidator.maxValue(number21 , number20));
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,147 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+
+/**
+ * Test Case for BigDecimalValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class BigDecimalValidatorTest extends BaseNumberValidatorTest {
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(BigDecimalValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public BigDecimalValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        validator       = new BigDecimalValidator(false);
+        strictValidator = new BigDecimalValidator(true);
+
+        testPattern = "#,###.###";
+
+        // testValidateMinMax()
+        max = null;
+        maxPlusOne = null;
+        min = null;
+        minMinusOne = null;
+
+        // testInvalidStrict()
+        invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.234X"};
+
+        // testInvalidNotStrict()
+        invalid       = new String[] {null, "", "X", "X12"};
+
+        // testValid()
+        testNumber    = new BigDecimal("1234.5");
+        Number testNumber2 = new BigDecimal(".1");
+        Number testNumber3 = new BigDecimal("12345.67899");
+        testZero      = new BigDecimal("0");
+        validStrict          = new String[] {"0", "1234.5", "1,234.5", ".1", "12345.678990"};
+        validStrictCompare   = new Number[] {testZero, testNumber, testNumber, testNumber2, testNumber3};
+        valid                = new String[] {"0", "1234.5", "1,234.5", "1,234.5", "1234.5X"};
+        validCompare         = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+        testStringUS = "1,234.5";
+        testStringDE = "1.234,5";
+
+        // Localized Pattern test
+        localeValue = testStringDE;
+        localePattern = "#.###,#";
+        testLocale    = Locale.GERMANY;
+        localeExpected = testNumber;
+
+    }
+
+    /**
+     * Test BigDecimalValidator validate Methods
+     */
+    public void testBigDecimalValidatorMethods() {
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "0,00,00";
+        String patternVal = "1,23,45";
+        String localeVal  = "12.345";
+        String defaultVal = "12,345";
+        String XXXX    = "XXXX"; 
+        BigDecimal expected = new BigDecimal(12345);
+        assertEquals("validate(A) default", expected, BigDecimalValidator.getInstance().validate(defaultVal));
+        assertEquals("validate(A) locale ", expected, BigDecimalValidator.getInstance().validate(localeVal, locale));
+        assertEquals("validate(A) pattern", expected, BigDecimalValidator.getInstance().validate(patternVal, pattern));
+
+        assertTrue("isValid(A) default", BigDecimalValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", BigDecimalValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", BigDecimalValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", BigDecimalValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", BigDecimalValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", BigDecimalValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", BigDecimalValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", BigDecimalValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", BigDecimalValidator.getInstance().isValid(XXXX, pattern));
+    }
+
+    /**
+     * Test BigDecimal Range/Min/Max
+     */
+    public void testBigDecimalRangeMinMax() {
+        BigDecimalValidator validator = (BigDecimalValidator)strictValidator;
+        BigDecimal number9  = validator.validate("9", "#");
+        BigDecimal number10 = validator.validate("10", "#");
+        BigDecimal number11 = validator.validate("11", "#");
+        BigDecimal number19 = validator.validate("19", "#");
+        BigDecimal number20 = validator.validate("20", "#");
+        BigDecimal number21 = validator.validate("21", "#");
+
+        // Test isInRange()
+        assertFalse("isInRange() < min",   validator.isInRange(number9,  10, 20));
+        assertTrue("isInRange() = min",    validator.isInRange(number10, 10, 20));
+        assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+        assertTrue("isInRange() = max",    validator.isInRange(number20, 10, 20));
+        assertFalse("isInRange() > max",   validator.isInRange(number21, 10, 20));
+
+        // Test minValue()
+        assertFalse("minValue() < min",    validator.minValue(number9,  10));
+        assertTrue("minValue() = min",     validator.minValue(number10, 10));
+        assertTrue("minValue() > min",     validator.minValue(number11, 10));
+
+        // Test minValue()
+        assertTrue("maxValue() < max",     validator.maxValue(number19, 20));
+        assertTrue("maxValue() = max",     validator.maxValue(number20, 20));
+        assertFalse("maxValue() > max",    validator.maxValue(number21, 20));
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,145 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.math.BigInteger;
+import java.util.Locale;
+
+/**
+ * Test Case for BigIntegerValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class BigIntegerValidatorTest extends BaseNumberValidatorTest {
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(BigIntegerValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public BigIntegerValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        validator       = new BigIntegerValidator(false);
+        strictValidator = new BigIntegerValidator(true);
+
+        testPattern = "#,###";
+
+        // testValidateMinMax()
+        max =  null;
+        maxPlusOne = null;
+        min = null;
+        minMinusOne = null;
+
+        // testInvalidStrict()
+        invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2"};
+
+        // testInvalidNotStrict()
+        invalid       = new String[] {null, "", "X", "X12"};
+
+        // testValid()
+        testNumber    = new BigInteger("1234");
+        testZero      = new BigInteger("0");
+        validStrict          = new String[] {"0", "1234", "1,234"};
+        validStrictCompare   = new Number[] {testZero, testNumber, testNumber};
+        valid                = new String[] {"0", "1234", "1,234", "1,234.5", "1234X"};
+        validCompare         = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+        testStringUS = "1,234";
+        testStringDE = "1.234";
+
+        // Localized Pattern test
+        localeValue = testStringDE;
+        localePattern = "#.###";
+        testLocale    = Locale.GERMANY;
+        localeExpected = testNumber;
+
+    }
+
+    /**
+     * Test BigIntegerValidator validate Methods
+     */
+    public void testBigIntegerValidatorMethods() {
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "0,00,00";
+        String patternVal = "1,23,45";
+        String localeVal  = "12.345";
+        String defaultVal = "12,345";
+        String XXXX    = "XXXX"; 
+        BigInteger expected = new BigInteger("12345");
+        assertEquals("validate(A) default", expected, BigIntegerValidator.getInstance().validate(defaultVal));
+        assertEquals("validate(A) locale ", expected, BigIntegerValidator.getInstance().validate(localeVal, locale));
+        assertEquals("validate(A) pattern", expected, BigIntegerValidator.getInstance().validate(patternVal, pattern));
+
+        assertTrue("isValid(A) default", BigIntegerValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", BigIntegerValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", BigIntegerValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", BigIntegerValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", BigIntegerValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", BigIntegerValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", BigIntegerValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", BigIntegerValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", BigIntegerValidator.getInstance().isValid(XXXX, pattern));
+    }
+
+    /**
+     * Test BigInteger Range/Min/Max
+     */
+    public void testBigIntegerRangeMinMax() {
+        BigIntegerValidator validator = (BigIntegerValidator)strictValidator;
+        BigInteger number9  = validator.validate("9", "#");
+        BigInteger number10 = validator.validate("10", "#");
+        BigInteger number11 = validator.validate("11", "#");
+        BigInteger number19 = validator.validate("19", "#");
+        BigInteger number20 = validator.validate("20", "#");
+        BigInteger number21 = validator.validate("21", "#");
+
+        // Test isInRange()
+        assertFalse("isInRange() < min",   validator.isInRange(number9,  10, 20));
+        assertTrue("isInRange() = min",    validator.isInRange(number10, 10, 20));
+        assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+        assertTrue("isInRange() = max",    validator.isInRange(number20, 10, 20));
+        assertFalse("isInRange() > max",   validator.isInRange(number21, 10, 20));
+
+        // Test minValue()
+        assertFalse("minValue() < min",    validator.minValue(number9,  10));
+        assertTrue("minValue() = min",     validator.minValue(number10, 10));
+        assertTrue("minValue() > min",     validator.minValue(number11, 10));
+
+        // Test minValue()
+        assertTrue("maxValue() < max",     validator.maxValue(number19, 20));
+        assertTrue("maxValue() = max",     validator.maxValue(number20, 20));
+        assertFalse("maxValue() > max",    validator.maxValue(number21, 20));
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,146 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * Test Case for ByteValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class ByteValidatorTest extends BaseNumberValidatorTest {
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(ByteValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public ByteValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        validator       = new ByteValidator(false);
+        strictValidator = new ByteValidator(true);
+
+        testPattern = "#,###";
+
+        // testValidateMinMax()
+        max = new Byte(Byte.MAX_VALUE);
+        maxPlusOne = new Long(max.longValue() + 1);
+        min = new Byte(Byte.MIN_VALUE);
+        minMinusOne = new Long(min.longValue() - 1);
+
+        // testInvalidStrict()
+        invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2"};
+
+        // testInvalidNotStrict()
+        invalid       = new String[] {null, "", "X", "X12"};
+
+        // testValid()
+        testNumber    = new Byte((byte)123);
+        testZero      = new Byte((byte)0);
+        validStrict          = new String[] {"0", "123", ",123"};
+        validStrictCompare   = new Number[] {testZero, testNumber, testNumber};
+        valid                = new String[] {"0", "123", ",123", ",123.5", "123X"};
+        validCompare         = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+        testStringUS = ",123";
+        testStringDE = ".123";
+
+        // Localized Pattern test
+        localeValue = testStringDE;
+        localePattern = "#.###";
+        testLocale    = Locale.GERMANY;
+        localeExpected = testNumber;
+
+    }
+
+    /**
+     * Test ByteValidator validate Methods
+     */
+    public void testByteValidatorMethods() {
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "0,00";
+        String patternVal = "1,23";
+        String localeVal  = ".123";
+        String defaultVal = ",123";
+        String XXXX    = "XXXX"; 
+        Byte expected = new Byte((byte)123);
+        assertEquals("validate(A) default", expected, ByteValidator.getInstance().validate(defaultVal));
+        assertEquals("validate(A) locale ", expected, ByteValidator.getInstance().validate(localeVal, locale));
+        assertEquals("validate(A) pattern", expected, ByteValidator.getInstance().validate(patternVal, pattern));
+
+        assertTrue("isValid(A) default", ByteValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", ByteValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", ByteValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", ByteValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", ByteValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", ByteValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", ByteValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", ByteValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", ByteValidator.getInstance().isValid(XXXX, pattern));
+    }
+
+    /**
+     * Test Byte Range/Min/Max
+     */
+    public void testByteRangeMinMax() {
+        ByteValidator validator = (ByteValidator)strictValidator;
+        Byte number9  = validator.validate("9", "#");
+        Byte number10 = validator.validate("10", "#");
+        Byte number11 = validator.validate("11", "#");
+        Byte number19 = validator.validate("19", "#");
+        Byte number20 = validator.validate("20", "#");
+        Byte number21 = validator.validate("21", "#");
+        byte min = (byte)10;
+        byte max = (byte)20;
+
+        // Test isInRange()
+        assertFalse("isInRange() < min",   validator.isInRange(number9,  min, max));
+        assertTrue("isInRange() = min",    validator.isInRange(number10, min, max));
+        assertTrue("isInRange() in range", validator.isInRange(number11, min, max));
+        assertTrue("isInRange() = max",    validator.isInRange(number20, min, max));
+        assertFalse("isInRange() > max",   validator.isInRange(number21, min, max));
+
+        // Test minValue()
+        assertFalse("minValue() < min",    validator.minValue(number9,  min));
+        assertTrue("minValue() = min",     validator.minValue(number10, min));
+        assertTrue("minValue() > min",     validator.minValue(number11, min));
+
+        // Test minValue()
+        assertTrue("maxValue() < max",     validator.maxValue(number19, max));
+        assertTrue("maxValue() = max",     validator.maxValue(number20, max));
+        assertFalse("maxValue() > max",    validator.maxValue(number21, max));
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CalendarValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CalendarValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CalendarValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CalendarValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,208 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Test Case for CalendarValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class CalendarValidatorTest extends BaseCalendarValidatorTest {
+    
+    private static final int DATE_2005_11_23 = 20051123;
+    private static final int TIME_12_03_45   = 120345;
+
+    private CalendarValidator calendarValidator;
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(CalendarValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public CalendarValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        calendarValidator = new CalendarValidator();
+        validator         = calendarValidator;
+    }
+
+    /**
+     * Test CalendarValidator validate Methods
+     */
+    public void testCalendarValidatorMethods() {
+        Locale.setDefault(Locale.US);
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "yyyy-MM-dd";
+        String patternVal = "2005-12-31";
+        String localeVal  = "31.12.2005";
+        String defaultVal = "12/31/05";
+        String XXXX    = "XXXX"; 
+        Date expected = createCalendar(null, 20051231, 0).getTime();
+        assertEquals("validate(A) default", expected, CalendarValidator.getInstance().validate(defaultVal).getTime());
+        assertEquals("validate(A) locale ", expected, CalendarValidator.getInstance().validate(localeVal, locale).getTime());
+        assertEquals("validate(A) pattern", expected, CalendarValidator.getInstance().validate(patternVal, pattern).getTime());
+
+        assertTrue("isValid(A) default", CalendarValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", CalendarValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", CalendarValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", CalendarValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", CalendarValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", CalendarValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", CalendarValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", CalendarValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", CalendarValidator.getInstance().isValid(XXXX, pattern));
+
+        // Test Time Zone
+        TimeZone zone = (TimeZone.getDefault().getRawOffset() == EET.getRawOffset() ? EST : EET); 
+        Date expectedZone = createCalendar(zone, 20051231, 0).getTime();
+        assertFalse("default/EET same ", expected.getTime() == expectedZone.getTime());
+
+        assertEquals("validate(C) default", expectedZone, CalendarValidator.getInstance().validate(defaultVal, zone).getTime());
+        assertEquals("validate(C) locale ", expectedZone, CalendarValidator.getInstance().validate(localeVal, locale, zone).getTime());
+        assertEquals("validate(C) pattern", expectedZone, CalendarValidator.getInstance().validate(patternVal, pattern, zone).getTime());
+    }
+
+    /**
+     * Test compare date methods
+     */
+    public void testCompare() {
+        int sameTime = 124522;
+        int testDate = 20050823;
+        Calendar diffHour    = createCalendar(GMT, testDate, 115922);    // same date, different time
+        Calendar diffMin     = createCalendar(GMT, testDate, 124422);    // same date, different time
+        Calendar diffSec     = createCalendar(GMT, testDate, 124521);    // same date, different time
+
+        Calendar value       = createCalendar(GMT, testDate, sameTime);   // test value
+        Calendar cal20050824 = createCalendar(GMT, 20050824, sameTime);   // +1 day
+        Calendar cal20050822 = createCalendar(GMT, 20050822, sameTime);   // -1 day
+
+        Calendar cal20050830 = createCalendar(GMT, 20050830, sameTime);   // +1 week
+        Calendar cal20050816 = createCalendar(GMT, 20050816, sameTime);   // -1 week
+
+        Calendar cal20050901 = createCalendar(GMT, 20050901, sameTime);   // +1 month
+        Calendar cal20050801 = createCalendar(GMT, 20050801, sameTime);   // same month
+        Calendar cal20050731 = createCalendar(GMT, 20050731, sameTime);   // -1 month
+
+        Calendar cal20051101 = createCalendar(GMT, 20051101, sameTime);   // +1 quarter (Feb Start)
+        Calendar cal20051001 = createCalendar(GMT, 20051001, sameTime);   // +1 quarter
+        Calendar cal20050701 = createCalendar(GMT, 20050701, sameTime);   // same quarter
+        Calendar cal20050630 = createCalendar(GMT, 20050630, sameTime);   // -1 quarter
+
+        Calendar cal20060101 = createCalendar(GMT, 20060101, sameTime);   // +1 year
+        Calendar cal20050101 = createCalendar(GMT, 20050101, sameTime);   // same year
+        Calendar cal20041231 = createCalendar(GMT, 20041231, sameTime);   // -1 year
+
+        assertEquals("hour GT", 1, calendarValidator.compare(value, diffHour, Calendar.HOUR_OF_DAY));
+        assertEquals("hour EQ", 0, calendarValidator.compare(value, diffMin,  Calendar.HOUR_OF_DAY));
+        assertEquals("mins GT", 1, calendarValidator.compare(value, diffMin,  Calendar.MINUTE));
+        assertEquals("mins EQ", 0, calendarValidator.compare(value, diffSec,  Calendar.MINUTE));
+        assertEquals("secs GT", 1, calendarValidator.compare(value, diffSec,  Calendar.SECOND));
+
+        assertEquals("date LT", -1, calendarValidator.compareDates(value, cal20050824)); // +1 day
+        assertEquals("date EQ", 0,  calendarValidator.compareDates(value, diffHour));    // same day, diff hour
+        assertEquals("date GT", 1,  calendarValidator.compareDates(value, cal20050822)); // -1 day
+
+        assertEquals("week LT", -1, calendarValidator.compareWeeks(value, cal20050830)); // +1 week 
+        assertEquals("week =1", 0,  calendarValidator.compareWeeks(value, cal20050824)); // +1 day
+        assertEquals("week =2", 0,  calendarValidator.compareWeeks(value, cal20050822)); // same week
+        assertEquals("week =3", 0,  calendarValidator.compareWeeks(value, cal20050822)); // -1 day
+        assertEquals("week GT", 1,  calendarValidator.compareWeeks(value, cal20050816)); // -1 week
+
+        assertEquals("mnth LT", -1, calendarValidator.compareMonths(value, cal20050901)); // +1 month 
+        assertEquals("mnth =1", 0,  calendarValidator.compareMonths(value, cal20050830)); // +1 week 
+        assertEquals("mnth =2", 0,  calendarValidator.compareMonths(value, cal20050801)); // same month
+        assertEquals("mnth =3", 0,  calendarValidator.compareMonths(value, cal20050816)); // -1 week
+        assertEquals("mnth GT", 1,  calendarValidator.compareMonths(value, cal20050731)); // -1 month
+
+        assertEquals("qtrA <1", -1, calendarValidator.compareQuarters(value, cal20051101)); // +1 quarter (Feb) 
+        assertEquals("qtrA <2", -1, calendarValidator.compareQuarters(value, cal20051001)); // +1 quarter 
+        assertEquals("qtrA =1", 0,  calendarValidator.compareQuarters(value, cal20050901)); // +1 month 
+        assertEquals("qtrA =2", 0,  calendarValidator.compareQuarters(value, cal20050701)); // same quarter
+        assertEquals("qtrA =3", 0,  calendarValidator.compareQuarters(value, cal20050731)); // -1 month
+        assertEquals("qtrA GT", 1,  calendarValidator.compareQuarters(value, cal20050630)); // -1 quarter
+
+        // Change quarter 1 to start in Feb
+        assertEquals("qtrB LT", -1, calendarValidator.compareQuarters(value, cal20051101, 2)); // +1 quarter (Feb) 
+        assertEquals("qtrB =1", 0,  calendarValidator.compareQuarters(value, cal20051001, 2));  // same quarter 
+        assertEquals("qtrB =2", 0,  calendarValidator.compareQuarters(value, cal20050901, 2)); // +1 month 
+        assertEquals("qtrB =3", 1,  calendarValidator.compareQuarters(value, cal20050701, 2)); // same quarter
+        assertEquals("qtrB =4", 1,  calendarValidator.compareQuarters(value, cal20050731, 2)); // -1 month
+        assertEquals("qtrB GT", 1,  calendarValidator.compareQuarters(value, cal20050630, 2)); // -1 quarter
+
+        assertEquals("year LT", -1, calendarValidator.compareYears(value, cal20060101)); // +1 year 
+        assertEquals("year EQ", 0,  calendarValidator.compareYears(value, cal20050101)); // same year
+        assertEquals("year GT", 1,  calendarValidator.compareYears(value, cal20041231)); // -1 year
+    }
+
+    /**
+     * Test adjustToTimeZone() method
+     */
+    public void testAdjustToTimeZone() {
+
+        Calendar calEST = createCalendar(EST, DATE_2005_11_23, TIME_12_03_45);
+        Date dateEST = calEST.getTime();
+
+        Calendar calGMT = createCalendar(GMT, DATE_2005_11_23, TIME_12_03_45);
+        Date dateGMT = calGMT.getTime();
+
+        Calendar calCET = createCalendar(EET, DATE_2005_11_23, TIME_12_03_45);
+        Date dateCET = calCET.getTime();
+
+        // Check the dates don't match
+        assertFalse("Check GMT != CET", dateGMT.getTime() == dateCET.getTime());
+        assertFalse("Check GMT != EST", dateGMT.getTime() == dateEST.getTime());
+        assertFalse("Check CET != EST", dateCET.getTime() == dateEST.getTime());
+
+        // EST to GMT and back
+        CalendarValidator.adjustToTimeZone(calEST, GMT);
+        assertEquals("EST to GMT", dateGMT, calEST.getTime());
+        assertFalse("Check EST = GMT", dateEST == calEST.getTime());
+        CalendarValidator.adjustToTimeZone(calEST, EST);
+        assertEquals("back to EST", dateEST, calEST.getTime());
+        assertFalse("Check EST != GMT", dateGMT == calEST.getTime());
+
+        // CET to GMT and back
+        CalendarValidator.adjustToTimeZone(calCET, GMT);
+        assertEquals("CET to GMT", dateGMT, calCET.getTime());
+        assertFalse("Check CET = GMT", dateCET == calCET.getTime());
+        CalendarValidator.adjustToTimeZone(calCET, EET);
+        assertEquals("back to CET", dateCET, calCET.getTime());
+        assertFalse("Check CET != GMT", dateGMT == calCET.getTime());
+
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CalendarValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CalendarValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CurrencyValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CurrencyValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CurrencyValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CurrencyValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,83 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+import java.math.BigDecimal;
+/**
+ * Test Case for CurrencyValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class CurrencyValidatorTest extends TestCase {
+    
+    protected CurrencyValidator validator;
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(CurrencyValidatorTest.class);
+    }
+    
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public CurrencyValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        validator = new CurrencyValidator();
+    }
+
+    /**
+     * Tear down
+     * @throws Exception
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        validator = null;
+    }
+
+    /**
+     * Test Invalid, strict=false
+     */
+    public void testLocaleCurrency() {
+        String inputString = null;
+        BigDecimal expected = new BigDecimal("1234.56");
+        BigDecimal result = null;
+
+        inputString = "$1,234.56";
+        result = validator.validate(inputString, Locale.US);
+        assertEquals("US currency", expected, result);
+
+        inputString = "£1,234.56";
+        result = validator.validate(inputString, Locale.UK);
+        assertEquals("UK currency", expected, result);
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CurrencyValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CurrencyValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DateValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DateValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DateValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DateValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,164 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Test Case for DateValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class DateValidatorTest extends BaseCalendarValidatorTest {
+
+    private DateValidator dateValidator;
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(DateValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public DateValidatorTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Set Up.
+     * @throws Exception
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        dateValidator = new DateValidator();
+        validator         = dateValidator;
+    }
+
+    /**
+     * Test DateValidator validate Methods
+     */
+    public void testDateValidatorMethods() {
+        Locale.setDefault(Locale.US);
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "yyyy-MM-dd";
+        String patternVal = "2005-12-31";
+        String localeVal  = "31.12.2005";
+        String defaultVal = "12/31/05";
+        String XXXX    = "XXXX"; 
+        Date expected = createCalendar(null, 20051231, 0).getTime();
+
+        assertEquals("validate(A) default", expected, DateValidator.getInstance().validate(defaultVal));
+        assertEquals("validate(A) locale ", expected, DateValidator.getInstance().validate(localeVal, locale));
+        assertEquals("validate(A) pattern", expected, DateValidator.getInstance().validate(patternVal, pattern));
+
+        assertTrue("isValid(A) default", DateValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", DateValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", DateValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", DateValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", DateValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", DateValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", DateValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", DateValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", DateValidator.getInstance().isValid(XXXX, pattern));
+
+        // Test Time Zone
+        TimeZone zone = (TimeZone.getDefault().getRawOffset() == EET.getRawOffset() ? EST : EET); 
+        Date expectedZone = createCalendar(zone, 20051231, 0).getTime();
+        assertFalse("default/zone same "+zone, expected.getTime() == expectedZone.getTime());
+
+        assertEquals("validate(C) default", expectedZone, DateValidator.getInstance().validate(defaultVal, zone));
+        assertEquals("validate(C) locale ", expectedZone, DateValidator.getInstance().validate(localeVal, locale, zone));
+        assertEquals("validate(C) pattern", expectedZone, DateValidator.getInstance().validate(patternVal, pattern, zone));
+    }
+
+    /**
+     * Test compare date methods
+     */
+    public void testCompare() {
+        int sameTime = 124522;
+        int testDate = 20050823;
+        Date diffHour    = createDate(GMT, testDate, 115922);    // same date, different time
+
+        Date value        = createDate(GMT, testDate, sameTime);   // test value
+        Date date20050824 = createDate(GMT, 20050824, sameTime);   // +1 day
+        Date date20050822 = createDate(GMT, 20050822, sameTime);   // -1 day
+
+        Date date20050830 = createDate(GMT, 20050830, sameTime);   // +1 week
+        Date date20050816 = createDate(GMT, 20050816, sameTime);   // -1 week
+
+        Date date20050901 = createDate(GMT, 20050901, sameTime);   // +1 month
+        Date date20050801 = createDate(GMT, 20050801, sameTime);   // same month
+        Date date20050731 = createDate(GMT, 20050731, sameTime);   // -1 month
+
+        Date date20051101 = createDate(GMT, 20051101, sameTime);   // +1 quarter (Feb Start)
+        Date date20051001 = createDate(GMT, 20051001, sameTime);   // +1 quarter
+        Date date20050701 = createDate(GMT, 20050701, sameTime);   // same quarter
+        Date date20050630 = createDate(GMT, 20050630, sameTime);   // -1 quarter
+
+        Date date20060101 = createDate(GMT, 20060101, sameTime);   // +1 year
+        Date date20050101 = createDate(GMT, 20050101, sameTime);   // same year
+        Date date20041231 = createDate(GMT, 20041231, sameTime);   // -1 year
+
+        assertEquals("date LT", -1, dateValidator.compareDates(value, date20050824, null)); // +1 day
+        assertEquals("date EQ", 0,  dateValidator.compareDates(value, diffHour, null));    // same day, diff hour
+        assertEquals("date GT", 1,  dateValidator.compareDates(value, date20050822, null)); // -1 day
+
+        assertEquals("week LT", -1, dateValidator.compareWeeks(value, date20050830, null)); // +1 week 
+        assertEquals("week =1", 0,  dateValidator.compareWeeks(value, date20050824, null)); // +1 day
+        assertEquals("week =2", 0,  dateValidator.compareWeeks(value, date20050822, null)); // same week
+        assertEquals("week =3", 0,  dateValidator.compareWeeks(value, date20050822, null)); // -1 day
+        assertEquals("week GT", 1,  dateValidator.compareWeeks(value, date20050816, null)); // -1 week
+
+        assertEquals("mnth LT", -1, dateValidator.compareMonths(value, date20050901, null)); // +1 month 
+        assertEquals("mnth =1", 0,  dateValidator.compareMonths(value, date20050830, null)); // +1 week 
+        assertEquals("mnth =2", 0,  dateValidator.compareMonths(value, date20050801, null)); // same month
+        assertEquals("mnth =3", 0,  dateValidator.compareMonths(value, date20050816, null)); // -1 week
+        assertEquals("mnth GT", 1,  dateValidator.compareMonths(value, date20050731, null)); // -1 month
+
+        assertEquals("qtrA <1", -1, dateValidator.compareQuarters(value, date20051101, null)); // +1 quarter (Feb) 
+        assertEquals("qtrA <2", -1, dateValidator.compareQuarters(value, date20051001, null)); // +1 quarter 
+        assertEquals("qtrA =1", 0,  dateValidator.compareQuarters(value, date20050901, null)); // +1 month 
+        assertEquals("qtrA =2", 0,  dateValidator.compareQuarters(value, date20050701, null)); // same quarter
+        assertEquals("qtrA =3", 0,  dateValidator.compareQuarters(value, date20050731, null)); // -1 month
+        assertEquals("qtrA GT", 1,  dateValidator.compareQuarters(value, date20050630, null)); // -1 quarter
+
+        // Change quarter 1 to start in Feb
+        assertEquals("qtrB LT", -1, dateValidator.compareQuarters(value, date20051101, null, 2)); // +1 quarter (Feb) 
+        assertEquals("qtrB =1", 0,  dateValidator.compareQuarters(value, date20051001, null, 2));  // same quarter 
+        assertEquals("qtrB =2", 0,  dateValidator.compareQuarters(value, date20050901, null, 2)); // +1 month 
+        assertEquals("qtrB =3", 1,  dateValidator.compareQuarters(value, date20050701, null, 2)); // same quarter
+        assertEquals("qtrB =4", 1,  dateValidator.compareQuarters(value, date20050731, null, 2)); // -1 month
+        assertEquals("qtrB GT", 1,  dateValidator.compareQuarters(value, date20050630, null, 2)); // -1 quarter
+
+        assertEquals("year LT", -1, dateValidator.compareYears(value, date20060101, null)); // +1 year 
+        assertEquals("year EQ", 0,  dateValidator.compareYears(value, date20050101, null)); // same year
+        assertEquals("year GT", 1,  dateValidator.compareYears(value, date20041231, null)); // -1 year
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DateValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DateValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DoubleValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DoubleValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DoubleValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DoubleValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,144 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * Test Case for DoubleValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class DoubleValidatorTest extends BaseNumberValidatorTest {
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(DoubleValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public DoubleValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        validator       = new DoubleValidator(false);
+        strictValidator = new DoubleValidator(true);
+
+        testPattern = "#,###";
+
+        // testValidateMinMax()
+        max = null;
+        maxPlusOne = null;
+        min = null;
+        minMinusOne = null;
+
+        // testInvalidStrict()
+        invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2"};
+
+        // testInvalidNotStrict()
+        invalid       = new String[] {null, "", "X", "X12"};
+
+        // testValid()
+        testNumber    = new Double(1234.5);
+        testZero      = new Double(0);
+        validStrict          = new String[] {"0", "1234.5", "1,234.5"};
+        validStrictCompare   = new Number[] {testZero, testNumber, testNumber};
+        valid                = new String[] {"0", "1234.5", "1,234.5", "1,234.5", "1234.5X"};
+        validCompare         = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+        testStringUS = "1,234.5";
+        testStringDE = "1.234,5";
+
+        // Localized Pattern test
+        localeValue = testStringDE;
+        localePattern = "#.###,#";
+        testLocale    = Locale.GERMANY;
+        localeExpected = testNumber;
+
+    }
+
+    /**
+     * Test DoubleValidator validate Methods
+     */
+    public void testDoubleValidatorMethods() {
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "0,00,00";
+        String patternVal = "1,23,45";
+        String localeVal  = "12.345";
+        String defaultVal = "12,345";
+        String XXXX    = "XXXX"; 
+        Double expected = new Double(12345);
+        assertEquals("validate(A) default", expected, DoubleValidator.getInstance().validate(defaultVal));
+        assertEquals("validate(A) locale ", expected, DoubleValidator.getInstance().validate(localeVal, locale));
+        assertEquals("validate(A) pattern", expected, DoubleValidator.getInstance().validate(patternVal, pattern));
+
+        assertTrue("isValid(A) default", DoubleValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", DoubleValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", DoubleValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", DoubleValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", DoubleValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", DoubleValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", DoubleValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", DoubleValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", DoubleValidator.getInstance().isValid(XXXX, pattern));
+    }
+
+    /**
+     * Test Double Range/Min/Max
+     */
+    public void testDoubleRangeMinMax() {
+        DoubleValidator validator = (DoubleValidator)strictValidator;
+        Double number9  = validator.validate("9", "#");
+        Double number10 = validator.validate("10", "#");
+        Double number11 = validator.validate("11", "#");
+        Double number19 = validator.validate("19", "#");
+        Double number20 = validator.validate("20", "#");
+        Double number21 = validator.validate("21", "#");
+
+        // Test isInRange()
+        assertFalse("isInRange() < min",   validator.isInRange(number9,  10, 20));
+        assertTrue("isInRange() = min",    validator.isInRange(number10, 10, 20));
+        assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+        assertTrue("isInRange() = max",    validator.isInRange(number20, 10, 20));
+        assertFalse("isInRange() > max",   validator.isInRange(number21, 10, 20));
+
+        // Test minValue()
+        assertFalse("minValue() < min",    validator.minValue(number9,  10));
+        assertTrue("minValue() = min",     validator.minValue(number10, 10));
+        assertTrue("minValue() > min",     validator.minValue(number11, 10));
+
+        // Test minValue()
+        assertTrue("maxValue() < max",     validator.maxValue(number19, 20));
+        assertTrue("maxValue() = max",     validator.maxValue(number20, 20));
+        assertFalse("maxValue() > max",    validator.maxValue(number21, 20));
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DoubleValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DoubleValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/FloatValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/FloatValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/FloatValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/FloatValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,144 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * Test Case for FloatValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class FloatValidatorTest extends BaseNumberValidatorTest {
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(FloatValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public FloatValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        validator       = new FloatValidator(false);
+        strictValidator = new FloatValidator(true);
+
+        testPattern = "#,###.#";
+
+        // testValidateMinMax()
+        max = new Float(Float.MAX_VALUE);
+        maxPlusOne = new Double(max.doubleValue() * 10);
+        min = new Float(Float.MAX_VALUE * -1);
+        minMinusOne = new Double(min.doubleValue() * 10);
+
+        // testInvalidStrict()
+        invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2"};
+
+        // testInvalidNotStrict()
+        invalid       = new String[] {null, "", "X", "X12"};
+
+        // testValid()
+        testNumber    = new Float(1234.5);
+        testZero      = new Float(0);
+        validStrict          = new String[] {"0", "1234.5", "1,234.5"};
+        validStrictCompare   = new Number[] {testZero, testNumber, testNumber};
+        valid                = new String[] {"0", "1234.5", "1,234.5", "1,234.5", "1234.5X"};
+        validCompare         = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+        testStringUS = "1,234.5";
+        testStringDE = "1.234,5";
+
+        // Localized Pattern test
+        localeValue = testStringDE;
+        localePattern = "#.###,#";
+        testLocale    = Locale.GERMANY;
+        localeExpected = testNumber;
+
+    }
+
+    /**
+     * Test FloatValidator validate Methods
+     */
+    public void testFloatValidatorMethods() {
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "0,00,00";
+        String patternVal = "1,23,45";
+        String localeVal  = "12.345";
+        String defaultVal = "12,345";
+        String XXXX    = "XXXX"; 
+        Float expected = new Float(12345);
+        assertEquals("validate(A) default", expected, FloatValidator.getInstance().validate(defaultVal));
+        assertEquals("validate(A) locale ", expected, FloatValidator.getInstance().validate(localeVal, locale));
+        assertEquals("validate(A) pattern", expected, FloatValidator.getInstance().validate(patternVal, pattern));
+
+        assertTrue("isValid(A) default", FloatValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", FloatValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", FloatValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", FloatValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", FloatValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", FloatValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", FloatValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", FloatValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", FloatValidator.getInstance().isValid(XXXX, pattern));
+    }
+
+    /**
+     * Test Float Range/Min/Max
+     */
+    public void testFloatRangeMinMax() {
+        FloatValidator validator = (FloatValidator)strictValidator;
+        Float number9  = validator.validate("9", "#");
+        Float number10 = validator.validate("10", "#");
+        Float number11 = validator.validate("11", "#");
+        Float number19 = validator.validate("19", "#");
+        Float number20 = validator.validate("20", "#");
+        Float number21 = validator.validate("21", "#");
+
+        // Test isInRange()
+        assertFalse("isInRange() < min",   validator.isInRange(number9,  10, 20));
+        assertTrue("isInRange() = min",    validator.isInRange(number10, 10, 20));
+        assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+        assertTrue("isInRange() = max",    validator.isInRange(number20, 10, 20));
+        assertFalse("isInRange() > max",   validator.isInRange(number21, 10, 20));
+
+        // Test minValue()
+        assertFalse("minValue() < min",    validator.minValue(number9,  10));
+        assertTrue("minValue() = min",     validator.minValue(number10, 10));
+        assertTrue("minValue() > min",     validator.minValue(number11, 10));
+
+        // Test minValue()
+        assertTrue("maxValue() < max",     validator.maxValue(number19, 20));
+        assertTrue("maxValue() = max",     validator.maxValue(number20, 20));
+        assertFalse("maxValue() > max",    validator.maxValue(number21, 20));
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/FloatValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/FloatValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/IntegerValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/IntegerValidatorTest.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/IntegerValidatorTest.java (added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/IntegerValidatorTest.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,143 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * Test Case for IntegerValidator.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class IntegerValidatorTest extends BaseNumberValidatorTest {
+
+    /**
+     * Main
+     * @param args arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(IntegerValidatorTest.class);
+    }
+
+    /**
+     * Constructor
+     * @param name test name
+     */
+    public IntegerValidatorTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        validator       = new IntegerValidator(false);
+        strictValidator = new IntegerValidator(true);
+
+        testPattern = "#,###";
+
+        // testValidateMinMax()
+        max = new Integer(Integer.MAX_VALUE);
+        maxPlusOne = new Long(max.longValue() + 1);
+        min = new Integer(Integer.MIN_VALUE);
+        minMinusOne = new Long(min.longValue() - 1);
+
+        // testInvalidStrict()
+        invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2"};
+
+        // testInvalidNotStrict()
+        invalid       = new String[] {null, "", "X", "X12"};
+
+        // testValid()
+        testNumber    = new Integer(1234);
+        testZero      = new Integer(0);
+        validStrict          = new String[] {"0", "1234", "1,234"};
+        validStrictCompare   = new Number[] {testZero, testNumber, testNumber};
+        valid                = new String[] {"0", "1234", "1,234", "1,234.5", "1234X"};
+        validCompare         = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+        testStringUS = "1,234";
+        testStringDE = "1.234";
+
+        // Localized Pattern test
+        localeValue = testStringDE;
+        localePattern = "#.###";
+        testLocale    = Locale.GERMANY;
+        localeExpected = testNumber;
+    }
+
+    /**
+     * Test IntegerValidator validate Methods
+     */
+    public void testIntegerValidatorMethods() {
+        Locale locale     = Locale.GERMAN;
+        String pattern    = "0,00,00";
+        String patternVal = "1,23,45";
+        String localeVal  = "12.345";
+        String defaultVal = "12,345";
+        String XXXX    = "XXXX"; 
+        Integer expected = new Integer(12345);
+        assertEquals("validate(A) default", expected, IntegerValidator.getInstance().validate(defaultVal));
+        assertEquals("validate(A) locale ", expected, IntegerValidator.getInstance().validate(localeVal, locale));
+        assertEquals("validate(A) pattern", expected, IntegerValidator.getInstance().validate(patternVal, pattern));
+
+        assertTrue("isValid(A) default", IntegerValidator.getInstance().isValid(defaultVal));
+        assertTrue("isValid(A) locale ", IntegerValidator.getInstance().isValid(localeVal, locale));
+        assertTrue("isValid(A) pattern", IntegerValidator.getInstance().isValid(patternVal, pattern));
+
+        assertNull("validate(B) default", IntegerValidator.getInstance().validate(XXXX));
+        assertNull("validate(B) locale ", IntegerValidator.getInstance().validate(XXXX, locale));
+        assertNull("validate(B) pattern", IntegerValidator.getInstance().validate(XXXX, pattern));
+
+        assertFalse("isValid(B) default", IntegerValidator.getInstance().isValid(XXXX));
+        assertFalse("isValid(B) locale ", IntegerValidator.getInstance().isValid(XXXX, locale));
+        assertFalse("isValid(B) pattern", IntegerValidator.getInstance().isValid(XXXX, pattern));
+    }
+
+    /**
+     * Test Integer Range/Min/Max
+     */
+    public void testIntegerRangeMinMax() {
+        IntegerValidator validator = (IntegerValidator)strictValidator;
+        Integer number9  = validator.validate("9", "#");
+        Integer number10 = validator.validate("10", "#");
+        Integer number11 = validator.validate("11", "#");
+        Integer number19 = validator.validate("19", "#");
+        Integer number20 = validator.validate("20", "#");
+        Integer number21 = validator.validate("21", "#");
+
+        // Test isInRange()
+        assertFalse("isInRange() < min",   validator.isInRange(number9,  10, 20));
+        assertTrue("isInRange() = min",    validator.isInRange(number10, 10, 20));
+        assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+        assertTrue("isInRange() = max",    validator.isInRange(number20, 10, 20));
+        assertFalse("isInRange() > max",   validator.isInRange(number21, 10, 20));
+
+        // Test minValue()
+        assertFalse("minValue() < min",    validator.minValue(number9,  10));
+        assertTrue("minValue() = min",     validator.minValue(number10, 10));
+        assertTrue("minValue() > min",     validator.minValue(number11, 10));
+
+        // Test minValue()
+        assertTrue("maxValue() < max",     validator.maxValue(number19, 20));
+        assertTrue("maxValue() = max",     validator.maxValue(number20, 20));
+        assertFalse("maxValue() > max",    validator.maxValue(number21, 20));
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/IntegerValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/IntegerValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



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