1 package org.jmock.examples.website; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 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 NAME = "the-name"; 14 15 public interface Named { 16 void collectName( List 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 list = new ArrayList (); 26 ((Named)mockNamed.proxy()).collectName(list); 27 28 assertTrue("list should contain name", list.contains(NAME) ); 29 } 30 31 private Stub addListElement( Object newElement ) { 32 return new AddToListStub(newElement); 33 } 34 } 35 | Popular Tags |