KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > MockObjectTestCaseTest


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

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             // passes
22
}
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 JavaDoc 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 JavaDoc {
51         // setup
52
String JavaDoc roleName = "ROLE-NAME";
53
54         // expect
55
requiresVerification.addExpected(roleName);
56
57         // execute
58
testCase.mock(ExampleInterface.class, roleName);
59         testCase.verify();
60
61         // verify
62
requiresVerification.verify();
63     }
64 }
65
Popular Tags