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 public ExpectationCounter(String name) {
11 super(name);
12 }
13
14 public void clearActual() {
15 myActualCalls = 0;
16 }
17
18 public void inc() {
19 myActualCalls++;
20 if (shouldCheckImmediately()) {
21 Assert.assertTrue(
22 myName + " should not be called more than " + myExpectedCalls + " times",
23 myActualCalls <= myExpectedCalls);
24 }
25 }
26
27 public void setExpected(int expectedCalls) {
28 myExpectedCalls = expectedCalls;
29 setHasExpectations();
30 }
31
32 public void setExpectNothing() {
33 myExpectedCalls = 0;
34 setHasExpectations();
35 }
36
37 public void verify() {
38 assertEquals(
39 "did not receive the expected Count.",
40 myExpectedCalls,
41 myActualCalls);
42 }
43 }
This page was automatically generated by Maven