From: Steve F. <sm...@us...> - 2003-10-05 08:57:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv29646/src/core/test/mockobjects/dynamic Modified Files: InvocationMockerTest.java InvocationMatcherTest.java Log Message: Extended InvocationMatcher and InvocationMocker Index: InvocationMockerTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/InvocationMockerTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InvocationMockerTest.java 4 Oct 2003 22:56:45 -0000 1.1 +++ InvocationMockerTest.java 5 Oct 2003 08:57:27 -0000 1.2 @@ -3,6 +3,8 @@ */ package test.mockobjects.dynamic; +import com.mockobjects.constraint.Constraint; +import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.Invocation; import com.mockobjects.dynamic.InvocationMatcher; import com.mockobjects.dynamic.InvocationMocker; @@ -20,7 +22,9 @@ } }; - private Invocation invocation = new Invocation("example", new Class[0], Void.class, new Object[0]); + private Invocation invocation = + new Invocation("example", new Class[] { String.class, String.class }, Void.class, + new Object[] { "arg1", "arg2"} ); public InvocationMockerTest(String name) { @@ -40,5 +44,22 @@ assertFalse("Should not have matched", invocationMocker.matches(invocation)); } + + public void testExampleInvocationMatches() { + InvocationMocker invocationMocker = new InvocationMocker( + new InvocationMatcher[] { + new InvocationMatcher.MethodName("example"), + new InvocationMatcher.Arguments( new Constraint[] {C.eq("arg1"), C.eq("arg2")})}, null); + + assertTrue("Should have matched", invocationMocker.matches(invocation)); + } + public void testExampleInvocationDoesNotMatch() { + InvocationMocker invocationMocker = new InvocationMocker( + new InvocationMatcher[] { + new InvocationMatcher.MethodName("example"), + new InvocationMatcher.Arguments( new Constraint[] {C.eq("arg1"), C.eq("not arg2")})}, null); + + assertFalse("Should not have matched", invocationMocker.matches(invocation)); + } } Index: InvocationMatcherTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/InvocationMatcherTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InvocationMatcherTest.java 4 Oct 2003 22:56:45 -0000 1.1 +++ InvocationMatcherTest.java 5 Oct 2003 08:57:27 -0000 1.2 @@ -3,13 +3,16 @@ */ package test.mockobjects.dynamic; +import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.Invocation; import com.mockobjects.dynamic.InvocationMatcher; import com.mockobjects.util.TestCaseMo; public class InvocationMatcherTest extends TestCaseMo { - private Invocation invocation = new Invocation("example", new Class[0], Void.class, new Object[0]); + private Invocation exampleInvocation = + new Invocation("example", new Class[] { String.class }, Void.class, + new Object[] { "arg1", "arg2" } ); public InvocationMatcherTest(String name) { super(name); @@ -17,22 +20,52 @@ public void testNameMatchesWhenConstraintIsAnything() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName(C.IS_ANYTHING); - assertTrue("Should match name", matcher.matches(invocation)); + assertTrue("Should match name", matcher.matches(exampleInvocation)); } public void testNameMatchesWhenConstraintIsNothing() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName(C.not(C.IS_ANYTHING)); - assertFalse("Should not match name", matcher.matches(invocation)); + assertFalse("Should not match name", matcher.matches(exampleInvocation)); } public void testNameMatchesGivenString() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName("example"); - assertTrue("Should match name", matcher.matches(invocation)); + assertTrue("Should match name", matcher.matches(exampleInvocation)); } - public void testNameDoesNotMatcheIncorrectString() { + public void testNameDoesNotMatchIncorrectString() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName("not an example"); - assertFalse("Should not match name", matcher.matches(invocation)); + assertFalse("Should not match name", matcher.matches(exampleInvocation)); } + public void testNoMatchWhenTooManyArguments() throws Throwable { + InvocationMatcher.Arguments matcher = new InvocationMatcher.Arguments(new Constraint[0]); + + assertFalse("Too many arguments", matcher.matches(exampleInvocation)); + } + + public void testNoMatchWhenTooFewArguments() throws Throwable { + InvocationMatcher.Arguments matcher = + new InvocationMatcher.Arguments( + new Constraint[] { C.IS_ANYTHING, C.IS_ANYTHING, C.IS_ANYTHING} ); + + assertFalse("Too many arguments", matcher.matches(exampleInvocation)); + } + + public void testNoMatchWhenAnyArgumentDoesNotMatch() throws Throwable { + InvocationMatcher.Arguments matcher = + new InvocationMatcher.Arguments( + new Constraint[] { C.IS_ANYTHING, C.eq("wrong")} ); + + assertFalse("Incorrect argument", matcher.matches(exampleInvocation)); + } + + public void testArgumentsMatchWhenAllValuesMatch() throws Throwable { + InvocationMatcher.Arguments matcher = + new InvocationMatcher.Arguments( + new Constraint[] { C.IS_ANYTHING, C.eq("arg2")} ); + + assertTrue("Arguments match", matcher.matches(exampleInvocation)); + } + } |