Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6206/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment DummyInterface.java ExpectedCallTest.java MockCallable.java MockTest.java CallMatchTest.java Log Message: Improved error reporting for Proxy's as expectation values Added additional conveniance methods for primitive types Added deprecated expect methods to make library conversion easy Got distracted and have missed XtC completely... Index: DummyInterface.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/DummyInterface.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- DummyInterface.java 14 Apr 2003 08:46:29 -0000 1.1.2.3 +++ DummyInterface.java 15 Apr 2003 22:22:55 -0000 1.1.2.4 @@ -11,4 +11,5 @@ public String oneArgMethod( String arg1); public void noArgMethodVoid(); + public String noArgMethod(); } Index: ExpectedCallTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/ExpectedCallTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- ExpectedCallTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.3 +++ ExpectedCallTest.java 15 Apr 2003 22:22:55 -0000 1.1.2.4 @@ -13,26 +13,26 @@ */ public class ExpectedCallTest extends TestCase { - final String result = "result!"; - final String methodName = "methodName"; - final Object[] args = { "arg1", "arg2" }; - final String decoratedDescription = AssertMo.methodToString( methodName, args ); + final String RESULT = "result!"; + final String METHOD_NAME = "methodName"; + final Object[] ARGS = { "arg1", "arg2" }; + final String DECORATED_DESCRIPTION = AssertMo.methodToString( METHOD_NAME, ARGS ); Mock ignoredMock = null; - MockCallable mockDecorated = new MockCallable(); - ExpectedCall call = new ExpectedCall( mockDecorated ); + MockCallable mockCallable = new MockCallable(); + ExpectedCall call = new ExpectedCall( mockCallable ); public ExpectedCallTest(String name) { super(name); } public void setUp() { - mockDecorated.setupGetDescription(decoratedDescription); + mockCallable.setupGetDescription(DECORATED_DESCRIPTION); } public void testDescription() { AssertMo.assertIncludes( "should contain decorated's description", - decoratedDescription, call.getDescription() ); + DECORATED_DESCRIPTION, call.getDescription() ); AssertMo.assertIncludes( "should say that decorated call is mandatory", "mandatory", call.getDescription() ); } @@ -43,7 +43,7 @@ } catch( AssertionFailedError ex ) { AssertMo.assertIncludes( "should include description of expected call", - decoratedDescription, ex.getMessage() ); + DECORATED_DESCRIPTION, ex.getMessage() ); return; } @@ -51,52 +51,52 @@ } public void testVerifiesIfCalled() throws Throwable { - mockDecorated.setupCallReturn( result ); - mockDecorated.setExpectedVerifyCalls(1); + mockCallable.setupCallReturn( RESULT ); + mockCallable.setExpectedVerifyCalls(1); - call.call( ignoredMock, methodName, args ); + call.call( ignoredMock, METHOD_NAME, ARGS ); call.verify(); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testMatchesDelegated() throws Throwable { - mockDecorated.setExpectedMatches( methodName, args ); - mockDecorated.setupMatchesReturn(true); - assertTrue( "returns matches to be true", call.matches( methodName, args ) ); - mockDecorated.verifyExpectations(); + mockCallable.setExpectedMatches( METHOD_NAME, ARGS ); + mockCallable.setupMatchesReturn(true); + assertTrue( "returns matches to be true", call.matches( METHOD_NAME, ARGS ) ); + mockCallable.verifyExpectations(); } public void testCallArgumentsPassedThrough() throws Throwable { - mockDecorated.setExpectedCall(ignoredMock, methodName, args); - mockDecorated.setupCallReturn(result); + mockCallable.setExpectedCall(ignoredMock, METHOD_NAME, ARGS); + mockCallable.setupCallReturn(RESULT); - call.call( ignoredMock, methodName, args ); - mockDecorated.verifyExpectations(); + call.call( ignoredMock, METHOD_NAME, ARGS ); + mockCallable.verifyExpectations(); } public void testDecoratedResultPassedThrough() throws Throwable { - mockDecorated.setupCallReturn(result); + mockCallable.setupCallReturn(RESULT); assertSame( "should return decorated's result", - result, call.call( ignoredMock, methodName, args ) ); - mockDecorated.verifyExpectations(); + RESULT, call.call( ignoredMock, METHOD_NAME, ARGS ) ); + mockCallable.verifyExpectations(); } public void testDecoratedExceptionPassedThrough() throws Throwable { final Throwable exception = new DummyThrowable(); - mockDecorated.setupCallThrow(exception); + mockCallable.setupCallThrow(exception); try { - call.call( ignoredMock, methodName, args ); + call.call( ignoredMock, METHOD_NAME, ARGS ); fail("expected decorated's throwable to be thrown"); } catch( DummyThrowable ex ) { // expected } - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } } Index: MockCallable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockCallable.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- MockCallable.java 11 Apr 2003 13:21:16 -0000 1.1.2.1 +++ MockCallable.java 15 Apr 2003 22:22:56 -0000 1.1.2.2 @@ -19,6 +19,7 @@ private ExpectationValue matchesMethodName = new ExpectationValue("matches.methodName"); private ExpectationList matchesArgs = new ExpectationList("matches.args"); private ReturnValue matchesResult = new ReturnValue("matches.return"); + private ExpectationCounter matchesCount = new ExpectationCounter("matches.count"); private ExpectationCounter verifyCount = new ExpectationCounter("verify.count"); private AssertionFailedError verifyError = null; @@ -62,6 +63,10 @@ matchesArgs.addExpectedMany(args); } + public void setExpectedMatchesCount(int count) { + matchesCount.setExpected(count); + } + public void setupMatchesReturn( boolean result ) { matchesResult.setValue(result); } @@ -69,6 +74,7 @@ public boolean matches(String methodName, Object[] args) { matchesMethodName.setActual(methodName); matchesArgs.addActualMany(args); + matchesCount.inc(); return matchesResult.getBooleanValue(); } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.5 retrieving revision 1.8.2.6 diff -u -r1.8.2.5 -r1.8.2.6 --- MockTest.java 14 Apr 2003 08:46:28 -0000 1.8.2.5 +++ MockTest.java 15 Apr 2003 22:22:56 -0000 1.8.2.6 @@ -13,8 +13,10 @@ public class MockTest extends TestCase { private static final String MOCK_NAME = "Test mock"; final String METHOD_NOARG_NAME = "noArgMethodVoid"; + final String METHOD_NOARGANDRETURN_NAME = "noArgMethod"; + final String METHOD_NOARGANDRETURN_RESULT = "resultNoArgs"; final String METHOD_ONEARG_NAME = "oneArgMethod"; - final String METHOD_ONEARG_RESULT = "resultOArgs"; + final String METHOD_ONEARG_RESULT = "result1Args"; final String METHOD_TWOARG_NAME = "twoArgMethod"; final String METHOD_TWOARG_RESULT = "resultTwoArgs"; final Throwable METHOD_EXCEPTION = new DummyThrowable("Configured test throwable"); @@ -47,7 +49,7 @@ } } - public void testExpect() throws Throwable { + public void testExpectManyAndVoid() throws Throwable { mockCallFactory.setExpectedCreateVoidStubCalls(1); mockCallFactory.setupCreateVoidStub(mockVoidStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub); @@ -63,7 +65,71 @@ mockCallableAddable.verifyExpectations(); } - public void testExpectOne() throws Throwable { + public void testExpectNoneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expectAndReturn(METHOD_NOARGANDRETURN_NAME, METHOD_NOARGANDRETURN_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectNoneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expectAndThrow(METHOD_NOARGANDRETURN_NAME, METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectOneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expectAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectNoneAndVoid() throws Throwable { + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expect(METHOD_NOARG_NAME); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectOneAndVoid() throws Throwable { mockCallFactory.setExpectedCreateVoidStubCalls(1); mockCallFactory.setupCreateVoidStub(mockVoidStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub); @@ -79,7 +145,7 @@ mockCallableAddable.verifyExpectations(); } - public void testExpectAndReturn() throws Throwable { + public void testExpectManyAndReturn() throws Throwable { mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); @@ -96,7 +162,7 @@ mockCallableAddable.verifyExpectations(); } - public void testExpectAndThrow() throws Throwable { + public void testExpectManyAndThrow() throws Throwable { mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); @@ -130,7 +196,7 @@ mockCallableAddable.verifyExpectations(); } - public void testMatchAndReturn() throws Throwable { + public void testMatchManyAndReturn() throws Throwable { mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); @@ -145,7 +211,37 @@ mockCallableAddable.verifyExpectations(); } - public void testMatchAndThrow() throws Throwable { + public void testMatchNoneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_NOARGANDRETURN_RESULT); + + mock.matchAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMatchOneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + + mock.matchAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMatchManyAndThrow() throws Throwable { mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); @@ -174,6 +270,21 @@ Verifier.verifyObject(this); mockCallableAddable.verifyExpectations(); } + + public void testMatchNoneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + + mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } public void testMockAnnotatesAssertionFailedErrors() throws Throwable { @@ -207,7 +318,6 @@ mockCallableAddable.setExpectedCall(mock, METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS); mockCallableAddable.setupCallReturn("result ignored"); - //mock.invoke(unusedProxy, METHOD_A_METHOD, METHOD_A_ARGS); proxy.twoArgMethod(METHOD_TWOARG_ARGS[0], METHOD_TWOARG_ARGS[1]); mockCallableAddable.verifyExpectations(); @@ -247,5 +357,22 @@ mock.verify(); mockCallableAddable.verifyExpectations(); + } + + public void testProxyEquality() throws Exception { + assertTrue("Should handle proxy equality without checking expectations", proxy.equals(proxy)); + } + + public void testProxyInEquality() throws Exception { + boolean IGNORED_RESULT = true; + CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT)); + mockCallFactory.setupCreateReturnStub(ret); + mockCallFactory.setupCreateCallMatch(new CallMatch("call",C.ANY_ARGS,ret)); + mockCallableAddable.setupCallReturn(new Boolean(false)); + + mock.matchAndReturn("call", C.ANY_ARGS, IGNORED_RESULT); + assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); + + Verifier.verifyObject(this); } } Index: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallMatchTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallMatchTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.2 +++ CallMatchTest.java 15 Apr 2003 22:22:56 -0000 1.1.2.3 @@ -11,10 +11,10 @@ public class CallMatchTest extends TestCase { - final String methodName = "methodName"; + final String METHOD_NAME = "methodName"; Mock mock = new Mock(DummyInterface.class,"mock"); - MockCallable mockDecorated = new MockCallable(); - CallMatch call = new CallMatch( methodName, new Constraint[0], mockDecorated ); + MockCallable mockCallable = new MockCallable(); + CallMatch call = new CallMatch( METHOD_NAME, new Constraint[0], mockCallable ); public CallMatchTest(String name) { super(name); @@ -24,38 +24,38 @@ final Object[] arguments = new Object[0]; final String result = "result"; - mockDecorated.setExpectedCall( mock, methodName, arguments ); - mockDecorated.setupCallReturn( result ); + mockCallable.setExpectedCall( mock, METHOD_NAME, arguments ); + mockCallable.setupCallReturn( result ); - call.call(mock, methodName, arguments); + call.call(mock, METHOD_NAME, arguments); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testUncalledCallVerifies() { - mockDecorated.setExpectedVerifyCalls(1); + mockCallable.setExpectedVerifyCalls(1); call.verify(); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testSuccessfulCallVerifies() throws Throwable { - mockDecorated.setExpectedVerifyCalls(1); - mockDecorated.setupCallReturn("result"); + mockCallable.setExpectedVerifyCalls(1); + mockCallable.setupCallReturn("result"); call.call( mock, "methodName", new Object[0] ); call.verify(); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testMultipleCallsSucceed() throws Throwable { - mockDecorated.setupCallReturn("result"); + mockCallable.setupCallReturn("result"); - call.call( mock, methodName, new Object[0] ); - call.call( mock, methodName, new Object[0] ); + call.call( mock, METHOD_NAME, new Object[0] ); + call.call( mock, METHOD_NAME, new Object[0] ); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testArgumentsCheckedAgainstConstraints() throws Throwable { @@ -65,17 +65,17 @@ new MockConstraint( "constraint2", args[1], true ), new MockConstraint( "constraint3", args[2], true ) }; - mockDecorated.setupCallReturn("result"); + mockCallable.setupCallReturn("result"); - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - call.call( mock, methodName, args ); + call.call( mock, METHOD_NAME, args ); for( int i = 0; i < constraints.length; i++ ) { constraints[i].verify(); } - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testWrongNumberOfArguments() throws Throwable { @@ -86,11 +86,11 @@ new MockConstraint( "constraint3", args[1], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); boolean passed = true; try { - call.call( mock, methodName, args ); + call.call( mock, METHOD_NAME, args ); passed = false; } catch (AssertionFailedError ex) { AssertMo.assertIncludes("Should show expected number of arguments", @@ -98,11 +98,11 @@ AssertMo.assertIncludes("Should show actual number of arguments", Integer.toString(args.length), ex.getMessage()); AssertMo.assertIncludes("Should include the method name", - methodName, ex.getMessage()); + METHOD_NAME, ex.getMessage()); } assertTrue("Should fail is call doesn't give an exception", passed); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testConstraintFailure() throws Throwable { @@ -113,15 +113,15 @@ new MockConstraint( "constraintC", args[2], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); boolean passed = true; try { - call.call( mock, methodName, args ); + call.call( mock, METHOD_NAME, args ); passed = false; } catch (AssertionFailedError ex) { AssertMo.assertIncludes("Should include the method name", - methodName, ex.getMessage()); + METHOD_NAME, ex.getMessage()); AssertMo.assertIncludes("Should show index of failed argument", "1", ex.getMessage() ); AssertMo.assertIncludes("Should show expected arguments", @@ -131,7 +131,7 @@ } assertTrue("Should fail is call doesn't give an exception", passed); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } @@ -143,16 +143,41 @@ new MockConstraint( "constraint3", args[2], true ) }; - mockDecorated.setExpectedMatches( methodName, args ); - mockDecorated.setupMatchesReturn(true); + mockCallable.setExpectedMatches( METHOD_NAME, args ); + mockCallable.setupMatchesReturn(true); - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertTrue( "call matches", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertTrue( "call matches", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } - public void testCallDoesNotMatchIfDecoratedDoesNotMatch() throws Throwable { + public void testCallMatchesWithNoArguments() throws Throwable { + String[] args = new String[0]; + MockConstraint[] constraints = new MockConstraint[0]; + + mockCallable.setExpectedMatches( METHOD_NAME, args ); + mockCallable.setupMatchesReturn(true); + + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); + + assertTrue( "call should matche", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); + } + + public void testCallMatchesWithNoArgumentsAndCalleeHasArguments() throws Throwable { + String[] args = new String[] {"arg1", "arg2"}; + MockConstraint[] constraints = new MockConstraint[0]; + + mockCallable.setExpectedMatchesCount(0); + + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); + + assertFalse( "call should not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); + } + + public void testCallDoesNotMatchIfDelegateDoesNotMatch() throws Throwable { String[] args = { "arg1", "arg2", "arg3" }; MockConstraint[] constraints = { new MockConstraint( "constraint1", args[0], true ), @@ -160,20 +185,20 @@ new MockConstraint( "constraint3", args[2], true ) }; - mockDecorated.setExpectedMatches( methodName, args ); - mockDecorated.setupMatchesReturn(false); + mockCallable.setExpectedMatches( METHOD_NAME, args ); + mockCallable.setupMatchesReturn(false); - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertFalse( "call does not match when decorated does not match", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertFalse( "call does not match when delegate does not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } public void testCallDoesNotMatchWhenWrongName() throws Throwable { - CallMatch call = new CallMatch( methodName, new Constraint[0], mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, new Constraint[0], mockCallable ); assertFalse( "call does not match", call.matches( "anotherName", new Object[0]) ); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testCallDoesNotMatchWhenWrongNumberOfArguments() throws Throwable { @@ -184,10 +209,10 @@ new MockConstraint( "constraint3", args[1], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertFalse( "call does not match", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertFalse( "call does not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } public void testCallDoesNotMatchWhenConstraintIsViolated() throws Throwable { @@ -198,23 +223,23 @@ new MockConstraint( "constraintC", args[2], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertFalse( "call does not match", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertFalse( "call does not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } public void testMatchesAfterCalls() throws Throwable { - mockDecorated.setupCallReturn("result"); - mockDecorated.setupMatchesReturn(true); + mockCallable.setupCallReturn("result"); + mockCallable.setupMatchesReturn(true); - CallMatch call = new CallMatch(methodName, C.args(), mockDecorated ); + CallMatch call = new CallMatch(METHOD_NAME, C.args(), mockCallable ); - call.call( mock, methodName, new Object[0] ); - assertTrue( "matches after first call", call.matches( methodName, new Object[0]) ); - call.call( mock, methodName, new Object[0] ); - assertTrue( "matches after further calls", call.matches( methodName, new Object[0]) ); + call.call( mock, METHOD_NAME, new Object[0] ); + assertTrue( "matches after first call", call.matches( METHOD_NAME, new Object[0]) ); + call.call( mock, METHOD_NAME, new Object[0] ); + assertTrue( "matches after further calls", call.matches( METHOD_NAME, new Object[0]) ); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } } |