KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > ReturnObjectList


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

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

28     public ReturnObjectList(String JavaDoc aName) {
29         this.myName = aName;
30     }
31
32     /**
33      * Add a next object to the end of the list.
34      * @param anObjectToReturn object to be added to the list
35      */

36     public void addObjectToReturn(Object JavaDoc anObjectToReturn){
37         myObjects.add(anObjectToReturn);
38     }
39
40     /**
41      * Add a next boolean to the end of the list.
42      * @param aBooleanToReturn boolean to be added to the list
43      */

44     public void addObjectToReturn(boolean aBooleanToReturn){
45         myObjects.add(new Boolean JavaDoc(aBooleanToReturn));
46     }
47
48     /**
49      * Add a next integer to the end of the list.
50      * @param anIntegerToReturn integer to be added to the list
51      */

52     public void addObjectToReturn(int anIntegerToReturn){
53         myObjects.add(new Integer JavaDoc(anIntegerToReturn));
54     }
55
56     /**
57      * Returns the next object from the list. Each object it returned in the
58      * order in which they where added.
59      */

60     public Object JavaDoc nextReturnObject(){
61         AssertMo.assertTrue(myName + " has run out of objects.",
62             myObjects.size() > 0);
63         return myObjects.remove(0);
64     }
65
66     /**
67      * Verify that there are no objects left within the list.
68      */

69     public void verify() {
70         AssertMo.assertEquals(myName + " has un-used objects.", 0,
71             myObjects.size());
72     }
73 }
74
Popular Tags