EasyMock 2.3

Clover coverage report - EasyMock 2.3
Coverage timestamp: mar. juil. 10 2007 02:46:04 CEST
FRAMES NO FRAMES

file stats: | LOC: | 250 |  | Methods: | 26
| NCLOC: | 200 |  | Classes: | 2

Source file | Conditionals | Statements | Methods | TOTAL

MocksControl.java

-

100%

100%

100%

1 |  | /*
2 |  | * Copyright (c) 2001-2007 OFFIS, Tammo Freese.
3 |  | * This program is made available under the terms of the MIT License.
4 |  | */
5 |  | package org.easymock.internal;
6 |  |
7 |  | import org.easymock.ArgumentsMatcher;
8 |  | import org.easymock.IAnswer;
9 |  | import org.easymock.IExpectationSetters;
10 |  | import org.easymock.IMocksControl;
11 |  |
12 |  | public class MocksControl implements IMocksControl {
13 |  |
14 |  | private IMocksControlState state;
15 |  |
16 |  | private IMocksBehavior behavior;
17 |  |
18 |  | public enum MockType {
19 |  | NICE, DEFAULT, STRICT
20 |  | }
21 |  |
22 |  | private final MockType type;
23 |  |
24 | 461 | public MocksControl(MockType type) {
25 | 461 | this.type = type;
26 | 461 | reset();
27 |  | }
28 |  |
29 | 2044 | public IMocksControlState getState() {
30 | 2044 | return state;
31 |  | }
32 |  |
33 | 371 | public <T> T createMock(Class<T> toMock) {
34 | 371 | try {
35 | 371 | state.assertRecordState();
36 | 370 | IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
37 | 370 | return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
38 |  | toMock, new MockInvocationHandler(this), null));
39 |  | } catch (RuntimeExceptionWrapper e) {
40 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
41 |  | }
42 |  | }
43 |  |
44 | 6 | public <T> T createMock(String name, Class<T> toMock) {
45 | 6 | try {
46 | 6 | state.assertRecordState();
47 | 5 | IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
48 | 5 | return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
49 |  | toMock, new MockInvocationHandler(this), name));
50 |  | } catch (RuntimeExceptionWrapper e) {
51 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
52 |  | }
53 |  | }
54 |  |
55 | 375 | protected <T> IProxyFactory<T> createProxyFactory(Class<T> toMock) {
56 | 375 | return new JavaProxyFactory<T>();
57 |  | }
58 |  |
59 | 470 | public final void reset() {
60 | 470 | behavior = new MocksBehavior(type == MockType.NICE);
61 | 470 | behavior.checkOrder(type == MockType.STRICT);
62 | 470 | state = new RecordState(behavior);
63 | 470 | LastControl.reportLastControl(null);
64 |  | }
65 |  |
66 | 384 | public void replay() {
67 | 384 | try {
68 | 384 | state.replay();
69 | 380 | state = new ReplayState(behavior);
70 | 380 | LastControl.reportLastControl(null);
71 |  | } catch (RuntimeExceptionWrapper e) {
72 | 2 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
73 |  | }
74 |  | }
75 |  |
76 | 172 | public void verify() {
77 | 172 | try {
78 | 172 | state.verify();
79 |  | } catch (RuntimeExceptionWrapper e) {
80 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
81 |  | } catch (AssertionErrorWrapper e) {
82 | 20 | throw (AssertionError) e.getAssertionError().fillInStackTrace();
83 |  | }
84 |  | }
85 |  |
86 | 4 | public void checkOrder(boolean value) {
87 | 4 | try {
88 | 4 | state.checkOrder(value);
89 |  | } catch (RuntimeExceptionWrapper e) {
90 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
91 |  | }
92 |  | }
93 |  |
94 |  | // methods from IBehaviorSetters
95 |  |
96 | 247 | public IExpectationSetters andReturn(Object value) {
97 | 247 | try {
98 | 247 | state.andReturn(value);
99 | 228 | return this;
100 |  | } catch (RuntimeExceptionWrapper e) {
101 | 19 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
102 |  | }
103 |  | }
104 |  |
105 | 45 | public IExpectationSetters andThrow(Throwable throwable) {
106 | 45 | try {
107 | 45 | state.andThrow(throwable);
108 | 42 | return this;
109 |  | } catch (RuntimeExceptionWrapper e) {
110 | 3 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
111 |  | }
112 |  | }
113 |  |
114 | 9 | public IExpectationSetters andAnswer(IAnswer answer) {
115 | 9 | try {
116 | 9 | state.andAnswer(answer);
117 | 8 | return this;
118 |  | } catch (RuntimeExceptionWrapper e) {
119 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
120 |  | }
121 |  | }
122 |  |
123 | 24 | public void andStubReturn(Object value) {
124 | 24 | try {
125 | 24 | state.andStubReturn(value);
126 |  | } catch (RuntimeExceptionWrapper e) {
127 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
128 |  | }
129 |  | }
130 |  |
131 | 7 | public void andStubThrow(Throwable throwable) {
132 | 7 | try {
133 | 7 | state.andStubThrow(throwable);
134 |  | } catch (RuntimeExceptionWrapper e) {
135 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
136 |  | }
137 |  | }
138 |  |
139 | 3 | public void andStubAnswer(IAnswer answer) {
140 | 3 | try {
141 | 3 | state.andStubAnswer(answer);
142 |  | } catch (RuntimeExceptionWrapper e) {
143 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
144 |  | }
145 |  | }
146 |  |
147 | 3 | public void asStub() {
148 | 3 | try {
149 | 3 | state.asStub();
150 |  | } catch (RuntimeExceptionWrapper e) {
151 | 2 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
152 |  | }
153 |  | }
154 |  |
155 | 31 | public IExpectationSetters times(int times) {
156 | 31 | try {
157 | 31 | state.times(new Range(times));
158 | 29 | return this;
159 |  | } catch (RuntimeExceptionWrapper e) {
160 | 2 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
161 |  | }
162 |  | }
163 |  |
164 | 17 | public IExpectationSetters times(int min, int max) {
165 | 17 | try {
166 | 17 | state.times(new Range(min, max));
167 | 14 | return this;
168 |  | } catch (RuntimeExceptionWrapper e) {
169 | 3 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
170 |  | }
171 |  | }
172 |  |
173 | 104 | public IExpectationSetters once() {
174 | 104 | try {
175 | 104 | state.times(ONCE);
176 | 103 | return this;
177 |  | } catch (RuntimeExceptionWrapper e) {
178 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
179 |  | }
180 |  | }
181 |  |
182 | 31 | public IExpectationSetters atLeastOnce() {
183 | 31 | try {
184 | 31 | state.times(AT_LEAST_ONCE);
185 | 30 | return this;
186 |  | } catch (RuntimeExceptionWrapper e) {
187 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
188 |  | }
189 |  | }
190 |  |
191 | 6 | public IExpectationSetters anyTimes() {
192 | 6 | try {
193 | 6 | state.times(ZERO_OR_MORE);
194 | 5 | return this;
195 |  | } catch (RuntimeExceptionWrapper e) {
196 | 1 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
197 |  | }
198 |  | }
199 |  |
200 |  | /**
201 |  | * Exactly one call.
202 |  | */
203 |  | public static final Range ONCE = new Range(1);
204 |  |
205 |  | /**
206 |  | * One or more calls.
207 |  | */
208 |  | public static final Range AT_LEAST_ONCE = new Range(1, Integer.MAX_VALUE);
209 |  |
210 |  | /**
211 |  | * Zero or more calls.
212 |  | */
213 |  | public static final Range ZERO_OR_MORE = new Range(0, Integer.MAX_VALUE);
214 |  |
215 | 8 | public void setLegacyDefaultMatcher(ArgumentsMatcher matcher) {
216 | 8 | try {
217 | 8 | state.setDefaultMatcher(matcher);
218 |  | } catch (RuntimeExceptionWrapper e) {
219 | 3 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
220 |  | }
221 |  | }
222 |  |
223 | 15 | public void setLegacyMatcher(ArgumentsMatcher matcher) {
224 | 15 | try {
225 | 15 | state.setMatcher(null, matcher);
226 |  | } catch (RuntimeExceptionWrapper e) {
227 | 4 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
228 |  | }
229 |  | }
230 |  |
231 | 36 | public void setLegacyDefaultReturnValue(Object value) {
232 | 36 | try {
233 | 36 | state.setDefaultReturnValue(value);
234 |  | } catch (RuntimeExceptionWrapper e) {
235 | 16 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
236 |  | }
237 |  | }
238 |  |
239 | 1 | public void setLegacyDefaultVoidCallable() {
240 | 1 | state.setDefaultVoidCallable();
241 |  | }
242 |  |
243 | 9 | public void setLegacyDefaultThrowable(Throwable throwable) {
244 | 9 | try {
245 | 9 | state.setDefaultThrowable(throwable);
246 |  | } catch (RuntimeExceptionWrapper e) {
247 | 6 | throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
248 |  | }
249 |  | }
250 |  | }