1 3 package org.jmock.expectation; 4 5 import java.util.Hashtable ; 6 import java.util.Iterator ; 7 import org.jmock.core.Verifiable; 8 9 10 22 public class ReturnObjectBag implements Verifiable 23 { 24 private final Hashtable returnObjectLists = new Hashtable (); 25 private final String name; 26 27 30 public ReturnObjectBag( String name ) { 31 this.name = name; 32 } 33 34 41 public void putObjectToReturn( Object key, Object value ) { 42 if (key == null) { 43 key = Null.NULL; 44 } 45 ReturnObjectList returnObjectList = (ReturnObjectList)returnObjectLists.get(key); 46 if (returnObjectList == null) { 47 returnObjectList = new ReturnObjectList(name + "." + key.toString()); 48 returnObjectLists.put(key, returnObjectList); 49 } 50 51 returnObjectList.addObjectToReturn(value); 52 } 53 54 61 public void putObjectToReturn( int key, Object value ) { 62 putObjectToReturn(new Integer (key), value); 63 } 64 65 74 public void putObjectToReturn( Object key, int value ) { 75 putObjectToReturn(key, new Integer (value)); 76 } 77 78 87 public void putObjectToReturn( Object key, boolean value ) { 88 putObjectToReturn(key, new Boolean (value)); 89 } 90 91 97 public void verify() { 98 for (Iterator it = returnObjectLists.values().iterator(); it.hasNext();) { 99 ((ReturnObjectList)it.next()).verify(); 100 } 101 } 102 103 112 public Object getNextReturnObject( Object key ) { 113 if (key == null) { 114 key = Null.NULL; 115 } 116 ReturnObjectList returnObjectList = (ReturnObjectList)returnObjectLists.get(key); 117 AssertMo.assertNotNull(name + " does not contain " + key.toString(), returnObjectList); 118 return returnObjectList.nextReturnObject(); 119 } 120 121 130 public Object getNextReturnObject( int key ) { 131 return getNextReturnObject(new Integer (key)); 132 } 133 134 public Hashtable getHashTable() { 135 return returnObjectLists; 136 } 137 138 public int getNextReturnInt( Object key ) { 139 return ((Integer )getNextReturnObject(key)).intValue(); 140 } 141 142 public boolean getNextReturnBoolean( Object key ) { 143 return ((Boolean )getNextReturnObject(key)).booleanValue(); 144 } 145 } 146 | Popular Tags |