1 28 29 package org.objectweb.util.explorer.core.common; 30 31 import org.objectweb.util.explorer.core.common.lib.DefaultKey; 32 import org.objectweb.util.explorer.core.role.api.Role; 33 import org.objectweb.util.explorer.core.role.api.RoleProvider; 34 import org.objectweb.util.explorer.core.role.lib.DefaultRole; 35 36 import junit.framework.Assert; 37 import junit.framework.TestCase; 38 39 47 public class DefaultKeyTest 48 extends TestCase 49 { 50 51 57 58 protected DefaultKey testKey_, nullRoleKey_, nullIdKey_, nullRoleAndNullIdKey_, allNullKey_; 59 60 66 72 75 protected void setUp() throws Exception { 76 Role role = new DefaultRole("test_role"); 77 testKey_ = new DefaultKey("java","test_id",role); 78 nullRoleKey_ = new DefaultKey("java","test_id",null); 79 nullIdKey_ = new DefaultKey("java",null,role); 80 nullRoleAndNullIdKey_ = new DefaultKey("java",null,null); 81 allNullKey_ = new DefaultKey(null,null,null); 82 } 83 84 90 93 public void testEqualsObject() { 94 Assert.assertTrue(!testKey_.equals(null)); 95 Assert.assertEquals(testKey_, testKey_); 96 Assert.assertEquals(nullRoleKey_, new DefaultKey("java","test_id",null)); 97 Assert.assertEquals(nullIdKey_, new DefaultKey("java",null,new DefaultRole("test_role"))); 98 Assert.assertNotSame(nullRoleAndNullIdKey_, new DefaultKey("java",null,null)); 99 Assert.assertEquals(allNullKey_, new DefaultKey(null,null,null)); 100 Assert.assertEquals(testKey_, new DefaultKey("java","test_id",new DefaultRole("test_role"))); 101 102 Object key = new DefaultKey("java","test",new DefaultRole(RoleProvider.DEFAULT_ROLE)); 103 Assert.assertEquals(key, new DefaultKey("java","test",new DefaultRole(RoleProvider.DEFAULT_ROLE))); 104 105 } 106 107 110 public void testHashCode() { 111 Assert.assertEquals(testKey_.hashCode(), testKey_.hashCode()); 112 Assert.assertEquals(nullRoleKey_.hashCode(), (new DefaultKey("java","test_id",null)).hashCode()); 113 Assert.assertEquals(nullIdKey_.hashCode(), (new DefaultKey("java",null,new DefaultRole("test_role"))).hashCode()); 114 Assert.assertEquals(allNullKey_.hashCode(), (new DefaultKey(null,null,null)).hashCode()); 115 Assert.assertEquals(testKey_.hashCode(), (new DefaultKey("java","test_id",new DefaultRole("test_role"))).hashCode()); 116 117 Object key = new DefaultKey("java","test",new DefaultRole(RoleProvider.DEFAULT_ROLE)); 118 Assert.assertEquals(key.hashCode(), (new DefaultKey("java","test",new DefaultRole(RoleProvider.DEFAULT_ROLE))).hashCode()); 119 120 } 121 122 } | Popular Tags |