1 5 package xdoclet.modules.mockobjects.util; 6 7 import java.util.Vector ; 8 9 import com.mockobjects.Verifiable; 10 11 import junit.framework.Assert; 12 13 31 public class ReturnObjectList implements Verifiable 32 { 33 private final Vector myObjects = new Vector (); 34 private final String myName; 35 private boolean myReuseLast = false; 36 private Object myLastObject; 37 38 43 public ReturnObjectList(String aName) 44 { 45 myName = aName; 46 } 47 48 53 public void setReuseLast(boolean reuseLast) 54 { 55 myReuseLast = reuseLast; 56 } 57 58 63 public void add(Object anObjectToReturn) 64 { 65 myObjects.add(anObjectToReturn); 66 67 if (null == myLastObject) { 68 myLastObject = anObjectToReturn; 69 } 70 } 71 72 77 public void add(boolean aBooleanToReturn) 78 { 79 myObjects.add(new Boolean (aBooleanToReturn)); 80 81 if (null == myLastObject) { 82 myLastObject = new Boolean (aBooleanToReturn); 83 } 84 } 85 86 91 public void add(int anIntegerToReturn) 92 { 93 myObjects.add(new Integer (anIntegerToReturn)); 94 95 if (null == myLastObject) { 96 myLastObject = new Integer (anIntegerToReturn); 97 } 98 } 99 100 107 public boolean hasNext() 108 { 109 return (myReuseLast || (myObjects.size() > 0)); 110 } 111 112 120 public Object next() 121 { 122 if (myReuseLast && (myObjects.size() == 0)) { 123 return myLastObject; 124 } 125 else { 126 Assert.assertTrue(myName + " has run out of objects.", 127 myObjects.size() > 0); 128 129 return myObjects.remove(0); 130 } 131 } 132 133 136 public void clear() 137 { 138 myObjects.clear(); 139 myLastObject = null; 140 myReuseLast = false; 141 } 142 143 146 public void verify() 147 { 148 Assert.assertEquals(myName + " has un-used objects.", 0, 149 myObjects.size()); 150 } 151 } 152 | Popular Tags |