KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > examples > timedcache > InvokeCountMatcher


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.examples.timedcache;
4
5 import junit.framework.Assert;
6 import org.jmock.core.Invocation;
7 import org.jmock.core.InvocationMatcher;
8
9
10 public class InvokeCountMatcher
11         implements InvocationMatcher
12 {
13     int expectedCount;
14     int invocationCount = 0;
15
16     public InvokeCountMatcher( int expectedCount ) {
17         this.expectedCount = expectedCount;
18     }
19
20     public boolean matches( Invocation invocation ) {
21         return invocationCount < expectedCount;
22     }
23
24     public void verify() {
25         Assert.assertTrue("Invoked wrong number of times", expectedCount == invocationCount);
26     }
27
28     public boolean hasDescription() {
29         return true;
30     }
31
32     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
33         return buffer.append("expected ").append(expectedCount)
34                 .append(" times, invoked ").append(invocationCount).append(" times");
35     }
36
37     public void invoked( Invocation invocation ) {
38         invocationCount++;
39     }
40 }
41
Popular Tags