1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.expectation;
3
4 import junit.framework.AssertionFailedError;
5 import org.jmock.AbstractTestCase;
6
7 public class TestReturnObjectMap extends AbstractTestCase {
8 private ReturnObjectMap map;
9 private static final String KEY1 = "key1";
10 private static final String KEY2 = "key2";
11 private static final short SHORT_KEY1 = 1;
12 private static final short SHORT_KEY2 = 2;
13 private static final String VALUE_ONE = "one";
14 private static final String VALUE_TWO = "two";
15
16 protected void setUp() throws Exception {
17 super.setUp();
18 map = new ReturnObjectMap(getName());
19 }
20
21 public void testLeftoverObjectFails() {
22 map.putReturnValue(KEY1, VALUE_ONE);
23
24 assertVerifyFails(map);
25 }
26
27 public void testEmptyList() {
28 map.verify();
29 }
30
31 public void testReturnSucceeds() {
32 map.putReturnValue(KEY1, VALUE_ONE);
33 map.putReturnValue(KEY2, VALUE_TWO);
34
35 assertEquals("Should be first result", VALUE_ONE, map.getValue(KEY1));
36 assertEquals("Should be second result", VALUE_TWO, map.getValue(KEY2));
37 map.verify();
38 }
39
40 public void testReturnInt() {
41 map.putReturnValue(KEY1, 1);
42
43 assertEquals("Should be 1", 1, map.getIntValue(KEY1));
44 map.verify();
45 }
46
47 public void testReturnBoolean() {
48 map.putReturnValue(KEY1, true);
49
50 assertEquals("Should be true", true, map.getBooleanValue(KEY1));
51 map.verify();
52 }
53
54 public void testShortKey() {
55 map.putReturnValue(SHORT_KEY1, VALUE_ONE);
56 map.putReturnValue(SHORT_KEY2, VALUE_TWO);
57
58 assertEquals("Should be first result", VALUE_ONE, map.getValue(SHORT_KEY1));
59 assertEquals("Should be second result", VALUE_TWO, map.getValue(SHORT_KEY2));
60 map.verify();
61 }
62
63 public void testNoListForKey() {
64 try {
65 map.getValue(KEY1);
66 fail("AssertionFiledError not thrown");
67 } catch (AssertionFailedError e) {
68 assertEquals(getName() + " does not contain key1", e.getMessage());
69 }
70 }
71
72 public void testNullKey() {
73 map.putReturnValue(null, VALUE_ONE);
74 assertEquals(VALUE_ONE, map.getValue(null));
75 }
76
77 public void testManyReturns() {
78 map.putReturnValue(KEY1, VALUE_ONE);
79 assertEquals(map.getValue(KEY1), map.getValue(KEY1));
80 }
81
82 }
This page was automatically generated by Maven