KickJava   Java API By Example, From Geeks To Geeks.

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


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.ReturnObjectMap;
9
10
11 public class ReturnObjectMapTest extends TestCase
12 {
13     private ReturnObjectMap map;
14     private static final String JavaDoc KEY1 = "key1";
15     private static final String JavaDoc KEY2 = "key2";
16     private static final short SHORT_KEY1 = 1;
17     private static final short SHORT_KEY2 = 2;
18     private static final String JavaDoc VALUE_ONE = "one";
19     private static final String JavaDoc VALUE_TWO = "two";
20
21     protected void setUp() throws Exception JavaDoc {
22         super.setUp();
23         map = new ReturnObjectMap(getName());
24     }
25
26     public void testLeftoverObjectFails() {
27         map.putReturnValue(KEY1, VALUE_ONE);
28
29         AssertMo.assertVerifyFails(map);
30     }
31
32     public void testEmptyList() {
33         map.verify();
34     }
35
36     public void testReturnSucceeds() {
37         map.putReturnValue(KEY1, VALUE_ONE);
38         map.putReturnValue(KEY2, VALUE_TWO);
39
40         assertEquals("Should be first result", VALUE_ONE, map.getValue(KEY1));
41         assertEquals("Should be second result", VALUE_TWO, map.getValue(KEY2));
42         map.verify();
43     }
44
45     public void testReturnInt() {
46         map.putReturnValue(KEY1, 1);
47
48         assertEquals("Should be 1", 1, map.getIntValue(KEY1));
49         map.verify();
50     }
51
52     public void testReturnBoolean() {
53         map.putReturnValue(KEY1, true);
54
55         assertEquals("Should be true", true, map.getBooleanValue(KEY1));
56         map.verify();
57     }
58
59     public void testShortKey() {
60         map.putReturnValue(SHORT_KEY1, VALUE_ONE);
61         map.putReturnValue(SHORT_KEY2, VALUE_TWO);
62
63         assertEquals("Should be first result", VALUE_ONE, map.getValue(SHORT_KEY1));
64         assertEquals("Should be second result", VALUE_TWO, map.getValue(SHORT_KEY2));
65         map.verify();
66     }
67
68     public void testNoListForKey() {
69         try {
70             map.getValue(KEY1);
71             fail("AssertionFiledError not thrown");
72         }
73         catch (AssertionFailedError e) {
74             assertEquals(getName() + " does not contain key1", e.getMessage());
75         }
76     }
77
78     public void testNullKey() {
79         map.putReturnValue(null, VALUE_ONE);
80         assertEquals(VALUE_ONE, map.getValue(null));
81     }
82
83     public void testManyReturns() {
84         map.putReturnValue(KEY1, VALUE_ONE);
85         assertEquals(map.getValue(KEY1), map.getValue(KEY1));
86     }
87
88 }
89
Popular Tags