Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
146   274   21   9,12
0   212   0,14   16
16     1,31  
1    
 
  EasyMockSupportTest       Line # 30 146 0% 21 5 96,9% 0.9691358
 
  (26)
 
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.tests2;
18   
19    import static org.easymock.EasyMock.*;
20    import static org.junit.Assert.*;
21   
22    import org.easymock.EasyMockSupport;
23    import org.easymock.IMocksControl;
24    import org.easymock.tests.IMethods;
25    import org.junit.Test;
26   
27    /**
28    * @author Henri Tremblay
29    */
 
30    public class EasyMockSupportTest extends EasyMockSupport {
31   
32    private IMethods mock1;
33   
34    private IMethods mock2;
35   
 
36  2 toggle @Test
37    public void testCreateControl() {
38  2 final IMocksControl ctrl = createControl();
39  2 mock1 = ctrl.createMock(IMethods.class);
40  2 mock2 = ctrl.createMock(IMethods.class);
41  2 testDefaultMock();
42    }
43   
 
44  2 toggle @Test
45    public void testCreateMock() {
46  2 mock1 = createMock(IMethods.class);
47  2 mock2 = createMock(IMethods.class);
48  2 testDefaultMock();
49    }
50   
 
51  2 toggle @Test
52    public void testCreateNamedMock() {
53  2 mock1 = createMock("a", IMethods.class);
54  2 mock2 = createMock("b", IMethods.class);
55  2 testDefaultMock();
56  2 assertEquals("a", mock1.toString());
57  2 assertEquals("b", mock2.toString());
58    }
59   
 
60  6 toggle private void testDefaultMock() {
61  6 mock1.simpleMethod();
62  6 expect(mock1.oneArg(true)).andReturn("foo");
63  6 mock2.simpleMethod();
64  6 expect(mock2.oneArg(false)).andReturn("foo");
65  6 replayAll();
66  6 assertEquals("foo", mock1.oneArg(true));
67  6 assertEquals("foo", mock2.oneArg(false));
68  6 mock2.simpleMethod();
69  6 mock1.simpleMethod();
70  6 verifyAll();
71    }
72   
 
73  2 toggle @Test
74    public void testCreateNiceControl() {
75  2 final IMocksControl ctrl = createNiceControl();
76  2 mock1 = ctrl.createMock(IMethods.class);
77  2 mock2 = ctrl.createMock(IMethods.class);
78  2 testNiceMock();
79    }
80   
 
81  2 toggle @Test
82    public void testCreateNiceMock() {
83  2 mock1 = createNiceMock(IMethods.class);
84  2 mock2 = createNiceMock(IMethods.class);
85  2 testNiceMock();
86    }
87   
 
88  2 toggle @Test
89    public void testCreateNamedNiceMock() {
90  2 mock1 = createNiceMock("a", IMethods.class);
91  2 mock2 = createNiceMock("b", IMethods.class);
92  2 testNiceMock();
93  2 assertEquals("a", mock1.toString());
94  2 assertEquals("b", mock2.toString());
95    }
96   
 
97  6 toggle private void testNiceMock() {
98  6 expect(mock1.oneArg(true)).andReturn("foo");
99  6 expect(mock2.oneArg(false)).andReturn("foo");
100  6 replayAll();
101  6 assertNull(mock1.oneArg(false));
102  6 assertNull(mock2.oneArg(true));
103  6 assertEquals("foo", mock1.oneArg(true));
104  6 assertEquals("foo", mock2.oneArg(false));
105  6 verifyAll();
106    }
107   
 
108  2 toggle @Test
109    public void testCreateStrictControl() {
110  2 final IMocksControl ctrl = createStrictControl();
111  2 mock1 = ctrl.createMock(IMethods.class);
112  2 mock2 = ctrl.createMock(IMethods.class);
113  2 testStrictMock();
114  2 resetAll();
115  2 mock1.simpleMethod();
116  2 mock2.simpleMethod();
117  2 replayAll();
118  2 try {
119  2 mock2.simpleMethod();
120  0 fail("Should be ordered");
121    } catch (final AssertionError e) {
122    }
123  2 mock1.simpleMethod();
124  2 mock2.simpleMethod();
125  2 verifyAll();
126    }
127   
 
128  2 toggle @Test
129    public void testCreateStrictMock() {
130  2 mock1 = createStrictMock(IMethods.class);
131  2 mock2 = createStrictMock(IMethods.class);
132  2 testStrictMock();
133    }
134   
 
135  2 toggle @Test
136    public void testCreateNamedStrictMock() {
137  2 mock1 = createStrictMock("a", IMethods.class);
138  2 mock2 = createStrictMock("b", IMethods.class);
139  2 testStrictMock();
140  2 assertEquals("a", mock1.toString());
141  2 assertEquals("b", mock2.toString());
142    }
143   
 
144  6 toggle private void testStrictMock() {
145  6 expect(mock1.oneArg(true)).andReturn("foo");
146  6 expect(mock1.oneArg(false)).andReturn("foo");
147  6 expect(mock2.oneArg(false)).andReturn("foo");
148  6 expect(mock2.oneArg(true)).andReturn("foo");
149  6 replayAll();
150  6 try {
151  6 mock1.oneArg(false);
152  0 fail("Should be ordered");
153    } catch (final AssertionError e) {
154    }
155  6 mock1.oneArg(true);
156  6 mock1.oneArg(false);
157  6 try {
158  6 mock2.oneArg(true);
159  0 fail("Should be ordered");
160    } catch (final AssertionError e) {
161    }
162  6 mock2.oneArg(false);
163  6 mock2.oneArg(true);
164  6 verifyAll();
165    }
166   
 
167  2 toggle @Test
168    public void testVerify() {
169  2 mock1 = createMock(IMethods.class);
170  2 mock2 = createMock(IMethods.class);
171  2 mock1.simpleMethod();
172  2 mock2.simpleMethod();
173  2 replayAll();
174  2 mock1.simpleMethod();
175  2 mock2.simpleMethod();
176  2 verifyAll();
177  2 resetAll();
178  2 mock1.simpleMethod();
179  2 mock2.simpleMethod();
180  2 resetAll();
181  2 replayAll();
182  2 verifyAll();
183    }
184   
 
185  2 toggle @Test
186    public void defaultResetToNice() {
187  2 mock1 = createMock(IMethods.class);
188  2 mock2 = createMock(IMethods.class);
189   
190  2 expect(mock1.oneArg(true)).andReturn("foo");
191  2 expect(mock2.oneArg(false)).andReturn("foo");
192   
193  2 replayAll();
194   
195  2 resetAllToNice();
196   
197  2 replayAll();
198   
199  2 assertNull(mock1.oneArg(true));
200  2 assertNull(mock2.oneArg(false));
201   
202  2 verifyAll();
203    }
204   
 
205  2 toggle @Test
206    public void strictResetToDefault() {
207  2 mock1 = createStrictMock(IMethods.class);
208  2 mock2 = createStrictMock(IMethods.class);
209   
210  2 expect(mock1.oneArg(true)).andReturn("foo");
211  2 expect(mock1.oneArg(false)).andReturn("foo");
212  2 expect(mock1.oneArg(true)).andReturn("foo");
213  2 expect(mock1.oneArg(false)).andReturn("foo");
214   
215  2 replayAll();
216   
217  2 resetAllToDefault();
218   
219  2 expect(mock1.oneArg(false)).andReturn("foo");
220  2 expect(mock1.oneArg(true)).andReturn("foo");
221  2 expect(mock2.oneArg(false)).andReturn("foo");
222  2 expect(mock2.oneArg(true)).andReturn("foo");
223   
224  2 replayAll();
225   
226  2 assertEquals("foo", mock1.oneArg(false));
227  2 assertEquals("foo", mock1.oneArg(true));
228  2 assertEquals("foo", mock2.oneArg(false));
229  2 assertEquals("foo", mock2.oneArg(true));
230   
231  2 verifyAll();
232    }
233   
 
234  2 toggle @Test
235    public void niceToStrict() {
236  2 final IMethods mock1 = createNiceMock(IMethods.class);
237  2 final IMethods mock2 = createNiceMock(IMethods.class);
238   
239  2 expect(mock1.oneArg(false)).andReturn("foo");
240  2 expect(mock2.oneArg(false)).andReturn("foo");
241   
242  2 replayAll();
243   
244  2 assertNull(mock1.oneArg(true));
245  2 assertNull(mock2.oneArg(true));
246   
247  2 resetAllToStrict();
248   
249  2 expect(mock1.oneArg(false)).andReturn("foo");
250  2 expect(mock1.oneArg(true)).andReturn("foo");
251  2 expect(mock2.oneArg(false)).andReturn("foo");
252  2 expect(mock2.oneArg(true)).andReturn("foo");
253   
254  2 replayAll();
255   
256  2 try {
257  2 mock1.oneArg(true);
258  0 fail("Should be strict");
259    } catch (final AssertionError e) {
260    }
261  2 try {
262  2 mock2.oneArg(true);
263  0 fail("Should be strict");
264    } catch (final AssertionError e) {
265    }
266   
267  2 assertEquals("foo", mock1.oneArg(false));
268  2 assertEquals("foo", mock1.oneArg(true));
269  2 assertEquals("foo", mock2.oneArg(false));
270  2 assertEquals("foo", mock2.oneArg(true));
271   
272  2 verifyAll();
273    }
274    }