KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > types > TestUnsignedInt


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package test.types;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.types.UnsignedInt;
21
22 /**
23  * Test validation of types.UnsignedInt
24  */

25 public class TestUnsignedInt extends TestCase {
26
27     public TestUnsignedInt(String JavaDoc name) {
28         super(name);
29     }
30
31     /**
32      * Run a failure test. value should be invalid.
33      */

34     private void runFailTest(long value) throws Exception JavaDoc {
35         UnsignedInt oUnsignedInt = null;
36         try {
37             oUnsignedInt = new UnsignedInt(value);
38         }
39         catch (Exception JavaDoc e) { // catch the validation exception
40
}
41         // object is not iNstantiated on bad data value
42
assertNull("validation restriction failed [" +
43                 String.valueOf(value) + "]. did not restrict bad value.", oUnsignedInt);
44     }
45
46     /**
47      * Run a successful test. value should be valid.
48      */

49     private void runPassTest(long value) throws Exception JavaDoc {
50         UnsignedInt oUnsignedInt = null;
51         try {
52             oUnsignedInt = new UnsignedInt(value);
53         }
54         catch (Exception JavaDoc e) { // catch the validation exception
55
}
56         assertEquals("unsigned int not equal" +
57                 String.valueOf(value), oUnsignedInt.toString(), String.valueOf(value));
58     }
59
60     /**
61      * Test that a positive value succeeeds
62      */

63     public void testPositiveValue() throws Exception JavaDoc {
64         runPassTest(100);
65     }
66
67     /**
68      * Test that a negative number fails
69      */

70     public void testNegativeValue() throws Exception JavaDoc {
71         runFailTest(-100);
72     }
73
74
75     /**
76     * Test that a number at MaxInclusive succeeds
77     */

78     public void testMaxInclusive() throws Exception JavaDoc {
79        runPassTest(4294967295L);
80     }
81
82     /**
83     * Test that a number over MaxInclusive fails
84     */

85     public void testMaxOver() throws Exception JavaDoc {
86        runFailTest(4294967296L);
87     }
88
89     /**
90     * Test that a number at MinInclusive succeeds
91     */

92     public void testMinExclusive() throws Exception JavaDoc {
93        runPassTest(0L);
94     }
95
96 }
97
Popular Tags