Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
50   144   17   3,33
0   105   0,34   7,5
15     1,13  
2    
 
  UsageCallCountTest       Line # 28 50 0% 17 2 96,9% 0.9692308
  UsageCallCountTest.VoidMethodInterface       Line # 32 0 - 0 0 - -1.0
 
  (18)
 
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.junit.Before;
23    import org.junit.Test;
24   
25    /**
26    * @author OFFIS, Tammo Freese
27    */
 
28    public class UsageCallCountTest {
29   
30    private VoidMethodInterface mock;
31   
 
32    private interface VoidMethodInterface {
33    void method();
34    }
35   
 
36  18 toggle @Before
37    public void setup() {
38  18 mock = createMock(VoidMethodInterface.class);
39    }
40   
 
41  2 toggle @Test
42    public void mockWithNoExpectedCallsPassesWithNoCalls() {
43  2 replay(mock);
44  2 verify(mock);
45    }
46   
 
47  2 toggle @Test
48    public void mockWithNoExpectedCallsFailsAtFirstCall() {
49  2 replay(mock);
50  2 assertMethodCallFails();
51    }
52   
 
53  2 toggle @Test
54    public void mockWithOneExpectedCallFailsAtVerify() {
55  2 callMethodOnce();
56  2 replay(mock);
57  2 assertVerifyFails();
58    }
59   
 
60  2 toggle @Test
61    public void mockWithOneExpectedCallPassesWithOneCall() {
62  2 callMethodOnce();
63  2 replay(mock);
64  2 callMethodOnce();
65  2 verify(mock);
66    }
67   
 
68  2 toggle @Test
69    public void mockWithOneExpectedCallFailsAtSecondCall() {
70  2 callMethodOnce();
71  2 replay(mock);
72  2 callMethodOnce();
73  2 assertMethodCallFails();
74    }
75   
 
76  2 toggle @Test
77    public void tooFewCalls() {
78  2 callMethodThreeTimes();
79  2 replay(mock);
80  2 callMethodTwice();
81  2 assertVerifyFails();
82    }
83   
 
84  2 toggle @Test
85    public void correctNumberOfCalls() {
86  2 callMethodThreeTimes();
87  2 replay(mock);
88  2 callMethodThreeTimes();
89  2 verify(mock);
90    }
91   
 
92  2 toggle @Test
93    public void tooManyCalls() {
94  2 callMethodThreeTimes();
95  2 replay(mock);
96  2 callMethodThreeTimes();
97  2 assertMethodCallFails();
98    }
99   
 
100  10 toggle private void callMethodOnce() {
101  10 mock.method();
102    }
103   
 
104  2 toggle private void callMethodTwice() {
105  2 mock.method();
106  2 mock.method();
107    }
108   
 
109  10 toggle private void callMethodThreeTimes() {
110  10 mock.method();
111  10 mock.method();
112  10 mock.method();
113    }
114   
 
115  6 toggle private void assertVerifyFails() {
116  6 try {
117  6 verify(mock);
118  0 fail("Expected AssertionError");
119    } catch (final AssertionError expected) {
120    }
121    }
122   
 
123  6 toggle private void assertMethodCallFails() {
124  6 try {
125  6 mock.method();
126  0 fail("Expected AssertionError");
127    } catch (final AssertionError expected) {
128    }
129    }
130   
 
131  2 toggle @Test
132    public void noUpperLimitWithoutCallCountSet() {
133  2 mock.method();
134  2 expectLastCall().atLeastOnce();
135  2 replay(mock);
136  2 assertVerifyFails();
137  2 mock.method();
138  2 verify(mock);
139  2 mock.method();
140  2 verify(mock);
141  2 mock.method();
142  2 verify(mock);
143    }
144    }