Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
103   300   52   3,68
0   246   0,5   28
28     1,86  
1    
 
  RecordStateMethodCallMissingTest       Line # 30 103 0% 52 28 78,6% 0.78625953
 
  (48)
 
1    /**
2    * Copyright 2001-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.easymock.tests;
18   
19    import static org.easymock.EasyMock.*;
20    import static org.junit.Assert.*;
21   
22    import org.easymock.IAnswer;
23    import org.easymock.internal.MocksControl;
24    import org.junit.Before;
25    import org.junit.Test;
26   
27    /**
28    * @author OFFIS, Tammo Freese
29    */
 
30    public class RecordStateMethodCallMissingTest {
31   
32    private static final String METHOD_CALL_NEEDED = "method call on the mock needed before setting ";
33   
34    IMethods mock;
35   
36    MocksControl control;
37   
 
38  48 toggle @Before
39    public void setup() {
40  48 control = (MocksControl) createControl(); // this cast is a hack. It will provoke the errors below but I don't think it can happen using EasyMock normally
41  48 mock = control.createMock(IMethods.class);
42    }
43   
 
44  44 toggle private void assertMessage(final String suffix, final IllegalStateException expected) {
45  44 assertEquals(METHOD_CALL_NEEDED + suffix, expected.getMessage());
46    }
47   
 
48  2 toggle @Test
49    public void setBooleanReturnValueWithoutMethodCall() {
50  2 try {
51  2 control.andReturn(false);
52  0 fail("IllegalStateException expected");
53    } catch (final IllegalStateException expected) {
54  2 assertMessage("return value", expected);
55    }
56    }
57   
 
58  2 toggle @Test
59    public void setLongReturnValueWithoutMethodCall() {
60  2 try {
61  2 control.andReturn(0L);
62  0 fail("IllegalStateException expected");
63    } catch (final IllegalStateException expected) {
64  2 assertMessage("return value", expected);
65    }
66    }
67   
 
68  2 toggle @Test
69    public void setFloatReturnValueWithoutMethodCall() {
70  2 try {
71  2 control.andReturn(0.0f);
72  0 fail("IllegalStateException expected");
73    } catch (final IllegalStateException expected) {
74  2 assertMessage("return value", expected);
75    }
76    }
77   
 
78  2 toggle @Test
79    public void setDoubleReturnValueWithoutMethodCall() {
80  2 try {
81  2 control.andReturn(0.0);
82  0 fail("IllegalStateException expected");
83    } catch (final IllegalStateException expected) {
84  2 assertMessage("return value", expected);
85    }
86    }
87   
 
88  2 toggle @Test
89    public void setObjectReturnValueWithoutMethodCall() {
90  2 try {
91  2 control.andReturn(null);
92  0 fail("IllegalStateException expected");
93    } catch (final IllegalStateException expected) {
94  2 assertMessage("return value", expected);
95    }
96    }
97   
 
98  2 toggle @Test
99    public void setThrowableWithoutMethodCall() {
100  2 try {
101  2 control.andThrow(new RuntimeException());
102  0 fail("IllegalStateException expected");
103    } catch (final IllegalStateException expected) {
104  2 assertMessage("Throwable", expected);
105    }
106    }
107   
 
108  2 toggle @Test
109    public void setAnswerWithoutMethodCall() {
110  2 try {
111  2 control.andAnswer(new IAnswer<Object>() {
 
112  0 toggle public Object answer() throws Throwable {
113  0 return null;
114    }
115   
116    });
117  0 fail("IllegalStateException expected");
118    } catch (final IllegalStateException expected) {
119  2 assertMessage("answer", expected);
120    }
121    }
122   
 
123  2 toggle @Test
124    public void setDelegateToWithoutMethodCall() {
125  2 try {
126  2 control.andDelegateTo(null);
127  0 fail("IllegalStateException expected");
128    } catch (final IllegalStateException expected) {
129  2 assertMessage("delegate", expected);
130    }
131    }
132   
 
133  2 toggle @Test
134    public void setAnyTimesWithoutMethodCall() {
135  2 try {
136  2 control.anyTimes();
137  0 fail("IllegalStateException expected");
138    } catch (final IllegalStateException expected) {
139  2 assertMessage("times", expected);
140    }
141    }
142   
 
143  2 toggle @Test
144    public void setAtLeastOnceWithoutMethodCall() {
145  2 try {
146  2 control.atLeastOnce();
147  0 fail("IllegalStateException expected");
148    } catch (final IllegalStateException expected) {
149  2 assertMessage("times", expected);
150    }
151    }
152   
 
153  2 toggle @Test
154    public void setTimesWithoutMethodCall() {
155  2 try {
156  2 control.times(3);
157  0 fail("IllegalStateException expected");
158    } catch (final IllegalStateException expected) {
159  2 assertMessage("times", expected);
160    }
161    }
162   
 
163  2 toggle @Test
164    public void setTimesMinMaxWithoutMethodCall() {
165  2 try {
166  2 control.times(1, 3);
167  0 fail("IllegalStateException expected");
168    } catch (final IllegalStateException expected) {
169  2 assertMessage("times", expected);
170    }
171    }
172   
 
173  2 toggle @Test
174    public void setOnceWithoutMethodCall() {
175  2 try {
176  2 control.once();
177  0 fail("IllegalStateException expected");
178    } catch (final IllegalStateException expected) {
179  2 assertMessage("times", expected);
180    }
181    }
182   
 
183  2 toggle @Test
184    public void setBooleanDefaultReturnValueWithoutMethodCall() {
185  2 try {
186  2 control.andStubReturn(false);
187  0 fail("IllegalStateException expected");
188    } catch (final IllegalStateException expected) {
189  2 assertMessage("stub return value", expected);
190    }
191    }
192   
 
193  2 toggle @Test
194    public void setLongDefaultReturnValueWithoutMethodCall() {
195  2 try {
196  2 control.andStubReturn(0L);
197  0 fail("IllegalStateException expected");
198    } catch (final IllegalStateException expected) {
199  2 assertMessage("stub return value", expected);
200    }
201    }
202   
 
203  2 toggle @Test
204    public void setFloatDefaultReturnValueWithoutMethodCall() {
205  2 try {
206  2 control.andStubReturn(0.0f);
207  0 fail("IllegalStateException expected");
208    } catch (final IllegalStateException expected) {
209  2 assertMessage("stub return value", expected);
210    }
211    }
212   
 
213  2 toggle @Test
214    public void setDoubleDefaultReturnValueWithoutMethodCall() {
215  2 try {
216  2 control.andStubReturn(0.0);
217  0 fail("IllegalStateException expected");
218    } catch (final IllegalStateException expected) {
219  2 assertMessage("stub return value", expected);
220    }
221    }
222   
 
223  2 toggle @Test
224    public void setObjectDefaultReturnValueWithoutMethodCall() {
225  2 try {
226  2 control.andStubReturn(null);
227  0 fail("IllegalStateException expected");
228    } catch (final IllegalStateException expected) {
229  2 assertMessage("stub return value", expected);
230    }
231    }
232   
 
233  2 toggle @Test
234    public void setDefaultVoidCallableWithoutMethodCall() {
235  2 try {
236  2 control.asStub();
237  0 fail("IllegalStateException expected");
238    } catch (final IllegalStateException expected) {
239  2 assertMessage("stub behavior", expected);
240    }
241    }
242   
 
243  2 toggle @Test
244    public void setDefaultThrowableWithoutMethodCall() {
245  2 try {
246  2 control.andStubThrow(new RuntimeException());
247  0 fail("IllegalStateException expected");
248    } catch (final IllegalStateException expected) {
249  2 assertMessage("stub Throwable", expected);
250    }
251    }
252   
 
253  2 toggle @Test
254    public void setStubAnswerWithoutMethodCall() {
255  2 try {
256  2 control.andStubAnswer(new IAnswer<Object>() {
 
257  0 toggle public Object answer() throws Throwable {
258  0 return null;
259    }
260   
261    });
262  0 fail("IllegalStateException expected");
263    } catch (final IllegalStateException expected) {
264  2 assertMessage("stub answer", expected);
265    }
266    }
267   
 
268  2 toggle @Test
269    public void setStubDelegateToWithoutMethodCall() {
270  2 try {
271  2 control.andStubDelegateTo(null);
272  0 fail("IllegalStateException expected");
273    } catch (final IllegalStateException expected) {
274  2 assertMessage("stub delegate", expected);
275    }
276    }
277   
 
278  2 toggle @Test
279    public void timesWithoutReturnValue() {
280  2 mock.booleanReturningMethod(1);
281  2 try {
282  2 expectLastCall().times(3);
283  0 fail();
284    } catch (final IllegalStateException expected) {
285  2 assertEquals("last method called on mock is not a void method", expected.getMessage());
286    }
287    }
288   
 
289  2 toggle @Test
290    public void asStubWithNonVoidMethod() {
291  2 mock.booleanReturningMethod(1);
292  2 try {
293  2 expectLastCall().asStub();
294  0 fail();
295    } catch (final IllegalStateException expected) {
296  2 assertEquals("last method called on mock is not a void method", expected.getMessage());
297    }
298    }
299   
300    }