1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.matcher;
3
4 import org.jmock.AbstractTestCase;
5 import org.jmock.C;
6 import org.jmock.Constraint;
7 import org.jmock.dynamic.Invocation;
8
9 public class InvocationMatcherTest extends AbstractTestCase {
10 private Invocation emptyInvocation =
11 new Invocation("example", new Class[0], Void.class, new Object[0]);
12
13 private Invocation exampleInvocation =
14 new Invocation("example", new Class[]{String.class}, Void.class,
15 new Object[]{"arg1", "arg2"});
16
17 public void testNameMatchesWhenConstraintIsAnything() {
18 MethodNameMatcher matcher = new MethodNameMatcher(C.IS_ANYTHING);
19 assertTrue("Should match name", matcher.matches(exampleInvocation));
20 }
21
22 public void testNameMatchesWhenConstraintIsNothing() {
23 MethodNameMatcher matcher = new MethodNameMatcher(C.not(C.IS_ANYTHING));
24 assertFalse("Should not match name", matcher.matches(exampleInvocation));
25 }
26
27 public void testNameMatchesGivenString() {
28 MethodNameMatcher matcher = new MethodNameMatcher("example");
29 assertTrue("Should match name", matcher.matches(exampleInvocation));
30 }
31
32 public void testNameDoesNotMatchIncorrectString() {
33 MethodNameMatcher matcher = new MethodNameMatcher("not an example");
34 assertFalse("Should not match name", matcher.matches(exampleInvocation));
35 }
36
37 public void testMatchWhenNoArgumentsOrConstraints() throws Throwable {
38 ArgumentsMatcher matcher = new ArgumentsMatcher(new Constraint[0]);
39
40 assertTrue("No arguments", matcher.matches(emptyInvocation));
41 }
42
43 public void testNoMatchWhenTooManyArguments() throws Throwable {
44 ArgumentsMatcher matcher = new ArgumentsMatcher(new Constraint[0]);
45
46 assertFalse("Too many arguments", matcher.matches(exampleInvocation));
47 }
48
49 public void testNoMatchWhenTooFewArguments() throws Throwable {
50 ArgumentsMatcher matcher =
51 new ArgumentsMatcher(
52 new Constraint[]{C.IS_ANYTHING, C.IS_ANYTHING, C.IS_ANYTHING});
53
54 assertFalse("Too many arguments", matcher.matches(exampleInvocation));
55 }
56
57 public void testNoMatchWhenAnyArgumentDoNotConform() throws Throwable {
58 ArgumentsMatcher matcher =
59 new ArgumentsMatcher(
60 new Constraint[]{C.IS_ANYTHING, C.eq("wrong")});
61
62 assertFalse("Incorrect argument", matcher.matches(exampleInvocation));
63 }
64
65 public void testArgumentsMatchWhenAllValuesMatch() throws Throwable {
66 ArgumentsMatcher matcher =
67 new ArgumentsMatcher(
68 new Constraint[]{C.IS_ANYTHING, C.eq("arg2")});
69
70 assertTrue("Arguments match", matcher.matches(exampleInvocation));
71 }
72
73
74 }
This page was automatically generated by Maven