1
2
3 package org.virtualmock.test.testcase;
4
5 import java.util.ArrayList;
6 import java.util.List;
7 import junit.framework.TestCase;
8 import org.easymock.MockControl;
9 import org.virtualmock.call.CallManager;
10 import org.virtualmock.call.InvokedCallQueue;
11 import org.virtualmock.call.RecordedCallQueue;
12 import org.virtualmock.resource.ResourceManager;
13 import org.virtualmock.rule.RuleManager;
14 import org.virtualmock.util.Toolbox;
15 import org.virtualmock.verify.VerificationManager;
16
17
18 /***
19 * Abstract superclass to contain common EasyMock-related functionality used in
20 * VirtualMock unit tests.
21 *
22 * @author Chad Woolley
23 * @version $Revision: 1.8 $
24 */
25 public abstract class EasyMockTestCase extends TestCase {
26 /*** EasyMock mock object */
27 protected CallManager mockCallManager = null;
28
29 /*** EasyMock control */
30 protected MockControl controlCallManager = null;
31
32 /*** EasyMock control */
33 protected MockControl controlResourceManager = null;
34
35 /*** EasyMock control */
36 protected MockControl controlRuleManager = null;
37
38 /*** EasyMock control */
39 protected MockControl controlVerificationManager = null;
40
41 /*** EasyMock mock object */
42 protected ResourceManager mockResourceManager = null;
43
44 /*** EasyMock mock object */
45 protected RuleManager mockRuleManager = null;
46
47 /*** EasyMock mock object */
48 protected VerificationManager mockVerificationManager = null;
49
50 /***
51 * Set up the test
52 *
53 * @throws Exception any exception thrown during setup.
54 */
55 public void setUp() throws Exception {
56 super.setUp();
57
58
59 Toolbox.deregisterAllComponents();
60
61
62 controlCallManager =
63 MockControl.createControl(CallManager.class,
64 new Class[] {InvokedCallQueue.class, RecordedCallQueue.class},
65 new Object[] {new InvokedCallQueue(), new RecordedCallQueue()});
66 mockCallManager = (CallManager) controlCallManager.getMock();
67 Toolbox.registerComponent(Toolbox.CALL_MANAGER, mockCallManager);
68
69
70 controlResourceManager =
71 MockControl.createControl(ResourceManager.class,
72 new Class[] {String.class, String.class, String.class},
73 new Object[] {"", "", ""});
74 mockResourceManager =
75 (ResourceManager) controlResourceManager.getMock();
76
77
78 controlRuleManager =
79 MockControl.createControl(RuleManager.class,
80 new Class[] {List.class, ResourceManager.class},
81 new Object[] {new ArrayList(), mockResourceManager});
82 mockRuleManager = (RuleManager) controlRuleManager.getMock();
83
84
85 controlVerificationManager =
86 MockControl.createControl(VerificationManager.class,
87 new Class[] {RuleManager.class}, new Object[] {mockRuleManager});
88 mockVerificationManager =
89 (VerificationManager) controlVerificationManager.getMock();
90 }
91
92 /***
93 * Tear down the test
94 *
95 * @throws Exception any exception thrown during teardown.
96 */
97 public void tearDown() throws Exception {
98
99 Toolbox.deregisterAllComponents();
100 }
101 }