KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > eclipse > EqualityAndHashCodeTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.projectimport.eclipse;
21
22 import org.netbeans.junit.NbTestCase;
23
24 /**
25  * Tests equal and hashCode methods.
26  *
27  * @author mkrauskopf
28  */

29 public class EqualityAndHashCodeTest extends NbTestCase {
30
31     ClassPath.Link link2;
32     ClassPath.Link theSameAsLink2;
33
34     Workspace.Variable var2;
35     Workspace.Variable theSameAsVar2;
36
37     public EqualityAndHashCodeTest(String JavaDoc testName) {
38         super(testName);
39     }
40
41     protected void setUp() throws java.lang.Exception JavaDoc {
42         link2 = new ClassPath.Link();
43         link2.setLocation("/link2");
44         link2.setName("link2");
45         link2.setType(ClassPath.Link.TYPE_FILE);
46         
47         theSameAsLink2 = new ClassPath.Link();
48         theSameAsLink2.setLocation("/link2");
49         theSameAsLink2.setName("link2");
50         theSameAsLink2.setType(ClassPath.Link.TYPE_FILE);
51         
52         var2 = new Workspace.Variable();
53         var2.setLocation("/var2");
54         var2.setName("var2");
55         
56         theSameAsVar2 = new Workspace.Variable();
57         theSameAsVar2.setLocation("/var2");
58         theSameAsVar2.setName("var2");
59     }
60     
61     /** tests ClassPathContent.Link.equals() */
62     public void testLinksEquality() {
63         assertNotSame("link2 and theSameAsLink2 shouldn't be the same " +
64                 "(link2 == theSameAsLink2)", link2, theSameAsLink2);
65         assertEquals("link2 should be equal to theSameAsLink2",
66                 link2, theSameAsLink2);
67         theSameAsLink2.setType(ClassPath.Link.TYPE_FOLDER);
68         assertFalse("link2 should be not be equal to theSameAsLink2",
69                 link2.equals(theSameAsLink2));
70     }
71     
72     /** tests ClassPathContent.Link.hashCode() */
73     public void testLinksHashCodes() {
74         assertEquals("link2 and theSameAsLink2 should generate the same hashCode",
75                 link2.hashCode(), theSameAsLink2.hashCode());
76         theSameAsLink2.setType(ClassPath.Link.TYPE_FOLDER);
77         assertFalse("link2 and theSameAsLink2 shouldn't generate the same hashCode",
78                 link2.hashCode() == theSameAsLink2.hashCode());
79     }
80     /** tests ClassPathContent.Variable.equals() */
81     public void testVariablesEquality() {
82         assertNotSame("var2 and theSameAsVar2 shouldn't be the same " +
83                 "(var2 == theSameAsVar2)", var2, theSameAsVar2);
84         assertEquals("var2 should be equal to theSameAsVar2",
85                 var2, theSameAsVar2);
86         theSameAsVar2.setLocation(theSameAsVar2.getLocation() + "a");
87         assertFalse("var2 should be not be equal to theSameAsVar2",
88                 var2.equals(theSameAsVar2));
89     }
90     
91     /** tests ClassPathContent.Variable.hashCode() */
92     public void testVariablesHashCodes() {
93         assertEquals("var2 and theSameAsVar2 should generate the same hashCode",
94                 var2.hashCode(), theSameAsVar2.hashCode());
95         theSameAsVar2.setLocation(theSameAsVar2.getLocation() + "a");
96         assertFalse("var2 and theSameAsVar2 shouldn't generate the same hashCode",
97                 var2.hashCode() == theSameAsLink2.hashCode());
98     }
99
100 }
101
Popular Tags