KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > expectation > MapEntryTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.expectation;
4
5 import junit.framework.TestCase;
6 import org.jmock.expectation.MapEntry;
7
8
9 public class MapEntryTest extends TestCase
10 {
11
12     public void testEquals() {
13         assertEquals("Should be expected value",
14                      new MapEntry("A", "2"),
15                      new MapEntry("A", "2"));
16
17         assertTrue("Should not be equal",
18                    !new MapEntry("A", "2").equals(new MapEntry("A", "1")));
19
20         assertTrue("Should not be equal",
21                    !new MapEntry("A", "2").equals(new MapEntry("B", "2")));
22
23         assertEquals("Should be equal with null value",
24                      new MapEntry("A", null),
25                      new MapEntry("A", null));
26
27         assertEquals("Should be equal with null key",
28                      new MapEntry(null, "A"),
29                      new MapEntry(null, "A"));
30
31         assertEquals("Should be equal byte arrays",
32                      new MapEntry("A", "A".getBytes()),
33                      new MapEntry("A", "A".getBytes()));
34
35         assertTrue("Should not be equal byte arrays",
36                    !new MapEntry("A", "AB".getBytes()).equals(new MapEntry("A", "A".getBytes())));
37
38         assertTrue("Should not be equal byte arrays",
39                    !new MapEntry("A", "A".getBytes()).equals(new MapEntry("A", "AB".getBytes())));
40
41         assertTrue("Should not be equal byte arrays",
42                    !new MapEntry("A", null).equals(new MapEntry("A", "AB".getBytes())));
43     }
44
45     public void testHashCode() {
46         assertEquals("Should be equal hashcodes",
47                      new MapEntry("A", "A".getBytes()).hashCode(),
48                      new MapEntry("A", "A".getBytes()).hashCode());
49
50     }
51 }
52
Popular Tags