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