Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
97   279   53   3,23
0   223   0,55   15
30     1,77  
2    
 
 
  MocksControl       Line # 13 97 53 100% 1.0
  MocksControl.MockType       Line # 21 0 0 - -1.0
 
  (298)
 
1    /*
2    * Copyright (c) 2001-2008 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 java.io.Serializable;
8   
9    import org.easymock.IAnswer;
10    import org.easymock.IExpectationSetters;
11    import org.easymock.IMocksControl;
12   
 
13    public class MocksControl implements IMocksControl, IExpectationSetters<Object>, Serializable {
14   
15    private static final long serialVersionUID = 443604921336702014L;
16   
17    private IMocksControlState state;
18   
19    private IMocksBehavior behavior;
20   
 
21    public enum MockType {
22    NICE, DEFAULT, STRICT
23    }
24   
25    private MockType type;
26   
 
27  486 toggle public MocksControl(MockType type) {
28  486 this.type = type;
29  486 reset();
30    }
31   
 
32  2242 toggle public IMocksControlState getState() {
33  2242 return state;
34    }
35   
 
36  395 toggle public <T> T createMock(Class<T> toMock) {
37  395 try {
38  395 state.assertRecordState();
39  394 IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
40  394 return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
41    toMock, new MockInvocationHandler(this), null));
42    } catch (RuntimeExceptionWrapper e) {
43  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
44    }
45    }
46   
 
47  6 toggle public <T> T createMock(String name, Class<T> toMock) {
48  6 try {
49  6 state.assertRecordState();
50  5 IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
51  5 return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
52    toMock, new MockInvocationHandler(this), name));
53    } catch (RuntimeExceptionWrapper e) {
54  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
55    }
56    }
57   
 
58  399 toggle protected <T> IProxyFactory<T> createProxyFactory(Class<T> toMock) {
59  399 return new JavaProxyFactory<T>();
60    }
61   
 
62  498 toggle public final void reset() {
63  498 behavior = new MocksBehavior(type == MockType.NICE);
64  498 behavior.checkOrder(type == MockType.STRICT);
65  498 behavior.makeThreadSafe(false);
66  498 state = new RecordState(behavior);
67  498 LastControl.reportLastControl(null);
68    }
69   
 
70  1 toggle public void resetToNice() {
71  1 type = MockType.NICE;
72  1 reset();
73    }
74   
 
75  1 toggle public void resetToDefault() {
76  1 type = MockType.DEFAULT;
77  1 reset();
78    }
79   
 
80  1 toggle public void resetToStrict() {
81  1 type = MockType.STRICT;
82  1 reset();
83    }
84   
 
85  407 toggle public void replay() {
86  407 try {
87  407 state.replay();
88  403 state = new ReplayState(behavior);
89  403 LastControl.reportLastControl(null);
90    } catch (RuntimeExceptionWrapper e) {
91  2 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
92    }
93    }
94   
 
95  186 toggle public void verify() {
96  186 try {
97  186 state.verify();
98    } catch (RuntimeExceptionWrapper e) {
99  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
100    } catch (AssertionErrorWrapper e) {
101  19 throw (AssertionError) e.getAssertionError().fillInStackTrace();
102    }
103    }
104   
 
105  4 toggle public void checkOrder(boolean value) {
106  4 try {
107  4 state.checkOrder(value);
108    } catch (RuntimeExceptionWrapper e) {
109  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
110    }
111    }
112   
 
113  2 toggle public void makeThreadSafe(boolean threadSafe) {
114  2 try {
115  2 state.makeThreadSafe(threadSafe);
116    } catch (RuntimeExceptionWrapper e) {
117  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
118    }
119    }
120   
121    // methods from IBehaviorSetters
122   
 
123  274 toggle public IExpectationSetters<Object> andReturn(Object value) {
124  274 try {
125  274 state.andReturn(value);
126  255 return this;
127    } catch (RuntimeExceptionWrapper e) {
128  19 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
129    }
130    }
131   
 
132  43 toggle public IExpectationSetters<Object> andThrow(Throwable throwable) {
133  43 try {
134  43 state.andThrow(throwable);
135  40 return this;
136    } catch (RuntimeExceptionWrapper e) {
137  3 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
138    }
139    }
140   
 
141  10 toggle public IExpectationSetters<Object> andAnswer(IAnswer<? extends Object> answer) {
142  10 try {
143  10 state.andAnswer(answer);
144  9 return this;
145    } catch (RuntimeExceptionWrapper e) {
146  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
147    }
148    }
149   
 
150  24 toggle public void andStubReturn(Object value) {
151  24 try {
152  24 state.andStubReturn(value);
153    } catch (RuntimeExceptionWrapper e) {
154  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
155    }
156    }
157   
 
158  7 toggle public void andStubThrow(Throwable throwable) {
159  7 try {
160  7 state.andStubThrow(throwable);
161    } catch (RuntimeExceptionWrapper e) {
162  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
163    }
164    }
165   
 
166  4 toggle public void andStubAnswer(IAnswer<? extends Object> answer) {
167  4 try {
168  4 state.andStubAnswer(answer);
169    } catch (RuntimeExceptionWrapper e) {
170  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
171    }
172    }
173   
 
174  3 toggle public void asStub() {
175  3 try {
176  3 state.asStub();
177    } catch (RuntimeExceptionWrapper e) {
178  2 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
179    }
180    }
181   
 
182  34 toggle public IExpectationSetters<Object> times(int times) {
183  34 try {
184  34 state.times(new Range(times));
185  32 return this;
186    } catch (RuntimeExceptionWrapper e) {
187  2 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
188    }
189    }
190   
 
191  17 toggle public IExpectationSetters<Object> times(int min, int max) {
192  17 try {
193  17 state.times(new Range(min, max));
194  14 return this;
195    } catch (RuntimeExceptionWrapper e) {
196  3 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
197    }
198    }
199   
 
200  103 toggle public IExpectationSetters<Object> once() {
201  103 try {
202  103 state.times(ONCE);
203  102 return this;
204    } catch (RuntimeExceptionWrapper e) {
205  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
206    }
207    }
208   
 
209  30 toggle public IExpectationSetters<Object> atLeastOnce() {
210  30 try {
211  30 state.times(AT_LEAST_ONCE);
212  29 return this;
213    } catch (RuntimeExceptionWrapper e) {
214  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
215    }
216    }
217   
 
218  7 toggle public IExpectationSetters<Object> anyTimes() {
219  7 try {
220  7 state.times(ZERO_OR_MORE);
221  6 return this;
222    } catch (RuntimeExceptionWrapper e) {
223  1 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
224    }
225    }
226   
227    /**
228    * Exactly one call.
229    */
230    public static final Range ONCE = new Range(1);
231   
232    /**
233    * One or more calls.
234    */
235    public static final Range AT_LEAST_ONCE = new Range(1, Integer.MAX_VALUE);
236   
237    /**
238    * Zero or more calls.
239    */
240    public static final Range ZERO_OR_MORE = new Range(0, Integer.MAX_VALUE);
241   
 
