1 19 20 package org.netbeans.modules.projectimport.eclipse; 21 22 import org.netbeans.junit.NbTestCase; 23 24 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 testName) { 38 super(testName); 39 } 40 41 protected void setUp() throws java.lang.Exception { 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 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 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 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 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 |