KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > expectation > ReturnObjectList


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package org.jmock.expectation;
4
5 import java.util.Vector JavaDoc;
6 import org.jmock.core.Verifiable;
7
8
9 /**
10  * <p>This class allows a list of objects to be setup which can be used whilst.The
11  * list is check to make sure that all the object in it are used and that none
12  * are left over at the end of a test.</p>
13  * <p/>
14  * <p>For ever sucessive call to nextReturnObject the next object in the list will
15  * returned.</p>
16  * <p/>
17  * <p>If the nextReturnObject invokedMethod is called and there are no objects in the list
18  * an assertion error will be thrown. If the verify invokedMethod is called and there
19  * are objects still in the list an assertion error will also be thrown.</p>
20  */

21 public class ReturnObjectList implements Verifiable
22 {
23
24     private final Vector JavaDoc myObjects = new Vector JavaDoc();
25     private final String JavaDoc myName;
26
27     /**
28      * Construct a new empty list
29      *
30      * @param aName Label used to identify list
31      */

32     public ReturnObjectList( String JavaDoc aName ) {
33         this.myName = aName;
34     }
35
36     /**
37      * Add a next object to the end of the list.
38      *
39      * @param anObjectToReturn object to be added to the list
40      */

41     public void addObjectToReturn( Object JavaDoc anObjectToReturn ) {
42         myObjects.add(anObjectToReturn);
43     }
44
45     /**
46      * Add a next boolean to the end of the list.
47      *
48      * @param aBooleanToReturn boolean to be added to the list
49      */

50     public void addObjectToReturn( boolean aBooleanToReturn ) {
51         myObjects.add(new Boolean JavaDoc(aBooleanToReturn));
52     }
53
54     /**
55      * Add a next integer to the end of the list.
56      *
57      * @param anIntegerToReturn integer to be added to the list
58      */

59     public void addObjectToReturn( int anIntegerToReturn ) {
60         myObjects.add(new Integer JavaDoc(anIntegerToReturn));
61     }
62
63     /**
64      * Returns the next object from the list. Each object it returned in the
65      * order in which they where added.
66      */

67     public Object JavaDoc nextReturnObject() {
68         AssertMo.assertTrue(myName + " has run out of objects.",
69                             myObjects.size() > 0);
70         return myObjects.remove(0);
71     }
72
73     /**
74      * Verify that there are no objects left within the list.
75      */

76     public void verify() {
77         AssertMo.assertEquals(myName + " has un-used objects.", 0,
78                               myObjects.size());
79     }
80 }
81
Popular Tags