From: Tim M. <ma...@us...> - 2003-04-11 13:21:21
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21961/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment MockTest.java CallMatchTest.java ExpectedCallTest.java MockCallFactory.java CallSetTest.java Added Files: Tag: DynamicMockExperiment MockCallable.java Removed Files: Tag: DynamicMockExperiment MockCallMocker.java Log Message: Test updates for CallSet rename and expectAndReturn modification --- NEW FILE: MockCallable.java --- package test.mockobjects.dynamic; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.dynamic.Callable; import com.mockobjects.dynamic.Mock; import com.mockobjects.util.*; public class MockCallable implements Callable { private ExpectationCounter callCount = new ExpectationCounter("call.count"); private ExpectationValue callMock = new ExpectationValue("call.mock"); private ExpectationValue callMethodName = new ExpectationValue("call.methodName"); private ExpectationList callArgs = new ExpectationList("call.args"); private ReturnValue callResult = new ReturnValue("call.return"); private Throwable callThrow = null; private ExpectationValue matchesMethodName = new ExpectationValue("matches.methodName"); private ExpectationList matchesArgs = new ExpectationList("matches.args"); private ReturnValue matchesResult = new ReturnValue("matches.return"); private ExpectationCounter verifyCount = new ExpectationCounter("verify.count"); private AssertionFailedError verifyError = null; private ReturnValue toStringResult = new ReturnValue("toString.return"); public void setExpectedCallCount( int count ) { callCount.setExpected(count); } public void setExpectedCall( Mock mock, String methodName, Object[] args ) { callMock.setExpected(mock); callMethodName.setExpected(methodName); callArgs.addExpectedMany(args); } public void setupCallReturn( Object result ) { callResult.setValue(result); } public void setupCallThrow( Throwable thrown ) { callThrow = thrown; } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { callMock.setActual(mock); callMethodName.setActual(methodName); callArgs.addActualMany(args); callCount.inc(); if( callThrow != null ) { throw callThrow; } else { return callResult.getValue(); } } public void setExpectedMatches( String methodName, Object[] args ) { matchesMethodName.setExpected(methodName); matchesArgs.addExpectedMany(args); } public void setupMatchesReturn( boolean result ) { matchesResult.setValue(result); } public boolean matches(String methodName, Object[] args) { matchesMethodName.setActual(methodName); matchesArgs.addActualMany(args); return matchesResult.getBooleanValue(); } public void setExpectedVerifyCalls( int count ) { verifyCount.setExpected(count); } public void setupVerifyThrow( AssertionFailedError err ) { verifyError = err; } /** @deprecated to avoid calling verify instead of verifyExpectations */ public void verify() { verifyCount.inc(); if( verifyError != null ) throw verifyError; } /** We have to rename 'verify' because we want to mock the behaviour of the * verify method itself. */ public void verifyExpectations() { Verifier.verifyObject(this); } public void setupGetDescription( String result ) { toStringResult.setValue(result); } public String getDescription() { return (String)toStringResult.getValue(); } } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.3 retrieving revision 1.8.2.4 diff -u -r1.8.2.3 -r1.8.2.4 --- MockTest.java 7 Apr 2003 17:38:46 -0000 1.8.2.3 +++ MockTest.java 11 Apr 2003 13:21:16 -0000 1.8.2.4 @@ -49,7 +49,7 @@ final String[] expectedArgs = { "hello", "world" }; final String[] receivedArgs = new String[2]; - MockCallMocker mockMethod = new MockCallMocker(); + MockCallable mockMethod = new MockCallable(); mockMethod.setExpectedMatches( methodName, expectedArgs ); mockMethod.setupMatchesReturn(true); mockMethod.setExpectedCall( aMock, methodName, expectedArgs ); @@ -66,7 +66,7 @@ final String methodName = "aMethodWithNoArguments"; final Object[] expectedArgs = {}; - MockCallMocker mockMethod = new MockCallMocker(); + MockCallable mockMethod = new MockCallable(); mockMethod.setExpectedMatches( methodName, expectedArgs ); mockMethod.setupMatchesReturn(true); mockMethod.setExpectedCall( aMock, methodName, expectedArgs ); Index: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallMatchTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallMatchTest.java 7 Apr 2003 17:38:31 -0000 1.1.2.1 +++ CallMatchTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.2 @@ -13,7 +13,7 @@ final String methodName = "methodName"; Mock mock = new Mock(DummyInterface.class,"mock"); - MockCallMocker mockDecorated = new MockCallMocker(); + MockCallable mockDecorated = new MockCallable(); CallMatch call = new CallMatch( methodName, new Constraint[0], mockDecorated ); public CallMatchTest(String name) { Index: ExpectedCallTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/ExpectedCallTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- ExpectedCallTest.java 7 Apr 2003 17:38:38 -0000 1.1.2.2 +++ ExpectedCallTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.3 @@ -19,7 +19,7 @@ final String decoratedDescription = AssertMo.methodToString( methodName, args ); Mock ignoredMock = null; - MockCallMocker mockDecorated = new MockCallMocker(); + MockCallable mockDecorated = new MockCallable(); ExpectedCall call = new ExpectedCall( mockDecorated ); public ExpectedCallTest(String name) { Index: MockCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockCallFactory.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- MockCallFactory.java 7 Apr 2003 17:38:36 -0000 1.1.2.1 +++ MockCallFactory.java 11 Apr 2003 13:21:16 -0000 1.1.2.2 @@ -1,11 +1,8 @@ package test.mockobjects.dynamic; -import mockmaker.ReturnValues; -import mockmaker.VoidReturnValues; -import mockmaker.ExceptionalReturnValue; import com.mockobjects.*; import com.mockobjects.dynamic.CallFactory; -import com.mockobjects.dynamic.CallMocker; +import com.mockobjects.dynamic.Callable; import com.mockobjects.constraint.Constraint; public class MockCallFactory implements CallFactory{ @@ -15,14 +12,14 @@ private ExpectationCounter myCreateThrowStubCalls = new ExpectationCounter("MockCallFactory.createThrowStub(Throwable)"); private ReturnValues myActualCreateThrowStubReturnValues = new ReturnValues("MockCallFactory.createThrowStub(Throwable)", true); private ExpectationList myCreateThrowStubParameter0Values = new ExpectationList("MockCallFactory.createThrowStub(Throwable) java.lang.Throwable"); - private ExpectationCounter myCreateExpectedCallCalls = new ExpectationCounter("MockCallFactory.createExpectedCall(CallMocker)"); - private ReturnValues myActualCreateExpectedCallReturnValues = new ReturnValues("MockCallFactory.createExpectedCall(CallMocker)", true); - private ExpectationList myCreateExpectedCallParameter0Values = new ExpectationList("MockCallFactory.createExpectedCall(CallMocker) com.mockobjects.dynamic.CallMocker"); - private ExpectationCounter myCreateCallMatchCalls = new ExpectationCounter("MockCallFactory.createCallMatch(String, Constraint[], CallMocker)"); - private ReturnValues myActualCreateCallMatchReturnValues = new ReturnValues("MockCallFactory.createCallMatch(String, Constraint[], CallMocker)", true); - private ExpectationList myCreateCallMatchParameter0Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], CallMocker) java.lang.String"); - private ExpectationList myCreateCallMatchParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], CallMocker) com.mockobjects.constraint.Constraint"); - private ExpectationList myCreateCallMatchParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], CallMocker) com.mockobjects.dynamic.CallMocker"); + private ExpectationCounter myCreateExpectedCallCalls = new ExpectationCounter("MockCallFactory.createExpectedCall(Callable)"); + private ReturnValues myActualCreateExpectedCallReturnValues = new ReturnValues("MockCallFactory.createExpectedCall(Callable)", true); + private ExpectationList myCreateExpectedCallParameter0Values = new ExpectationList("MockCallFactory.createExpectedCall(Callable) com.mockobjects.dynamic.Callable"); + private ExpectationCounter myCreateCallMatchCalls = new ExpectationCounter("MockCallFactory.createCallMatch(String, Constraint[], Callable)"); + private ReturnValues myActualCreateCallMatchReturnValues = new ReturnValues("MockCallFactory.createCallMatch(String, Constraint[], Callable)", true); + private ExpectationList myCreateCallMatchParameter0Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], Callable) java.lang.String"); + private ExpectationList myCreateCallMatchParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], Callable) com.mockobjects.constraint.Constraint"); + private ExpectationList myCreateCallMatchParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], Callable) com.mockobjects.dynamic.Callable"); public void setExpectedCreateReturnStubCalls(int calls){ myCreateReturnStubCalls.setExpected(calls); @@ -32,20 +29,20 @@ myCreateReturnStubParameter0Values.addExpected(arg0); } - public CallMocker createReturnStub(Object arg0){ + public Callable createReturnStub(Object arg0){ myCreateReturnStubCalls.inc(); myCreateReturnStubParameter0Values.addActual(arg0); Object nextReturnValue = myActualCreateReturnStubReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (CallMocker) nextReturnValue; + return (Callable) nextReturnValue; } public void setupExceptionCreateReturnStub(Throwable arg){ myActualCreateReturnStubReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateReturnStub(CallMocker arg){ + public void setupCreateReturnStub(Callable arg){ myActualCreateReturnStubReturnValues.add(arg); } @@ -57,20 +54,20 @@ myCreateThrowStubParameter0Values.addExpected(arg0); } - public CallMocker createThrowStub(Throwable arg0){ + public Callable createThrowStub(Throwable arg0){ myCreateThrowStubCalls.inc(); myCreateThrowStubParameter0Values.addActual(arg0); Object nextReturnValue = myActualCreateThrowStubReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (CallMocker) nextReturnValue; + return (Callable) nextReturnValue; } public void setupExceptionCreateThrowStub(Throwable arg){ myActualCreateThrowStubReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateThrowStub(CallMocker arg){ + public void setupCreateThrowStub(Callable arg){ myActualCreateThrowStubReturnValues.add(arg); } @@ -78,24 +75,24 @@ myCreateExpectedCallCalls.setExpected(calls); } - public void addExpectedCreateExpectedCall(CallMocker arg0){ + public void addExpectedCreateExpectedCall(Callable arg0){ myCreateExpectedCallParameter0Values.addExpected(arg0); } - public CallMocker createExpectedCall(CallMocker arg0){ + public Callable createExpectedCall(Callable arg0){ myCreateExpectedCallCalls.inc(); myCreateExpectedCallParameter0Values.addActual(arg0); Object nextReturnValue = myActualCreateExpectedCallReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (CallMocker) nextReturnValue; + return (Callable) nextReturnValue; } public void setupExceptionCreateExpectedCall(Throwable arg){ myActualCreateExpectedCallReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateExpectedCall(CallMocker arg){ + public void setupCreateExpectedCall(Callable arg){ myActualCreateExpectedCallReturnValues.add(arg); } @@ -103,28 +100,28 @@ myCreateCallMatchCalls.setExpected(calls); } - public void addExpectedCreateCallMatch(String arg0, Constraint[] arg1, CallMocker arg2){ + public void addExpectedCreateCallMatch(String arg0, Constraint[] arg1, Callable arg2){ myCreateCallMatchParameter0Values.addExpected(arg0); - myCreateCallMatchParameter1Values.addExpected(arg1); + myCreateCallMatchParameter1Values.addExpectedMany(arg1); myCreateCallMatchParameter2Values.addExpected(arg2); } - public CallMocker createCallMatch(String arg0, Constraint[] arg1, CallMocker arg2){ + public Callable createCallMatch(String arg0, Constraint[] arg1, Callable arg2){ myCreateCallMatchCalls.inc(); myCreateCallMatchParameter0Values.addActual(arg0); - myCreateCallMatchParameter1Values.addActual(arg1); + myCreateCallMatchParameter1Values.addActualMany(arg1); myCreateCallMatchParameter2Values.addActual(arg2); Object nextReturnValue = myActualCreateCallMatchReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (CallMocker) nextReturnValue; + return (Callable) nextReturnValue; } public void setupExceptionCreateCallMatch(Throwable arg){ myActualCreateCallMatchReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateCallMatch(CallMocker arg){ + public void setupCreateCallMatch(Callable arg){ myActualCreateCallMatchReturnValues.add(arg); } Index: CallSetTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSetTest.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- CallSetTest.java 10 Apr 2003 21:26:09 -0000 1.1.2.4 +++ CallSetTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.5 @@ -15,14 +15,14 @@ public class CallSetTest extends TestCase { private MockCallFactory mockCallFactory = new MockCallFactory(); private CallSet callSet = new CallSet(mockCallFactory); - private MockCallMocker mockReturnStub = new MockCallMocker(); - private MockCallMocker mockCallMatch = new MockCallMocker(); - private MockCallMocker mockExpectedCall = new MockCallMocker(); - private MockCallMocker mockThrowStub = new MockCallMocker(); + private MockCallable mockReturnStub = new MockCallable(); + private MockCallable mockCallMatch = new MockCallable(); + private MockCallable mockExpectedCall = new MockCallable(); + private MockCallable mockThrowStub = new MockCallable(); private Mock unusedMock = null; - private MockCallMocker methodA = new MockCallMocker(); - private MockCallMocker methodB = new MockCallMocker(); + private MockCallable methodA = new MockCallable(); + private MockCallable methodB = new MockCallable(); final String METHOD_A_NAME = "methodA"; final String[] METHOD_A_ARGS = new String[] { "a1", "a2" }; final Constraint[] METHOD_A_CONSTRAINTS = C.args( C.eq("a1"), C.eq("a2") ); @@ -87,7 +87,7 @@ Verifier.verifyObject(this); } - public void testPermitAndReturn() throws Throwable{ + public void testMatchAndReturn() throws Throwable{ mockCallMatch.setupMatchesReturn(true); mockCallMatch.setupCallReturn(METHOD_A_RESULT); @@ -104,7 +104,7 @@ Verifier.verifyObject(this); } - public void testPermitOneAndReturn() throws Throwable{ + public void testMatchOneAndReturn() throws Throwable{ final String PARAMETER = "One Arg Method"; mockCallMatch.setupMatchesReturn(true); mockCallMatch.setupCallReturn(METHOD_A_RESULT); @@ -121,6 +121,26 @@ Verifier.verifyObject(this); } + + public void testExpectOneAndReturn() throws Throwable{ + final String PARAMETER = "One Arg Method"; + mockExpectedCall.setupMatchesReturn(true); + mockExpectedCall.setupCallReturn(METHOD_A_RESULT); + + mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); + mockCallFactory.setupCreateReturnStub( mockReturnStub ); + mockCallFactory.addExpectedCreateCallMatch( "oneArgMethod", C.args(C.eq(PARAMETER)), mockReturnStub ); + mockCallFactory.setupCreateCallMatch( mockCallMatch ); + mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); + mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); + + callSet.expectAndReturn( "oneArgMethod", PARAMETER, METHOD_A_RESULT ); + + assertSame( "should be result of calling expected call", + METHOD_A_RESULT, callSet.call( unusedMock, "oneArgMethod", new Object[] {PARAMETER}) ); + + Verifier.verifyObject(this); + } public void testExpectAndThrow() throws Throwable{ mockExpectedCall.setupMatchesReturn(true); @@ -145,7 +165,7 @@ fail("Should have thrown configured exception"); } - public void testPermitAndThrow() throws Throwable{ + public void testMatchAndThrow() throws Throwable{ mockCallMatch.setupMatchesReturn(true); mockCallMatch.setupCallThrow(METHOD_A_EXCEPTION); --- MockCallMocker.java DELETED --- |