KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > expectation > ReturnObjectListTest


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

3 package test.jmock.expectation;
4
5 import junit.framework.AssertionFailedError;
6 import junit.framework.TestCase;
7 import org.jmock.expectation.AssertMo;
8 import org.jmock.expectation.ReturnObjectList;
9
10
11 public class ReturnObjectListTest extends TestCase
12 {
13     private ReturnObjectList list = new ReturnObjectList("test");
14
15     public void testLeftoverObjectFails() {
16         list.addObjectToReturn("one");
17
18         AssertMo.assertVerifyFails(list);
19     }
20
21     public void testEmptyList() {
22         list.verify();
23     }
24
25     public void testReturnSucceeds() {
26         list.addObjectToReturn("one");
27         list.addObjectToReturn("two");
28
29         assertEquals("Should be first result", "one", list.nextReturnObject());
30         assertEquals("Should be second result", "two", list.nextReturnObject());
31         list.verify();
32     }
33
34     public void testTooManyReturns() {
35         try {
36             list.nextReturnObject();
37             fail("Error should have been raised");
38         }
39         catch (AssertionFailedError expected) {
40         }
41     }
42 }
43
Popular Tags