KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > util > ObjectPairTest


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

18 package net.sf.uitags.util;
19
20 import junit.framework.TestCase;
21
22 /**
23  * Tests {@link net.sf.uitags.util.ObjectPair}.
24  *
25  * @author hgani
26  * @version $Id: ObjectPairTest.java,v 1.1.1.1 2006/02/26 11:39:22 hgani Exp $
27  */

28 public class ObjectPairTest extends TestCase {
29
30   /**
31    * Instance of the class under test.
32    */

33   private ObjectPair pair;
34
35   /**
36    * Main method for the tests.
37    *
38    * @param args main arguments
39    */

40   public static void main(String JavaDoc[] args) {
41     junit.textui.TestRunner.run(ObjectPairTest.class);
42   }
43
44   /** {@inheritDoc} */
45   protected void setUp() throws Exception JavaDoc {
46     super.setUp();
47     this.pair = new ObjectPair("first1", "second1");
48   }
49
50   /** {@inheritDoc} */
51   protected void tearDown() throws Exception JavaDoc {
52     super.tearDown();
53     this.pair = null;
54   }
55
56   /**
57    * Ensures that all getters of this class return proper objects.
58    */

59   public void testGetObjects() {
60     assertEquals("first1", this.pair.getFirstObject());
61     assertEquals("second1", this.pair.getSecondObject());
62   }
63
64   /**
65    * Ensures that {@link ObjectPair#equals(Object)}
66    * correctly compares two objects.
67    */

68   public void testEquals() {
69     // same first object, diff second object
70
ObjectPair pair1 = new ObjectPair("first1", "second2");
71     // diff first object, same second object
72
ObjectPair pair2 = new ObjectPair("first2", "second1");
73     // same first object, same second object
74
ObjectPair pair3 = new ObjectPair("first1", "second1");
75     // diff first object, diff second object
76
ObjectPair pair4 = new ObjectPair("first2", "second2");
77
78     assertTrue(!this.pair.equals(pair1));
79     assertTrue(!this.pair.equals(pair2));
80     assertTrue(this.pair.equals(pair3));
81     assertTrue(!this.pair.equals(pair4));
82   }
83
84   /**
85    * Ensures that {@link ObjectPair#hashCode()}
86    * returns the same hash code value when the objects are equal.
87    */

88   public void testHashCode() {
89     // we can only test objects with the same hashcode, because
90
// there is no guarantee that different objects will have
91
// different hash code
92
ObjectPair tempPair = new ObjectPair("first1", "second1");
93
94     assertEquals(this.pair.hashCode(), tempPair.hashCode());
95   }
96 }
97
Popular Tags