KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > common > DefaultKeyTest


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: DefaultKeyTest.java,v 1.2 2005/07/06 15:36:02 moroy Exp $
27 ====================================================================*/

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 /**
40  * Test class for DefaultKey object.
41  *
42  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
43  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
44  *
45  * @version 0.1
46  */

47 public class DefaultKeyTest
48      extends TestCase
49 {
50
51     //==================================================================
52
//
53
// Internal States.
54
//
55
// ==================================================================
56

57     /** The key ot test. */
58     protected DefaultKey testKey_, nullRoleKey_, nullIdKey_, nullRoleAndNullIdKey_, allNullKey_;
59     
60     // ==================================================================
61
//
62
// Constructors.
63
//
64
// ==================================================================
65

66     // ==================================================================
67
//
68
// Internal method.
69
//
70
// ==================================================================
71

72     /*
73      * @see TestCase#setUp()
74      */

75     protected void setUp() throws Exception JavaDoc {
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     // ==================================================================
85
//
86
// Public methods (code to test).
87
//
88
// ==================================================================
89

90     /*
91      * Class under test for boolean equals(Object)
92      */

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 JavaDoc 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     /*
108      * Class under test for boolean equals(Object)
109      */

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 JavaDoc 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