From: Steve F. <sm...@us...> - 2003-10-04 22:56:49
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv20912/src/core/test/mockobjects/dynamic Modified Files: MockTest.java Added Files: InvocationMockerTest.java ArgumentsMatcherTest.java InvocationMatcherTest.java DynamicMockErrorTest.java Removed Files: ConstraintMatcherTest.java Log Message: Started implementing new dynamic mock structure. Introduced InvocationMocker. and InvocationMatcher Renamed ConstraintMatcher to ArgumentsMatcher --- NEW FILE: InvocationMockerTest.java --- /* * Copyright MockObjects.com 04-Oct-2003 */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.Invocation; import com.mockobjects.dynamic.InvocationMatcher; import com.mockobjects.dynamic.InvocationMocker; import com.mockobjects.util.TestCaseMo; public class InvocationMockerTest extends TestCaseMo { private InvocationMatcher matchAll = new InvocationMatcher() { public boolean matches(Invocation invocation) { return true; } }; private InvocationMatcher matchNone = new InvocationMatcher() { public boolean matches(Invocation invocation) { return false; } }; private Invocation invocation = new Invocation("example", new Class[0], Void.class, new Object[0]); public InvocationMockerTest(String name) { super(name); } public void testMatchesIfEverythingMatches() { InvocationMocker invocationMocker = new InvocationMocker(new InvocationMatcher[] { matchAll, matchAll}, null); assertTrue("Should have matched", invocationMocker.matches(invocation)); } public void testDoesNotMatchIfEverythingMatches() { InvocationMocker invocationMocker = new InvocationMocker(new InvocationMatcher[] { matchAll, matchNone}, null); assertFalse("Should not have matched", invocationMocker.matches(invocation)); } } --- NEW FILE: ArgumentsMatcherTest.java --- package test.mockobjects.dynamic; import test.mockobjects.dynamic.support.*; import com.mockobjects.dynamic.*; import com.mockobjects.dynamic.ArgumentsMatcher; import junit.framework.TestCase; public class ArgumentsMatcherTest extends TestCase { public ArgumentsMatcherTest(String name) { super(name); } public void testNoMatchWhenTooManyArguments() throws Throwable { String[] args = { "arg1", "arg2" }; MockConstraint[] constraints = { new MockConstraint("constraint1", args[0], true) }; ArgumentsMatcher constraintMatcher = new FullArgumentsMatcher(constraints); assertFalse("Should not match if too many arguments", constraintMatcher.matches(args)); } public void testNoMatchWhenTooFewArguments() throws Throwable { String[] args = { "arg1" }; MockConstraint[] constraints = { new MockConstraint("constraint1", args[0], true), new MockConstraint("constraint2", args[0], true) }; ArgumentsMatcher constraintMatcher = new FullArgumentsMatcher(constraints); assertFalse("Should not match if too few arguments", constraintMatcher.matches(args)); } public void testNoMatchWhenConstraintIsViolated() throws Throwable { String[] args = { "argA", "argB", "argC" }; MockConstraint[] constraints = { new MockConstraint("constraintA", args[0], true), new MockConstraint("constraintB", args[1], false), new MockConstraint("constraintC", args[2], true) }; ArgumentsMatcher constraintMatcher = new FullArgumentsMatcher(constraints); assertFalse("Should not match", constraintMatcher.matches(args)); } public void testNoMatchWithNoArgumentsAndCalleeHasArguments() throws Throwable { String[] args = new String[] { "arg1", "arg2" }; MockConstraint[] constraints = new MockConstraint[0]; ArgumentsMatcher constraintMatcher = new FullArgumentsMatcher(constraints); assertFalse("Should not match", constraintMatcher.matches(args)); } public void testMatchWithNoArguments() throws Throwable { String[] args = new String[0]; MockConstraint[] constraints = new MockConstraint[0]; ArgumentsMatcher constraintMatcher = new FullArgumentsMatcher(constraints); assertTrue("Should match", constraintMatcher.matches(args)); } public void testMatchAndArgumentsCheckedAgainstConstraints() throws Throwable { String[] args = { "argA", "argB", "argC" }; MockConstraint constraintA = new MockConstraint("constraintA", args[0], true); MockConstraint constraintB = new MockConstraint("constraintB", args[1], true); MockConstraint constraintC = new MockConstraint("constraintC", args[2], true); MockConstraint[] constraints = { constraintA, constraintB, constraintC }; ArgumentsMatcher constraintMatcher = new FullArgumentsMatcher(constraints); assertTrue("Should match", constraintMatcher.matches(args)); constraintA.verify(); constraintB.verify(); constraintC.verify(); } public void testMatchWithArgument() throws Throwable { String[] args = { "argA" }; MockConstraint constraintA = new MockConstraint("constraintA", args[0], true); ArgumentsMatcher constraintMatcher = new FullArgumentsMatcher(new MockConstraint[] { constraintA }); assertTrue("Should match", constraintMatcher.matches(args)); } } --- NEW FILE: InvocationMatcherTest.java --- /* * Copyright mockobjects.com 04-Oct-2003 */ package test.mockobjects.dynamic; 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]); public InvocationMatcherTest(String name) { super(name); } public void testNameMatchesWhenConstraintIsAnything() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName(C.IS_ANYTHING); assertTrue("Should match name", matcher.matches(invocation)); } public void testNameMatchesWhenConstraintIsNothing() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName(C.not(C.IS_ANYTHING)); assertFalse("Should not match name", matcher.matches(invocation)); } public void testNameMatchesGivenString() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName("example"); assertTrue("Should match name", matcher.matches(invocation)); } public void testNameDoesNotMatcheIncorrectString() { InvocationMatcher.MethodName matcher = new InvocationMatcher.MethodName("not an example"); assertFalse("Should not match name", matcher.matches(invocation)); } } --- NEW FILE: DynamicMockErrorTest.java --- /* * copyright mockobjects.com 04-Oct-2003 */ package test.mockobjects.dynamic; import com.mockobjects.util.TestCaseMo; public class DynamicMockErrorTest extends TestCaseMo { public DynamicMockErrorTest(String name) { super(name); } // TODO test message generation based on message and invocation. } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- MockTest.java 2 Oct 2003 23:42:06 -0000 1.26 +++ MockTest.java 4 Oct 2003 22:56:45 -0000 1.27 @@ -6,7 +6,7 @@ import com.mockobjects.constraint.Constraint; import com.mockobjects.constraint.IsEqual; import com.mockobjects.dynamic.C; -import com.mockobjects.dynamic.ConstraintMatcher; +import com.mockobjects.dynamic.ArgumentsMatcher; import com.mockobjects.dynamic.Mock; @@ -14,8 +14,8 @@ private static final String MOCK_NAME = "Test mock"; final Throwable METHOD_EXCEPTION = new DummyThrowable("Configured test throwable"); - final ConstraintMatcher METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1")); - final ConstraintMatcher METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2")); + final ArgumentsMatcher METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1")); + final ArgumentsMatcher METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2")); private MockInvokableFactory mockCallableFactory = new MockInvokableFactory(); private MockInvocationDispatcher mockDispatcher = new MockInvocationDispatcher(); --- ConstraintMatcherTest.java DELETED --- |