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