1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.functional;
3
4 import junit.framework.AssertionFailedError;
5 import junit.framework.TestCase;
6 import org.jmock.Mock;
7
8 /***
9 * High level test of dynamic mock class.
10 */
11 public abstract class AbstractMockTest extends TestCase {
12 private MockTestActions actions;
13
14 public abstract MockTestActions createActions();
15
16 public void setUp() {
17 actions = createActions();
18 }
19
20 public void testHasDefaultNameBasedOnMockedType() {
21 Mock mock = new Mock(MockTestActions.class);
22 assertEquals("Should have same name", "mockMockTestActions", mock.toString());
23 }
24
25 public void testCanBeExplicitlyNamed() {
26 Mock otherMock = new Mock(MockTestActions.class, "otherMock");
27 assertEquals("Should have same name", "otherMock", otherMock.toString());
28 }
29
30 public void testPassesIfMockedMethodCalled() {
31 actions.expectNoParams();
32 actions.callNoParams();
33 actions.verifyMock();
34 }
35
36 public void testFailsIfMockedMethodCalledTwice() {
37 actions.expectNoParams();
38 actions.callNoParams();
39 try {
40 actions.callNoParams();
41 fail("Should have throw exception");
42 } catch (AssertionFailedError expected) {
43 return;
44 }
45 }
46
47 public void testFailsIfMockedMethodNotCalled() {
48 actions.expectNoParams();
49
50 try {
51 actions.verifyMock();
52 } catch (AssertionFailedError unused) {
53 return;
54 }
55 fail("Should have thrown exception");
56 }
57
58 public void testFailsImmediatelyIfUnexpectedMethodCalled() {
59 actions.expectNotNoParams();
60
61 try {
62 actions.callNoParams();
63 } catch (AssertionFailedError unused) {
64 return;
65 }
66 fail("Should have thrown exception");
67 }
68
69 public void testPassesIfMockedMethodCalledWithParameters() {
70 actions.expectTwoParams();
71 actions.callTwoParams();
72 actions.verifyMock();
73 }
74
75 public void testInvocationFailsIfParameterValueIncorrect() {
76 actions.expectTwoParams();
77
78 try {
79 actions.callIncorrectSecondParameter();
80 } catch (AssertionFailedError unused) {
81 return;
82 }
83 fail("Should have thrown exception");
84 }
85
86 }
This page was automatically generated by Maven