1
|
|
|
2
|
|
package org.jmock;
|
3
|
|
|
4
|
|
import org.jmock.dynamic.*;
|
5
|
|
import org.jmock.expectation.Verifiable;
|
6
|
|
import org.jmock.matcher.ArgumentsMatcher;
|
7
|
|
|
8
|
|
public class Mock implements Verifiable {
|
9
|
|
private InvokableFactory invokableFactory;
|
10
|
|
private DynamicMock coreMock;
|
11
|
|
|
12
|
70
|
public Mock(InvokableFactory invokableFactory, InvocationDispatcher invocationDispatcher, Class mockedClass, String name) {
|
13
|
70
|
coreMock = new CoreMock(mockedClass, name, invocationDispatcher);
|
14
|
|
|
15
|
70
|
this.invokableFactory = invokableFactory;
|
16
|
|
}
|
17
|
|
|
18
|
70
|
public Mock(Class mockedClass, String nonDefaultName) {
|
19
|
70
|
this(new InvokableFactory(), new LIFOInvocationDispatcher(), mockedClass, nonDefaultName);
|
20
|
|
}
|
21
|
|
|
22
|
60
|
public Mock(Class mockedClass) {
|
23
|
60
|
this(mockedClass, CoreMock.mockNameFromClass(mockedClass));
|
24
|
|
}
|
25
|
|
|
26
|
12
|
public String toString() {
|
27
|
12
|
return coreMock.toString();
|
28
|
|
}
|
29
|
|
|
30
|
0
|
private InvocationMatcher createConstraintMatcher(Object constraintArg) {
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
0
|
if (constraintArg instanceof Constraint[]) {
|
35
|
|
|
36
|
0
|
return new ArgumentsMatcher((Constraint[]) constraintArg);
|
37
|
0
|
} else if (constraintArg instanceof Constraint) {
|
38
|
|
|
39
|
0
|
return C.args((Constraint) constraintArg);
|
40
|
|
} else {
|
41
|
|
|
42
|
0
|
return C.args(C.eq(constraintArg));
|
43
|
|
}
|
44
|
|
}
|
45
|
|
|
46
|
12
|
public void expect(String methodName, InvocationMatcher args) {
|
47
|
12
|
coreMock.add(invokableFactory.createVoidExpectation(methodName, args));
|
48
|
|
}
|
49
|
|
|
50
|
12
|
public void expectAndReturn(String methodName, InvocationMatcher args, Object result) {
|
51
|
12
|
coreMock.add(invokableFactory.createReturnExpectation(methodName, args, result));
|
52
|
|
}
|
53
|
|
|
54
|
12
|
public void expectAndThrow(String methodName, InvocationMatcher args, Throwable throwable) {
|
55
|
12
|
coreMock.add(invokableFactory.createThrowableExpectation(methodName, args, throwable));
|
56
|
|
}
|
57
|
|
|
58
|
0
|
public void match(String methodName, InvocationMatcher args) {
|
59
|
0
|
coreMock.add(invokableFactory.createVoidStub(methodName, args));
|
60
|
|
}
|
61
|
|
|
62
|
0
|
public void matchAndReturn(String methodName, InvocationMatcher args, Object result) {
|
63
|
0
|
coreMock.add(invokableFactory.createReturnStub(methodName, args, result));
|
64
|
|
}
|
65
|
|
|
66
|
0
|
public void matchAndThrow(String methodName, InvocationMatcher args, Throwable throwable) {
|
67
|
0
|
coreMock.add(invokableFactory.createThrowableStub(methodName, args, throwable));
|
68
|
|
}
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
|
|
73
|
|
|
74
|
8
|
public void expect(String methodName) {
|
75
|
8
|
expect(methodName, C.NO_ARGS);
|
76
|
|
}
|
77
|
|
|
78
|
0
|
public void expect(String methodName, Object singleEqualArg) {
|
79
|
0
|
expect(methodName, createConstraintMatcher(singleEqualArg));
|
80
|
|
}
|
81
|
|
|
82
|
8
|
public void expectAndReturn(String methodName, Object result) {
|
83
|
8
|
expectAndReturn(methodName, C.NO_ARGS, result);
|
84
|
|
}
|
85
|
|
|
86
|
0
|
public void expectAndReturn(String methodName, boolean result) {
|
87
|
0
|
expectAndReturn(methodName, new Boolean(result));
|
88
|
|
}
|
89
|
|
|
90
|
0
|
public void expectAndReturn(String methodName, int result) {
|
91
|
0
|
expectAndReturn(methodName, new Integer(result));
|
92
|
|
}
|
93
|
|
|
94
|
0
|
public void expectAndReturn(String methodName, Object singleEqualArg, Object result) {
|
95
|
0
|
expectAndReturn(methodName, createConstraintMatcher(singleEqualArg), result);
|
96
|
|
}
|
97
|
|
|
98
|
0
|
public void expectAndReturn(String methodName, Object singleEqualArg, boolean result) {
|
99
|
0
|
expectAndReturn(methodName, singleEqualArg, new Boolean(result));
|
100
|
|
}
|
101
|
|
|
102
|
0
|
public void expectAndReturn(String methodName, Object singleEqualArg, int result) {
|
103
|
0
|
expectAndReturn(methodName, singleEqualArg, new Integer(result));
|
104
|
|
}
|
105
|
|
|
106
|
0
|
public void expectAndReturn(String methodName, InvocationMatcher args, boolean result) {
|
107
|
0
|
expectAndReturn(methodName, args, new Boolean(result));
|
108
|
|
}
|
109
|
|
|
110
|
0
|
public void expectAndReturn(String methodName, InvocationMatcher args, int result) {
|
111
|
0
|
expectAndReturn(methodName, args, new Integer(result));
|
112
|
|
}
|
113
|
|
|
114
|
8
|
public void expectAndThrow(String methodName, Throwable exception) {
|
115
|
8
|
expectAndThrow(methodName, C.NO_ARGS, exception);
|
116
|
|
}
|
117
|
|
|
118
|
0
|
public void expectAndThrow(String methodName, Object singleEqualArg, Throwable exception) {
|
119
|
0
|
expectAndThrow(methodName, createConstraintMatcher(singleEqualArg), exception);
|
120
|
|
}
|
121
|
|
|
122
|
0
|
public void match(String methodName) {
|
123
|
0
|
match(methodName, C.NO_ARGS);
|
124
|
|
}
|
125
|
|
|
126
|
0
|
public void match(String methodName, Object singleEqualArg) {
|
127
|
0
|
match(methodName, createConstraintMatcher(singleEqualArg));
|
128
|
|
}
|
129
|
|
|
130
|
0
|
public void match(String methodName, int singleEqualArg) {
|
131
|
0
|
match(methodName, new Integer(singleEqualArg));
|
132
|
|
}
|
133
|
|
|
134
|
0
|
public void match(String methodName, boolean singleEqualArg) {
|
135
|
0
|
match(methodName, new Boolean(singleEqualArg));
|
136
|
|
}
|
137
|
|
|
138
|
0
|
public void matchAndReturn(String methodName, Object result) {
|
139
|
0
|
matchAndReturn(methodName, C.NO_ARGS, result);
|
140
|
|
}
|
141
|
|
|
142
|
0
|
public void matchAndReturn(String methodName, boolean result) {
|
143
|
0
|
matchAndReturn(methodName, new Boolean(result));
|
144
|
|
}
|
145
|
|
|
146
|
0
|
public void matchAndReturn(String methodName, int result) {
|
147
|
0
|
matchAndReturn(methodName, new Integer(result));
|
148
|
|
}
|
149
|
|
|
150
|
0
|
public void matchAndReturn(String methodName, Object singleEqualArg, Object result) {
|
151
|
0
|
matchAndReturn(methodName, createConstraintMatcher(singleEqualArg), result);
|
152
|
|
}
|
153
|
|
|
154
|
0
|
public void matchAndReturn(String methodName, boolean singleEqualArg, Object result) {
|
155
|
0
|
matchAndReturn(methodName, new Boolean(singleEqualArg), result);
|
156
|
|
}
|
157
|
|
|
158
|
0
|
public void matchAndReturn(String methodName, int singleEqualArg, Object result) {
|
159
|
0
|
matchAndReturn(methodName, new Integer(singleEqualArg), result);
|
160
|
|
}
|
161
|
|
|
162
|
0
|
public void matchAndReturn(String methodName, Object singleEqualArg, boolean result) {
|
163
|
0
|
matchAndReturn(methodName, singleEqualArg, new Boolean(result));
|
164
|
|
}
|
165
|
|
|
166
|
0
|
public void matchAndReturn(String methodName, Object singleEqualArg, int result) {
|
167
|
0
|
matchAndReturn(methodName, singleEqualArg, new Integer(result));
|
168
|
|
}
|
169
|
|
|
170
|
0
|
public void matchAndReturn(String methodName, InvocationMatcher args, boolean result) {
|
171
|
0
|
matchAndReturn(methodName, args, new Boolean(result));
|
172
|
|
}
|
173
|
|
|
174
|
0
|
public void matchAndReturn(String methodName, InvocationMatcher args, int result) {
|
175
|
0
|
matchAndReturn(methodName, args, new Integer(result));
|
176
|
|
}
|
177
|
|
|
178
|
0
|
public void matchAndThrow(String methodName, Throwable throwable) {
|
179
|
0
|
matchAndThrow(methodName, C.NO_ARGS, throwable);
|
180
|
|
}
|
181
|
|
|
182
|
0
|
public void matchAndThrow(String methodName, Object singleEqualArg, Throwable throwable) {
|
183
|
0
|
matchAndThrow(methodName, createConstraintMatcher(singleEqualArg), throwable);
|
184
|
|
}
|
185
|
|
|
186
|
0
|
public void matchAndThrow(String methodName, boolean singleEqualArg, Throwable throwable) {
|
187
|
0
|
matchAndThrow(methodName, new Boolean(singleEqualArg), throwable);
|
188
|
|
}
|
189
|
|
|
190
|
0
|
public void matchAndThrow(String methodName, int singleEqualArg, Throwable throwable) {
|
191
|
0
|
matchAndThrow(methodName, new Integer(singleEqualArg), throwable);
|
192
|
|
}
|
193
|
|
|
194
|
|
|
195
|
|
|
196
|
|
|
197
|
0
|
public void expectVoid(String methodName, InvocationMatcher args) {
|
198
|
0
|
this.expect(methodName, args);
|
199
|
|
}
|
200
|
|
|
201
|
|
|
202
|
|
|
203
|
|
|
204
|
0
|
public void expectVoid(String methodName, Object equalArg) {
|
205
|
0
|
this.expect(methodName, equalArg);
|
206
|
|
}
|
207
|
|
|
208
|
|
|
209
|
|
|
210
|
|
|
211
|
0
|
public void expectVoid(String methodName) {
|
212
|
0
|
this.expect(methodName);
|
213
|
|
}
|
214
|
|
|
215
|
|
|
216
|
|
|
217
|
|
|
218
|
0
|
public void expectNotCalled(String methodName) {
|
219
|
|
}
|
220
|
|
|
221
|
58
|
public Object proxy() {
|
222
|
58
|
return coreMock.proxy();
|
223
|
|
}
|
224
|
|
|
225
|
0
|
public void reset() {
|
226
|
0
|
coreMock.reset();
|
227
|
|
}
|
228
|
|
|
229
|
18
|
public void verify() {
|
230
|
18
|
coreMock.verify();
|
231
|
|
}
|
232
|
|
|
233
|
|
}
|
234
|
|
|