1 3 package test.jmock; 4 5 import junit.framework.TestCase; 6 import org.jmock.MockObjectTestCase; 7 import org.jmock.core.Verifiable; 8 import org.jmock.expectation.ExpectationList; 9 10 11 public class MockObjectTestCaseTest extends TestCase 12 { 13 14 private class SampleMockObjectTestCase extends MockObjectTestCase 15 { 16 public void registerToVerify( Verifiable verifiable ) { 17 requiresVerification.addActual(verifiable.toString()); 18 } 19 20 public void testMethod() { 21 } 23 } 24 25 interface ExampleInterface 26 { 27 void expectedMethod(); 28 } 29 30 private SampleMockObjectTestCase testCase; 31 ExpectationList requiresVerification; 32 33 public void setUp() { 34 requiresVerification = new ExpectationList("registerToVerify #arguments"); 35 testCase = new SampleMockObjectTestCase() 36 { 37 }; 38 } 39 40 public void testCanBeConstructedWithAName() { 41 String name = "NAME"; 42 43 MockObjectTestCase namedTestCase = new MockObjectTestCase(name) 44 { 45 }; 46 47 assertEquals("name", name, namedTestCase.getName()); 48 } 49 50 public void testRegistersAllMocksItCreatesForVerification() throws Throwable { 51 String roleName = "ROLE-NAME"; 53 54 requiresVerification.addExpected(roleName); 56 57 testCase.mock(ExampleInterface.class, roleName); 59 testCase.verify(); 60 61 requiresVerification.verify(); 63 } 64 } 65 | Popular Tags |