    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
    20  import junit.framework.Test;
    21  import junit.framework.TestSuite;
    22
    23
    24  /***
    25   * Performs Validation Test for <code>int</code> validations.
    26   *
    27   * @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
    28   */
    29  public class IntegerTest extends TestNumber {
    30
    31
    32      public IntegerTest(String name) {
    33          super(name);
    34          FORM_KEY = "intForm";
    35          ACTION = "int";
    36      }
    37
    38      /***
    39       * Start the tests.
    40       *
    41       * @param theArgs the arguments. Not used
    42       */
    43      public static void main(String[] theArgs) {
    44          junit.awtui.TestRunner.main(new String[]{IntegerTest.class.getName()});
    45      }
    46
    47      /***
    48       * @return a test suite (<code>TestSuite</code>) that includes all methods
    49       *         starting with "test"
    50       */
    51      public static Test suite() {
    52          // All methods starting with "test" will be executed in the test suite.
    53          return new TestSuite(IntegerTest.class);
    54      }
    55
    56      /***
    57       * Tests the int validation.
    58       */
    59      public void testInt() throws ValidatorException {
    60          // Create bean to run test on.
    61          ValueBean info = new ValueBean();
    62          info.setValue("0");
    63
    64          valueTest(info, true);
    65      }
    66
    67      /***
    68       * Tests the int validation.
    69       */
    70      public void testIntMin() throws ValidatorException {
    71          // Create bean to run test on.
    72          ValueBean info = new ValueBean();
    73          info.setValue(new Integer(Integer.MIN_VALUE).toString());
    74
    75          valueTest(info, true);
    76      }
    77
    78      /***
    79       * Tests the int validation.
    80       */
    81      public void testIntegerMax() throws ValidatorException {
    82          // Create bean to run test on.
    83          ValueBean info = new ValueBean();
    84          info.setValue(new Integer(Integer.MAX_VALUE).toString());
    85
    86          valueTest(info, true);
    87      }
    88
    89      /***
    90       * Tests the int validation failure.
    91       */
    92      public void testIntFailure() throws ValidatorException {
    93          // Create bean to run test on.
    94          ValueBean info = new ValueBean();
    95
    96          valueTest(info, false);
    97      }
    98
    99      /***
    100      * Tests the int validation failure.
    101      */
    102     public void testIntBeyondMin() throws ValidatorException {
    103         // Create bean to run test on.
    104         ValueBean info = new ValueBean();
    105         info.setValue(Integer.MIN_VALUE + "1");
    106
    107         valueTest(info, false);
    108     }
    109
    110     /***
    111      * Tests the int validation failure.
    112      */
    113     public void testIntBeyondMax() throws ValidatorException {
    114         // Create bean to run test on.
    115         ValueBean info = new ValueBean();
    116         info.setValue(Integer.MAX_VALUE + "1");
    117
    118         valueTest(info, false);
    119     }
    120
    121 }