1
2
3 package org.virtualmock.call;
4
5 import junit.framework.Test;
6 import junit.framework.TestCase;
7 import org.hansel.CoverageDecorator;
8 import org.virtualmock.call.InvokedCall;
9 import org.virtualmock.call.Signature;
10
11
12 /***
13 * Tests the InvokedCall class
14 *
15 * @author Chad Woolley
16 * @version $Revision: 1.1 $
17 */
18 public class InvokedCallTest extends TestCase {
19 Class classType = null;
20 InvokedCall invokedCall = null;
21 Object returnValue = null;
22 Signature signature = null;
23 String className = null;
24 String methodName = null;
25 Throwable exception = null;
26 Class[] argTypes = null;
27 Object[] argValues = null;
28
29 /***
30 * Hansel support
31 *
32 * @return the decorated Test
33 */
34 public static Test suite() {
35 CoverageDecorator cd = new CoverageDecorator(InvokedCallTest.class,
36 new Class[] { InvokedCall.class });
37 cd.setDisplayStatistics(true);
38
39 return cd;
40 }
41
42 /***
43 * Set up the test
44 *
45 * @throws Exception any exception thrown during setup.
46 */
47 public void setUp() throws Exception {
48 super.setUp();
49 classType = InvokedCall.class;
50 className = "org.virtualmock.call.InvokedCall";
51 methodName = "MyMethod";
52 argTypes = new Class[] { String.class, Integer.class };
53 argValues = new Object[] { "ARG0", new Integer(1) };
54 returnValue = "RETURN_VALUE";
55 signature = new Signature(returnValue.getClass(), classType,
56 methodName, argTypes);
57 exception = new RuntimeException("EXCEPTION");
58 }
59
60 /***
61 * Tear down the test
62 *
63 * @throws Exception any exception thrown during teardown.
64 */
65 public void tearDown() throws Exception {
66 super.tearDown();
67 }
68
69 /***
70 * Test that the constructor with args
71 */
72 public void testCanConstructWithArgs() {
73 invokedCall = new InvokedCall(signature, argValues);
74 }
75
76 /***
77 * Test that the constructor with args and a return value works
78 */
79 public void testCanConstructWithArgsAndReturnValue() {
80 invokedCall = new InvokedCall(signature, argValues, returnValue);
81 }
82
83 /***
84 * Test that the constructor with no args
85 */
86 public void testCanConstructWithNoArgs() {
87 signature = new Signature(returnValue.getClass(), classType, methodName);
88 invokedCall = new InvokedCall(signature);
89 }
90
91 /***
92 * Test that verificationCount works correctly
93 */
94 public void testIncrementVerificationCount() {
95 invokedCall = new InvokedCall(signature, argValues, exception);
96 invokedCall.incrementVerificationCount();
97 assertEquals(1, invokedCall.getVerificationCount());
98 assertTrue(invokedCall.isVerified());
99 }
100
101 /***
102 * Test that isVerified method returns false
103 */
104 public void testIndicatesIsVerifiedFalse() {
105 invokedCall = new InvokedCall(signature, argValues);
106 assertFalse(invokedCall.isVerified());
107 }
108 }