KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > matcher > MethodNameMatcher


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

3 package org.jmock.core.matcher;
4
5 import org.jmock.core.Constraint;
6 import org.jmock.core.Invocation;
7
8
9 public class MethodNameMatcher
10         extends StatelessInvocationMatcher
11 {
12     private Constraint constraint;
13
14     public MethodNameMatcher( Constraint constraint ) {
15         this.constraint = constraint;
16     }
17
18     public MethodNameMatcher( final String JavaDoc methodName ) {
19         this(new Constraint()
20         {
21             public boolean eval( Object JavaDoc o ) {
22                 return methodName.equals(o);
23             }
24
25             public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
26                 return buffer.append(methodName);
27             }
28         });
29     }
30
31     public boolean matches( Invocation invocation ) {
32         return constraint.eval(invocation.invokedMethod.getName());
33     }
34
35     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
36         return constraint.describeTo(buffer);
37     }
38 }
39
Popular Tags