01: package net.sf.mockcreator;
02:
03: import net.sf.mockcreator.exceptions.MockException;
04: import net.sf.mockcreator.expectable.Ignore;
05: import net.sf.mockcreator.dumby.MockStatic;
06: import net.sf.mockcreator.dumby.Static;
07:
08: public class StaticTest extends TestCase {
09: MockStatic mock;
10:
11: public StaticTest(String name) {
12: super (name);
13: }
14:
15: public void setUp() throws Exception {
16: super .setUp();
17: mock = new MockStatic();
18: }
19:
20: public RuntimeException th() {
21: return new IllegalArgumentException("oops");
22: }
23:
24: public void testExpect() throws Exception {
25: mock.expectVoidMethod();
26: Static.voidMethod();
27: MockCore.verify();
28: }
29:
30: public void testExpectThrow() throws Exception {
31: mock.expectVoidMethod().throwable(th());
32:
33: try {
34: Static.voidMethod();
35: fail();
36: } catch (IllegalArgumentException ex) {
37: }
38:
39: MockCore.verify();
40: }
41:
42: public void testAccept() throws Exception {
43: mock.acceptAnotherMethod_boolean(new Ignore());
44: Static.anotherMethod(true);
45: MockCore.verify();
46: }
47:
48: public void testAcceptThrow() throws Exception {
49: mock.acceptAnotherMethod_boolean(Boolean.TRUE).throwable(th());
50:
51: try {
52: Static.anotherMethod(true);
53: fail();
54: } catch (IllegalArgumentException ex) {
55: }
56:
57: MockCore.verify();
58: }
59:
60: public void testZeroOrMore() throws Exception {
61: mock.expectZeroOrMoreAnotherMethod_boolean().throwable(th());
62:
63: try {
64: Static.anotherMethod(false);
65: fail();
66: } catch (IllegalArgumentException ex) {
67: }
68:
69: try {
70: Static.anotherMethod(true);
71: fail();
72: } catch (IllegalArgumentException ex) {
73: }
74:
75: MockCore.verify();
76: }
77:
78: public void testUnsetuped() throws Exception {
79: try {
80: Static.voidMethod();
81: fail();
82: } catch (MockException ex) {
83: }
84: }
85:
86: public void testExpectedNotCalled() throws Exception {
87: mock.expectAnotherMethod(false);
88:
89: try {
90: MockCore.verify();
91: fail();
92: } catch (MockException ex) {
93: }
94: }
95: }
|