KickJava   Java API By Example, From Geeks To Geeks.

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


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

3 package test.jmock.expectation;
4
5 import junit.framework.AssertionFailedError;
6 import junit.framework.TestCase;
7 import org.jmock.expectation.AssertMo;
8 import org.jmock.expectation.ExpectationMap;
9
10
11 public class ExpectationMapTest extends TestCase
12 {
13
14     public void testExpectMissingEntry() {
15         ExpectationMap map = new ExpectationMap("map");
16
17         map.addExpectedMissing("key");
18         assertEquals("one entry", null, map.get("key"));
19         map.verify();
20     }
21
22     public void testExpectNullEntry() {
23
24         ExpectationMap map = new ExpectationMap("map");
25
26         try {
27             map.addExpected("key", null);
28             assertEquals("one entry", null, map.get("key"));
29             map.verify();
30         }
31         catch (NullPointerException JavaDoc ex) {
32             AssertMo.assertStartsWith("Should be JDK 1.1.7A",
33                                       "1.1",
34                                       System.getProperty("java.version"));
35         }
36     }
37
38     public void testExpectOneEntry() {
39         ExpectationMap map = new ExpectationMap("map");
40
41         map.addExpected("key", "value");
42         assertEquals("one entry", "value", map.get("key"));
43         map.verify();
44     }
45
46     public void testExpectTwoEntries() {
47         ExpectationMap map = new ExpectationMap("map");
48
49         map.addExpected("key", "value");
50         map.addExpected("key1", "value1");
51
52         assertEquals("two entries", "value", map.get("key"));
53         assertEquals("two entries", "value1", map.get("key1"));
54         map.verify();
55     }
56
57     public void testFailOneEntry() {
58         try {
59             ExpectationMap map = new ExpectationMap("map");
60             map.setExpectNothing();
61             map.get("key");
62         }
63         catch (AssertionFailedError ex) {
64             return;
65         }
66         fail("should fail one entry");
67     }
68
69     public void testFailOnVerify() {
70         ExpectationMap map = new ExpectationMap("map");
71         map.setExpectNothing();
72         map.setFailOnVerify();
73         map.get("key");
74
75         try {
76             map.verify();
77         }
78         catch (AssertionFailedError ex) {
79             return;
80         }
81         fail("should fail one entry");
82     }
83
84     public void testOverwriteEntry() {
85         ExpectationMap map = new ExpectationMap("map");
86
87         map.addExpected("key", "value");
88         map.addExpected("key", "value1");
89
90         assertEquals("overwrite entry", "value1", map.get("key"));
91         map.verify();
92     }
93 }
94
Popular Tags