KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > examples > website > CallbackExampleTest


1 package org.jmock.examples.website;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.jmock.Mock;
7 import org.jmock.MockObjectTestCase;
8 import org.jmock.core.Stub;
9
10
11 public class CallbackExampleTest extends MockObjectTestCase
12 {
13     private static final String JavaDoc NAME = "the-name";
14
15     public interface Named {
16         void collectName( List JavaDoc list );
17     }
18
19     public void testCallbackStub() {
20         Mock mockNamed = mock(Named.class);
21
22         mockNamed.expects(once()).method("collectName").with(NOT_NULL)
23             .will(addListElement(NAME));
24         
25         List JavaDoc list = new ArrayList JavaDoc();
26         ((Named)mockNamed.proxy()).collectName(list);
27
28         assertTrue("list should contain name", list.contains(NAME) );
29     }
30
31     private Stub addListElement( Object JavaDoc newElement ) {
32         return new AddToListStub(newElement);
33     }
34 }
35
Popular Tags