|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ReturnObjectList.java | - | 71.4% | 66.7% | 69.2% |
|
1 |
/* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
|
|
2 |
package org.jmock.expectation;
|
|
3 |
|
|
4 |
import java.util.Vector;
|
|
5 |
|
|
6 |
/**
|
|
7 |
* <p>This class allows a list of objects to be setup which can be used whilst.The
|
|
8 |
* list is check to make sure that all the object in it are used and that none
|
|
9 |
* are left over at the end of a test.</p>
|
|
10 |
* <p/>
|
|
11 |
* <p>For ever sucessive call to nextReturnObject the next object in the list will
|
|
12 |
* returned.</p>
|
|
13 |
* <p/>
|
|
14 |
* <p>If the nextReturnObject method is called and there are no objects in the list
|
|
15 |
* an assertion error will be thrown. If the verify method is called and there
|
|
16 |
* are objects still in the list an assertion error will also be thrown.</p>
|
|
17 |
*/
|
|
18 |
public class ReturnObjectList implements Verifiable { |
|
19 |
|
|
20 |
private final Vector myObjects = new Vector(); |
|
21 |
private final String myName;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Construct a new empty list
|
|
25 |
*
|
|
26 |
* @param aName Label used to identify list
|
|
27 |
*/
|
|
28 | 26 |
public ReturnObjectList(String aName) {
|
29 | 26 |
this.myName = aName;
|
30 |
} |
|
31 |
|
|
32 |
/**
|
|
33 |
* Add a next object to the end of the list.
|
|
34 |
*
|
|
35 |
* @param anObjectToReturn object to be added to the list
|
|
36 |
*/
|
|
37 | 24 |
public void addObjectToReturn(Object anObjectToReturn) { |
38 | 24 |
myObjects.add(anObjectToReturn); |
39 |
} |
|
40 |
|
|
41 |
/**
|
|
42 |
* Add a next boolean to the end of the list.
|
|
43 |
*
|
|
44 |
* @param aBooleanToReturn boolean to be added to the list
|
|
45 |
*/
|
|
46 | 0 |
public void addObjectToReturn(boolean aBooleanToReturn) { |
47 | 0 |
myObjects.add(new Boolean(aBooleanToReturn));
|
48 |
} |
|
49 |
|
|
50 |
/**
|
|
51 |
* Add a next integer to the end of the list.
|
|
52 |
*
|
|
53 |
* @param anIntegerToReturn integer to be added to the list
|
|
54 |
*/
|
|
55 | 0 |
public void addObjectToReturn(int anIntegerToReturn) { |
56 | 0 |
myObjects.add(new Integer(anIntegerToReturn));
|
57 |
} |
|
58 |
|
|
59 |
/**
|
|
60 |
* Returns the next object from the list. Each object it returned in the
|
|
61 |
* order in which they where added.
|
|
62 |
*/
|
|
63 | 24 |
public Object nextReturnObject() {
|
64 | 24 |
AssertMo.assertTrue(myName + " has run out of objects.",
|
65 |
myObjects.size() > 0); |
|
66 | 20 |
return myObjects.remove(0);
|
67 |
} |
|
68 |
|
|
69 |
/**
|
|
70 |
* Verify that there are no objects left within the list.
|
|
71 |
*/
|
|
72 | 20 |
public void verify() { |
73 | 20 |
AssertMo.assertEquals(myName + " has un-used objects.", 0,
|
74 |
myObjects.size()); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|