KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > mockobjects > TestReturnObjectList


1 package test.mockobjects;
2
3 import junit.framework.AssertionFailedError;
4
5 import com.mockobjects.ReturnObjectList;
6 import com.mockobjects.util.TestCaseMo;
7
8 public class TestReturnObjectList extends TestCaseMo {
9     private ReturnObjectList list = new ReturnObjectList("test");
10
11     public TestReturnObjectList(String JavaDoc name) {
12         super(name);
13     }
14
15     public static void main(String JavaDoc[] args) {
16         start(new String JavaDoc[] { TestReturnObjectList.class.getName()});
17     }
18
19     public void testLeftoverObjectFails() {
20         list.addObjectToReturn("one");
21         
22         assertVerifyFails(list);
23     }
24     
25     public void testEmptyList() {
26         list.verify();
27     }
28     
29     public void testReturnSucceeds() {
30         list.addObjectToReturn("one");
31         list.addObjectToReturn("two");
32
33         assertEquals("Should be first result", "one", list.nextReturnObject());
34         assertEquals("Should be second result", "two", list.nextReturnObject());
35         list.verify();
36     }
37     
38     public void testTooManyReturns() {
39         try{
40             list.nextReturnObject();
41             fail("Error should have been raised");
42         } catch(AssertionFailedError expected){
43         }
44     }
45 }
46
Popular Tags