KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > types > TestUnsignedLong


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.UnsignedLong;
21
22 /**
23  * Test validation of types.UnsignedLong
24  */

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

34     private void runFailTest(double value) throws Exception JavaDoc {
35         UnsignedLong oUnsignedLong = null;
36         try {
37             oUnsignedLong = new UnsignedLong(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.", oUnsignedLong);
44     }
45
46     /**
47      * Run a successful test. value should be valid. String should come out
48      * as expected.
49      */

50     private void runPassTest(double value, String JavaDoc strValue) throws Exception JavaDoc {
51         UnsignedLong oUnsignedLong = null;
52         try {
53             oUnsignedLong = new UnsignedLong(value);
54         }
55         catch (Exception JavaDoc e) { // catch the validation exception
56
// error!
57
assertTrue("validation error thrown and it shouldn't be", false);
58         }
59         assertEquals("unsigned long not equal: " +
60                 String.valueOf(value), strValue, oUnsignedLong.toString());
61     }
62
63     /**
64      * Test that a positive value succeeeds
65      */

66     public void testPositiveValue() throws Exception JavaDoc {
67         runPassTest(100, "100");
68     }
69
70     /**
71      * Test that a negative number fails
72      */

73     public void testNegativeValue() throws Exception JavaDoc {
74         runFailTest(-100);
75     }
76
77     /**
78     * Test that a big number that send the double in scientific notation is OK
79     */

80     public void testMaxInclusive() throws Exception JavaDoc {
81       runPassTest(123456789, "123456789");
82     }
83
84     /**
85     * Test that a number over MaxInclusive fails
86      * This test wont pass because of precision issues:
87      * expected:<18446744073709551615> but was:<18446744073709552000>
88     */

89 /*
90       public void testBigNumber() throws Exception {
91       runPassTest(18446744073709551615D, "18446744073709551615");
92     }
93 */

94
95     /**
96     * Test that a number at MinInclusive succeeds
97     */

98     public void testMinExclusive() throws Exception JavaDoc {
99        runPassTest(0L, "0");
100     }
101
102
103 }
104
Popular Tags