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 TestReturnObjectBag extends AbstractTestCase { 8 private ReturnObjectBag bag; 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 bag = new ReturnObjectBag(getName()); 19 } 20 21 public void testLeftoverObjectFails() { 22 bag.putObjectToReturn(KEY1, VALUE_ONE); 23 24 assertVerifyFails(bag); 25 } 26 27 public void testEmptyList() { 28 bag.verify(); 29 } 30 31 public void testReturnSucceeds() { 32 bag.putObjectToReturn(KEY1, VALUE_ONE); 33 bag.putObjectToReturn(KEY2, VALUE_TWO); 34 35 assertEquals("Should be first result", VALUE_ONE, bag.getNextReturnObject(KEY1)); 36 assertEquals("Should be second result", VALUE_TWO, bag.getNextReturnObject(KEY2)); 37 bag.verify(); 38 } 39 40 public void testReturnInt() { 41 bag.putObjectToReturn(KEY1, 1); 42 43 assertEquals("Should be 1", 1, bag.getNextReturnInt(KEY1)); 44 bag.verify(); 45 } 46 47 public void testReturnBoolean() { 48 bag.putObjectToReturn(KEY1, true); 49 50 assertEquals("Should be true", true, bag.getNextReturnBoolean(KEY1)); 51 bag.verify(); 52 } 53 54 public void testShortKey() { 55 bag.putObjectToReturn(SHORT_KEY1, VALUE_ONE); 56 bag.putObjectToReturn(SHORT_KEY2, VALUE_TWO); 57 58 assertEquals("Should be first result", VALUE_ONE, bag.getNextReturnObject(SHORT_KEY1)); 59 assertEquals("Should be second result", VALUE_TWO, bag.getNextReturnObject(SHORT_KEY2)); 60 bag.verify(); 61 } 62 63 public void testNoListForKey() { 64 try { 65 bag.getNextReturnObject(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 bag.putObjectToReturn(null, VALUE_ONE); 74 assertEquals(VALUE_ONE, bag.getNextReturnObject(null)); 75 } 76 77 public void testTooManyReturns() { 78 bag.putObjectToReturn(KEY1, VALUE_ONE); 79 bag.getNextReturnObject(KEY1); 80 try { 81 bag.getNextReturnObject(KEY1); 82 fail("AssertionFiledError not thrown"); 83 } catch (AssertionFailedError e) { 84 assertEquals(getName() + ".key1 has run out of objects.", e.getMessage()); 85 } 86 } 87 }

This page was automatically generated by Maven