|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ExpectationCounter.java | 100% | 100% | 100% | 100% |
|
1 |
/* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
|
|
2 |
package org.jmock.expectation;
|
|
3 |
|
|
4 |
import junit.framework.Assert;
|
|
5 |
|
|
6 |
public class ExpectationCounter extends AbstractExpectation { |
|
7 |
private int myExpectedCalls = 0; |
|
8 |
private int myActualCalls = 0; |
|
9 |
|
|
10 | 154 |
public ExpectationCounter(String name) {
|
11 | 154 |
super(name);
|
12 |
} |
|
13 |
|
|
14 | 30 |
public void clearActual() { |
15 | 30 |
myActualCalls = 0; |
16 |
} |
|
17 |
|
|
18 | 36 |
public void inc() { |
19 | 36 |
myActualCalls++; |
20 | 36 |
if (shouldCheckImmediately()) {
|
21 | 26 |
Assert.assertTrue( |
22 |
myName + " should not be called more than " + myExpectedCalls + " times", |
|
23 |
myActualCalls <= myExpectedCalls); |
|
24 |
} |
|
25 |
} |
|
26 |
|
|
27 | 26 |
public void setExpected(int expectedCalls) { |
28 | 26 |
myExpectedCalls = expectedCalls; |
29 | 26 |
setHasExpectations(); |
30 |
} |
|
31 |
|
|
32 | 4 |
public void setExpectNothing() { |
33 | 4 |
myExpectedCalls = 0; |
34 | 4 |
setHasExpectations(); |
35 |
} |
|
36 |
|
|
37 | 70 |
public void verify() { |
38 | 70 |
assertEquals( |
39 |
"did not receive the expected Count.",
|
|
40 |
myExpectedCalls, |
|
41 |
myActualCalls); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|