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