KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > matcher > MethodNameMatcherTest


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

3 package test.jmock.core.matcher;
4
5 import junit.framework.TestCase;
6 import org.jmock.core.Invocation;
7 import org.jmock.core.matcher.MethodNameMatcher;
8 import test.jmock.core.testsupport.MethodFactory;
9 import test.jmock.core.testsupport.MockConstraint;
10
11
12 public class MethodNameMatcherTest
13         extends TestCase
14 {
15     private String JavaDoc METHOD_NAME = "methodName";
16     private String JavaDoc OTHER_NAME = "otherName";
17
18     private Invocation exampleInvocation;
19
20     public void setUp() {
21         MethodFactory methodFactory = new MethodFactory();
22         exampleInvocation = new Invocation("INVOKED-OBJECT",
23                                            methodFactory.newMethod(METHOD_NAME, new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class}, Void JavaDoc.class,
24                                                                    MethodFactory.NO_EXCEPTIONS),
25                                            new Object JavaDoc[]{"arg1", "arg2"});
26     }
27
28     public void testDelegatesMethodNameMatchToConstraint() {
29         MockConstraint mockConstraint = new MockConstraint("name constraint", METHOD_NAME, true);
30         MethodNameMatcher matcher = new MethodNameMatcher(mockConstraint);
31
32         assertTrue("should match", matcher.matches(exampleInvocation));
33     }
34
35     public void testDoesNotMatchIfConstraintFails() {
36         MockConstraint mockConstraint = new MockConstraint("name constraint", METHOD_NAME, false);
37         MethodNameMatcher matcher = new MethodNameMatcher(mockConstraint);
38
39         assertFalse("should not match", matcher.matches(exampleInvocation));
40     }
41
42     public void testTestsMethodNameForEqualityToString() {
43         MethodNameMatcher matcher;
44
45         matcher = new MethodNameMatcher(METHOD_NAME);
46         assertTrue("Should match name", matcher.matches(exampleInvocation));
47
48         matcher = new MethodNameMatcher(OTHER_NAME);
49         assertFalse("Should not match other name", matcher.matches(exampleInvocation));
50     }
51 }
52
Popular Tags