1   /*
2    * $Id: GenericValidatorTest.java 376702 2006-02-10 14:30:11Z niallp $
3    * $Rev: 376702 $
4    * $Date: 2006-02-10 14:30:11 +0000 (Fri, 10 Feb 2006) $
5    *
6    * ====================================================================
7    * Copyright 2006 The Apache Software Foundation
8    *
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   *
13   *     http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   */
21  
22  package org.apache.commons.validator;
23  
24  import junit.framework.TestCase;
25  
26  /***
27   * Test the GenericValidator class.
28   */
29  public class GenericValidatorTest extends TestCase {
30      
31      /***
32       * Constructor for GenericValidatorTest.
33       */
34      public GenericValidatorTest(String name) {
35          super(name);
36      }
37  
38      public void testMinLength() {
39  
40          // Use 0 for line end length
41          assertTrue("Min=5 End=0",  GenericValidator.minLength("12345\n\r", 5, 0));
42          assertFalse("Min=6 End=0", GenericValidator.minLength("12345\n\r", 6, 0));
43          assertFalse("Min=7 End=0", GenericValidator.minLength("12345\n\r", 7, 0));
44          assertFalse("Min=8 End=0", GenericValidator.minLength("12345\n\r", 8, 0));
45  
46          // Use 1 for line end length
47          assertTrue("Min=5 End=1",  GenericValidator.minLength("12345\n\r", 5, 1));
48          assertTrue("Min=6 End=1",  GenericValidator.minLength("12345\n\r", 6, 1));
49          assertFalse("Min=7 End=1", GenericValidator.minLength("12345\n\r", 7, 1));
50          assertFalse("Min=8 End=1", GenericValidator.minLength("12345\n\r", 8, 1));
51  
52          // Use 2 for line end length
53          assertTrue("Min=5 End=2",  GenericValidator.minLength("12345\n\r", 5, 2));
54          assertTrue("Min=6 End=2",  GenericValidator.minLength("12345\n\r", 6, 2));
55          assertTrue("Min=7 End=2",  GenericValidator.minLength("12345\n\r", 7, 2));
56          assertFalse("Min=8 End=2", GenericValidator.minLength("12345\n\r", 8, 2));
57      }
58  
59      public void testMaxLength() {
60  
61          // Use 0 for line end length
62          assertFalse("Max=4 End=0", GenericValidator.maxLength("12345\n\r", 4, 0));
63          assertTrue("Max=5 End=0",  GenericValidator.maxLength("12345\n\r", 5, 0));
64          assertTrue("Max=6 End=0",  GenericValidator.maxLength("12345\n\r", 6, 0));
65          assertTrue("Max=7 End=0",  GenericValidator.maxLength("12345\n\r", 7, 0));
66  
67          // Use 1 for line end length
68          assertFalse("Max=4 End=1", GenericValidator.maxLength("12345\n\r", 4, 1));
69          assertFalse("Max=5 End=1", GenericValidator.maxLength("12345\n\r", 5, 1));
70          assertTrue("Max=6 End=1",  GenericValidator.maxLength("12345\n\r", 6, 1));
71          assertTrue("Max=7 End=1",  GenericValidator.maxLength("12345\n\r", 7, 1));
72  
73          // Use 2 for line end length
74          assertFalse("Max=4 End=2", GenericValidator.maxLength("12345\n\r", 4, 2));
75          assertFalse("Max=5 End=2", GenericValidator.maxLength("12345\n\r", 5, 2));
76          assertFalse("Max=6 End=2", GenericValidator.maxLength("12345\n\r", 6, 2));
77          assertTrue("Max=7 End=2",  GenericValidator.maxLength("12345\n\r", 7, 2));
78      }
79  
80  }