242  8 toggle @SuppressWarnings("deprecation")
243    public void setLegacyDefaultMatcher(org.easymock.ArgumentsMatcher matcher) {
244  8 try {
245  8 state.setDefaultMatcher(matcher);
246    } catch (RuntimeExceptionWrapper e) {
247  3 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
248    }
249    }
250   
 
251  15 toggle @SuppressWarnings("deprecation")
252    public void setLegacyMatcher(org.easymock.ArgumentsMatcher matcher) {
253  15 try {
254  15 state.setMatcher(null, matcher);
255    } catch (RuntimeExceptionWrapper e) {
256  4 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
257    }
258    }
259   
 
260  36 toggle public void setLegacyDefaultReturnValue(Object value) {
261  36 try {
262  36 state.setDefaultReturnValue(value);
263    } catch (RuntimeExceptionWrapper e) {
264  16 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
265    }
266    }
267   
 
268  1 toggle public void setLegacyDefaultVoidCallable() {
269  1 state.setDefaultVoidCallable();
270    }
271   
 
272  9 toggle public void setLegacyDefaultThrowable(Throwable throwable) {
273  9 try {
274  9 state.setDefaultThrowable(throwable);
275    } catch (RuntimeExceptionWrapper e) {
276  6 throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
277    }
278    }
279    }