KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > om > NumberKeyTest


1 package org.apache.torque.om;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */

21
22 import java.util.Arrays JavaDoc;
23
24 import junit.framework.Assert;
25 import junit.framework.TestCase;
26
27 /**
28  * Currently just tests the equality of NumberKey.
29  *
30  * @author <a HREF="mailto:stephenh@chase3000.com">Stephen Haberman</a>
31  * @version $Id: NumberKeyTest.java 473821 2006-11-11 22:37:25Z tv $
32  */

33 public class NumberKeyTest extends TestCase
34 {
35
36     /** Test value. */
37     private NumberKey n1a = new NumberKey(1);
38     /** Test value. */
39     private NumberKey n1b = new NumberKey(1);
40     /** Test value. */
41     private NumberKey n1c = new NumberKey(1);
42     /** Test value. */
43     private NumberKey n2a = new NumberKey(2);
44
45     /**
46      * Simple constructor.
47      *
48      * @param name the name of the test to execute
49      */

50     public NumberKeyTest(String JavaDoc name)
51     {
52         super(name);
53     }
54
55     /**
56      * Test a.equals(a)
57      */

58     public void testReflexive()
59     {
60         Assert.assertTrue(n1a.equals(n1a));
61     }
62
63     /**
64      * Test a.equals(b) = b.equals(a)
65      */

66     public void testSymmetric()
67     {
68         Assert.assertTrue(n1a.equals(n1b));
69         Assert.assertTrue(n1b.equals(n1a));
70
71         Assert.assertTrue(!"1".equals(n1a));
72         // As this used to give false, i.e. n1a was considered equal to "1"
73
// it can lead to difficult to find bugs if it is immediately
74
// changed to the opposite. So this will throw an exception.
75
//Assert.assertTrue(!n1a.equals("1"));
76
try
77         {
78             Assert.assertTrue(!n1a.equals("1"));
79         }
80         catch (IllegalArgumentException JavaDoc e)
81         {
82             // expected
83
}
84         Assert.assertTrue(!n1a.equals(new Integer JavaDoc(1)));
85         Assert.assertTrue(!new Integer JavaDoc(1).equals(n1a));
86     }
87
88     /**
89      * Test a.equals(b) = b.equals(c) = c.equals(a)
90      */

91     public void testTransitive()
92     {
93         Assert.assertTrue(n1a.equals(n1b));
94         Assert.assertTrue(n1b.equals(n1c));
95         Assert.assertTrue(n1c.equals(n1a));
96     }
97
98     /**
99      * Test !a.equals(null)
100      */

101     public void testNull()
102     {
103         Assert.assertTrue(!n1a.equals(null));
104     }
105
106     /**
107      * Test sorting.
108      */

109     public void testList()
110     {
111         Object JavaDoc[] array = new Object JavaDoc[] { n1a, n2a, n1b };
112         Arrays.sort(array);
113
114         Assert.assertEquals(n1a, array[0]);
115         Assert.assertEquals(n1b, array[1]);
116         Assert.assertEquals(n2a, array[2]);
117     }
118
119     /**
120      * Test long constructor
121      */

122     public void testLongConstructor()
123     {
124         NumberKey key = new NumberKey(9900000000000001L);
125         assertEquals("9900000000000001", key.toString());
126     }
127 }
128
Popular Tags