001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.validator;
018:
019: import junit.framework.TestCase;
020:
021: /**
022: * Test the GenericValidator class.
023: *
024: * @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
025: */
026: public class GenericValidatorTest extends TestCase {
027:
028: /**
029: * Constructor for GenericValidatorTest.
030: */
031: public GenericValidatorTest(String name) {
032: super (name);
033: }
034:
035: public void testMinLength() {
036:
037: // Use 0 for line end length
038: assertTrue("Min=5 End=0", GenericValidator.minLength(
039: "12345\n\r", 5, 0));
040: assertFalse("Min=6 End=0", GenericValidator.minLength(
041: "12345\n\r", 6, 0));
042: assertFalse("Min=7 End=0", GenericValidator.minLength(
043: "12345\n\r", 7, 0));
044: assertFalse("Min=8 End=0", GenericValidator.minLength(
045: "12345\n\r", 8, 0));
046:
047: // Use 1 for line end length
048: assertTrue("Min=5 End=1", GenericValidator.minLength(
049: "12345\n\r", 5, 1));
050: assertTrue("Min=6 End=1", GenericValidator.minLength(
051: "12345\n\r", 6, 1));
052: assertFalse("Min=7 End=1", GenericValidator.minLength(
053: "12345\n\r", 7, 1));
054: assertFalse("Min=8 End=1", GenericValidator.minLength(
055: "12345\n\r", 8, 1));
056:
057: // Use 2 for line end length
058: assertTrue("Min=5 End=2", GenericValidator.minLength(
059: "12345\n\r", 5, 2));
060: assertTrue("Min=6 End=2", GenericValidator.minLength(
061: "12345\n\r", 6, 2));
062: assertTrue("Min=7 End=2", GenericValidator.minLength(
063: "12345\n\r", 7, 2));
064: assertFalse("Min=8 End=2", GenericValidator.minLength(
065: "12345\n\r", 8, 2));
066: }
067:
068: public void testMaxLength() {
069:
070: // Use 0 for line end length
071: assertFalse("Max=4 End=0", GenericValidator.maxLength(
072: "12345\n\r", 4, 0));
073: assertTrue("Max=5 End=0", GenericValidator.maxLength(
074: "12345\n\r", 5, 0));
075: assertTrue("Max=6 End=0", GenericValidator.maxLength(
076: "12345\n\r", 6, 0));
077: assertTrue("Max=7 End=0", GenericValidator.maxLength(
078: "12345\n\r", 7, 0));
079:
080: // Use 1 for line end length
081: assertFalse("Max=4 End=1", GenericValidator.maxLength(
082: "12345\n\r", 4, 1));
083: assertFalse("Max=5 End=1", GenericValidator.maxLength(
084: "12345\n\r", 5, 1));
085: assertTrue("Max=6 End=1", GenericValidator.maxLength(
086: "12345\n\r", 6, 1));
087: assertTrue("Max=7 End=1", GenericValidator.maxLength(
088: "12345\n\r", 7, 1));
089:
090: // Use 2 for line end length
091: assertFalse("Max=4 End=2", GenericValidator.maxLength(
092: "12345\n\r", 4, 2));
093: assertFalse("Max=5 End=2", GenericValidator.maxLength(
094: "12345\n\r", 5, 2));
095: assertFalse("Max=6 End=2", GenericValidator.maxLength(
096: "12345\n\r", 6, 2));
097: assertTrue("Max=7 End=2", GenericValidator.maxLength(
098: "12345\n\r", 7, 2));
099: }
100:
101: }
|