1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.functional;
3
4 import org.jmock.C;
5 import org.jmock.Mock;
6 import org.jmock.functional.AbstractMockTest;
7 import org.jmock.functional.MockTestActions;
8
9
10 public class ThrowableMockTest extends AbstractMockTest {
11 public class TargetException extends Exception {
12 };
13 public interface TargetType {
14 void noParams() throws TargetException;
15
16 void oneParam(Object aParam) throws TargetException;
17
18 void twoParams(Object param1, Object param2) throws TargetException;
19 }
20
21 public class ReturnMockTestActions implements MockTestActions {
22 private Mock mockTarget = new Mock(TargetType.class);
23 private TargetType targetType = ((TargetType) mockTarget.proxy());
24
25 public void expectNoParams() {
26 mockTarget.expectAndThrow("noParams", new TargetException());
27 }
28
29 public void expectOneParam() {
30 mockTarget.expectAndThrow("oneParam", "one", new TargetException());
31 }
32
33 public void expectTwoParams() {
34 mockTarget.expectAndThrow("twoParams", C.eq("one", "two"), new TargetException());
35 }
36
37 public void expectNotNoParams() {
38 mockTarget.expectAndThrow("notNoParams", new TargetException());
39 }
40
41 public void callNoParams() {
42 try {
43 targetType.noParams();
44 } catch (TargetException expected) {
45 return;
46 }
47 fail("Should have thrown exception");
48 }
49
50 public void callOneParam() {
51 try {
52 targetType.oneParam("one");
53 } catch (TargetException expected) {
54 return;
55 }
56 fail("Should have thrown exception");
57 }
58
59 public void callTwoParams() {
60 try {
61 targetType.twoParams("one", "two");
62 } catch (TargetException expected) {
63 return;
64 }
65 fail("Should have thrown exception");
66 }
67
68 public void callIncorrectSecondParameter() {
69 try {
70 targetType.twoParams("one", "not two");
71 } catch (TargetException e) {
72 return; // skip
73 }
74 }
75
76 public void verifyMock() {
77 mockTarget.verify();
78 }
79 }
80
81 public MockTestActions createActions() {
82 return new ReturnMockTestActions();
83 }
84
85 public void testMethodToMakeTestRunnerNoticeTestCase() {
86 }
87 }
This page was automatically generated by Maven