1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.expectation;
3
4 import junit.framework.AssertionFailedError;
5
6 import java.util.Collection;
7 import java.util.Vector;
8
9 /***
10 * Sequence values as required by MockMaker
11 * This is a generic class that should have been introduced to the mockobjects code stream instead of
12 * being separately included in org.mockobjects.
13 * It is possibly similar to a ReturnObjectList?
14 */
15 public class ReturnValues {
16 private String myName;
17 protected Vector myContents = new Vector();
18 private boolean myKeepUsingLastReturnValue = false;
19
20 public ReturnValues() {
21 this("Generate me with a useful name!", true);
22 }
23
24 public ReturnValues(String name, boolean keepUsingLastReturnValue) {
25 myName = name;
26 myKeepUsingLastReturnValue = keepUsingLastReturnValue;
27 }
28
29 public ReturnValues(boolean keepUsingLastReturnValue) {
30 this("Generate me with a useful name!", keepUsingLastReturnValue);
31 }
32
33 public void add(Object element) {
34 myContents.addElement(element);
35 }
36
37 public void addAll(Collection returnValues) {
38 myContents.addAll(returnValues);
39 }
40
41 public Object getNext() {
42 if (myContents.isEmpty()) {
43 throw new AssertionFailedError(getClass().getName() + "[" + myName + "] was not setup with enough values");
44 }
45 return pop();
46 }
47
48 public boolean isEmpty() {
49 return myContents.size() == 0;
50 }
51
52 protected Object pop() {
53 Object result = myContents.firstElement();
54 boolean shouldNotRemoveElement = myContents.size() == 1 && myKeepUsingLastReturnValue;
55 if (!shouldNotRemoveElement) {
56 myContents.removeElementAt(0);
57 }
58 return result;
59 }
60 }
This page was automatically generated by Maven