01: package net.sf.mockcreator;
02:
03: import junit.framework.TestResult;
04: import junit.runner.BaseTestRunner;
05: import net.sf.mockcreator.exceptions.MockException;
06:
07: public class BugVerifyIsSilentTest extends TestCase {
08:
09: private static class Caller {
10: MockBugVerifyIsSilent mock;
11:
12: public Caller() {
13: mock = new MockBugVerifyIsSilent();
14: }
15:
16: public MockBugVerifyIsSilent getMock() {
17: return mock;
18: }
19:
20: public void callFoo(int n) {
21: mock.foo(n);
22: }
23: }
24:
25: public BugVerifyIsSilentTest(String name) {
26: super (name);
27: }
28:
29: public void testVerify() throws Exception {
30: Caller caller = new Caller();
31: MockBugVerifyIsSilent mock = caller.getMock();
32:
33: mock.expectFoo(123);
34: try {
35: MockCore.verify();
36: fail();
37: } catch (MockException ex) {
38: // ok
39: }
40: }
41:
42: public void testVerify2() throws Exception {
43: Caller caller = new Caller();
44: MockBugVerifyIsSilent mock = caller.getMock();
45:
46: mock.expectFoo(123);
47: try {
48: caller.callFoo(456);
49: fail();
50: } catch (MockException ex) {
51: // ok
52: }
53:
54: MockCore.verify(); // silent
55: }
56:
57: public void testVerifyInTearDown() throws Exception {
58: Caller caller = new Caller();
59: MockBugVerifyIsSilent mock = caller.getMock();
60:
61: mock.expectFoo(123);
62:
63: try {
64: MockCore.verify();
65: fail();
66: } catch (MockException ex) {
67: }
68: }
69:
70: public void testVerifyAfterSuppressedException() throws Exception {
71: Caller caller = new Caller();
72: MockBugVerifyIsSilent mock = caller.getMock();
73:
74: Throwable throwed = null;
75:
76: mock.expectFoo(123);
77: try {
78: try {
79: caller.callFoo(123);
80: caller.callFoo(456);
81: } catch (Exception ex) {
82: fail();
83: }
84: } catch (MockException ex) {
85: // ok, not caught by catch(Exception), but suppressed
86: }
87:
88: MockCore.verify(); // should be silent
89: }
90: }
|