You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(151) |
Sep
(21) |
Oct
(6) |
Nov
(70) |
Dec
(8) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(47) |
Feb
(66) |
Mar
(23) |
Apr
(115) |
May
(24) |
Jun
(53) |
Jul
(10) |
Aug
(279) |
Sep
(84) |
Oct
(149) |
Nov
(138) |
Dec
(52) |
2003 |
Jan
(22) |
Feb
(20) |
Mar
(29) |
Apr
(106) |
May
(170) |
Jun
(122) |
Jul
(70) |
Aug
(64) |
Sep
(27) |
Oct
(71) |
Nov
(49) |
Dec
(9) |
2004 |
Jan
(7) |
Feb
(38) |
Mar
(3) |
Apr
(9) |
May
(22) |
Jun
(4) |
Jul
(1) |
Aug
(2) |
Sep
(2) |
Oct
|
Nov
(15) |
Dec
(2) |
2005 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(28) |
Jun
(3) |
Jul
(11) |
Aug
(5) |
Sep
(1) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2006 |
Jan
(8) |
Feb
(3) |
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Tim M. <ma...@us...> - 2003-04-15 22:23:04
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6206/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallMatch.java Mock.java ExpectedCall.java C.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: CallMatch.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallMatch.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallMatch.java 11 Apr 2003 13:18:46 -0000 1.1.2.2 +++ CallMatch.java 15 Apr 2003 22:22:57 -0000 1.1.2.3 @@ -16,7 +16,7 @@ public CallMatch( String methodName, Constraint[] constraints, Callable decorated ) { this.methodName = methodName; - this.constraints = (Constraint[])constraints.clone(); + this.constraints = constraints == null ? null : (Constraint[])constraints.clone(); this.decorated = decorated; } @@ -55,5 +55,10 @@ public String getDescription() { return AssertMo.methodToString(methodName, constraints); + } + + // Implemented to aid visualisation in an IDE debugger + public String toString() { + return Mock.className(this.getClass()) + "(" + this.getDescription() + ")"; } } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.4 retrieving revision 1.16.2.5 diff -u -r1.16.2.4 -r1.16.2.5 --- Mock.java 14 Apr 2003 18:46:52 -0000 1.16.2.4 +++ Mock.java 15 Apr 2003 22:22:58 -0000 1.16.2.5 @@ -36,16 +36,24 @@ } public static String mockNameFromClass(Class c) { + return "mock" + className(c); + } + + public static String className(Class c) { String name = c.getName(); int dotIndex = name.lastIndexOf('.'); if (dotIndex >= 0) { - return "mock" + name.substring(dotIndex + 1); + return name.substring(dotIndex + 1); } else { - return "mock" + name; + return name; } } + public String getMockName() { + return name; + } + public String toString() { return name; } @@ -57,12 +65,27 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - return callSequence.call(this, method.getName(), ((args == null) ? new Object[0] : args)); + if(checkingProxyEquality(method, args)) { + return new Boolean(args[0] == this.proxy); + } else if(gettingMockName(method, args)) { + return this.getMockName(); + } else { + Object result = callSequence.call(this, method.getName(), ((args == null) ? new Object[0] : args)); + return result; + } } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); } } + private boolean checkingProxyEquality(Method method, Object[] args) { + return (method.getName().equals("equals")) && (args.length == 1) && (Proxy.isProxyClass(args[0].getClass())); + } + + private boolean gettingMockName(Method method, Object[] args) { + return (method.getName().equals("getMockName")) && (args.length == 0); + } + public void verify() { try { callSequence.verify(); @@ -71,35 +94,145 @@ } } - public void expect(String methodName, Object equalArg) { - expect(methodName, C.args(C.eq(equalArg))); + public void expect(String methodName) { + expect(methodName, C.NO_ARGS); } + public void expect(String methodName, Object singleEqualArg) { + expect(methodName, C.args(C.eq(singleEqualArg))); + } + public void expect(String methodName, Constraint[] args) { callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createVoidStub()))); } - - public void expectAndReturn(String methodName, Object equalArg, Object result) { - expectAndReturn(methodName, C.args(C.eq(equalArg)), result); + + public void expectAndReturn(String methodName, Object result) { + this.expectAndReturn(methodName, C.NO_ARGS, result); + } + + public void expectAndReturn(String methodName, boolean result) { + this.expectAndReturn(methodName, new Boolean(result)); + } + + public void expectAndReturn(String methodName, long result) { + this.expectAndReturn(methodName, new Long(result)); } + public void expectAndReturn(String methodName, Object singleEqualArg, Object result) { + this.expectAndReturn(methodName, C.args(C.eq(singleEqualArg)), result); + } + + public void expectAndReturn(String methodName, Object singleEqualArg, boolean result) { + this.expectAndReturn(methodName, singleEqualArg, new Boolean(result)); + } + + public void expectAndReturn(String methodName, Object singleEqualArg, long result) { + this.expectAndReturn(methodName, singleEqualArg, new Long(result)); + } + public void expectAndReturn(String methodName, Constraint[] args, Object result) { callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result)))); } + + public void expectAndReturn(String methodName, Constraint[] args, boolean result) { + this.expectAndReturn(methodName, args, new Boolean(result)); + } + + public void expectAndReturn(String methodName, Constraint[] args, long result) { + this.expectAndReturn(methodName, args, new Long(result)); + } + public void expectAndThrow(String methodName, Throwable exception) { + this.expectAndThrow(methodName, C.NO_ARGS, exception); + } + + public void expectAndThrow(String methodName, Object singleEqualArg, Throwable exception) { + this.expectAndThrow(methodName, C.args(C.eq(singleEqualArg)), exception); + } + public void expectAndThrow(String methodName, Constraint[] args, Throwable exception) { callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(exception)))); } - - public void matchAndReturn(String methodName, Object equalArg, Object result) { - matchAndReturn(methodName, C.args(C.eq(equalArg)), result); + + public void matchAndReturn(String methodName, Object result) { + this.matchAndReturn(methodName, C.NO_ARGS, result); } - + + public void matchAndReturn(String methodName, boolean result) { + this.matchAndReturn(methodName, new Boolean(result)); + } + + public void matchAndReturn(String methodName, long result) { + this.matchAndReturn(methodName, new Long(result)); + } + + public void matchAndReturn(String methodName, Object singleEqualArg, Object result) { + this.matchAndReturn(methodName, C.args(C.eq(singleEqualArg)), result); + } + + public void matchAndReturn(String methodName, boolean singleEqualArg, Object result) { + this.matchAndReturn(methodName, new Boolean(singleEqualArg), result); + } + + public void matchAndReturn(String methodName, long singleEqualArg, Object result) { + this.matchAndReturn(methodName, new Long(singleEqualArg), result); + } + + public void matchAndReturn(String methodName, Object singleEqualArg, boolean result) { + this.matchAndReturn(methodName, singleEqualArg, new Boolean(result)); + } + + public void matchAndReturn(String methodName, Object singleEqualArg, long result) { + this.matchAndReturn(methodName, singleEqualArg, new Long(result)); + } + public void matchAndReturn(String methodName, Constraint[] args, Object result) { callSequence.add(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result))); } + + public void matchAndReturn(String methodName, Constraint[] args, boolean result) { + this.matchAndReturn(methodName, args, new Boolean(result)); + } + public void matchAndReturn(String methodName, Constraint[] args, long result) { + this.matchAndReturn(methodName, args, new Long(result)); + } + + public void matchAndThrow(String methodName, Throwable throwable) { + this.matchAndThrow(methodName, C.NO_ARGS, throwable); + } + + public void matchAndThrow(String methodName, Object singleEqualArg, Throwable throwable) { + this.matchAndThrow(methodName, C.args(C.eq(singleEqualArg)), throwable); + } + + public void matchAndThrow(String methodName, boolean singleEqualArg, Throwable throwable) { + this.matchAndThrow(methodName,new Boolean(singleEqualArg), throwable); + } + + public void matchAndThrow(String methodName, long singleEqualArg, Throwable throwable) { + this.matchAndThrow(methodName,new Long(singleEqualArg), throwable); + } + public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { callSequence.add(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(throwable))); + } + + /** @deprecated @see OrderedMock + */ + public void expect(String methodName, CallSequence deprecated) { + throw new AssertionFailedError("method is deprecated! Use: new OrderedMock() instead..."); + } + + /** @deprecated @see OrderedMock + */ + public void expectAndReturn(String methodName, CallSequence deprecated, Object result) { + throw new AssertionFailedError("method is deprecated! Use: new OrderedMock() instead..."); + } + + /** @deprecated @see OrderedMock + */ + public void expectAndThrow(String methodName, CallSequence deprecated, Throwable throwable) { + throw new AssertionFailedError("method is deprecated! Use: new OrderedMock() instead..."); } } Index: ExpectedCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/ExpectedCall.java,v retrieving revision 1.2.2.4 retrieving revision 1.2.2.5 diff -u -r1.2.2.4 -r1.2.2.5 --- ExpectedCall.java 11 Apr 2003 15:38:18 -0000 1.2.2.4 +++ ExpectedCall.java 15 Apr 2003 22:22:59 -0000 1.2.2.5 @@ -36,4 +36,9 @@ delegate.verify(); } + + // Implemented to aid visualisation in an IDE debugger + public String toString() { + return Mock.className(this.getClass()) + "(" + this.getDescription() + ")"; + } } Index: C.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- C.java 10 Apr 2003 20:35:59 -0000 1.1.2.3 +++ C.java 15 Apr 2003 22:23:00 -0000 1.1.2.4 @@ -20,6 +20,7 @@ public static final Constraint IS_NOT_ZERO = not(IS_ZERO); public static final Constraint[] ANY_ARGS = null; + public static final Constraint[] NO_ARGS = new Constraint[0]; public static Constraint same( Object o ) { |
From: Tim M. <ma...@us...> - 2003-04-14 18:47:29
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv2259/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment Mock.java OrderedMock.java Added Files: Tag: DynamicMockExperiment CallSequence.java Log Message: Added CallSequence and OrderedMock This gives a usable reference implementation Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.3 retrieving revision 1.16.2.4 diff -u -r1.16.2.3 -r1.16.2.4 --- Mock.java 14 Apr 2003 08:46:27 -0000 1.16.2.3 +++ Mock.java 14 Apr 2003 18:46:52 -0000 1.16.2.4 @@ -18,12 +18,12 @@ private String name; private Object proxy; private CallFactory callFactory; - private CallableAddable callSet; + private CallableAddable callSequence; public Mock(CallFactory callFactory, CallableAddable callableAddable, Class mockedClass, String name) { this.name = name; this.callFactory = callFactory; - this.callSet = callableAddable; + this.callSequence = callableAddable; this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this); } @@ -57,7 +57,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - return callSet.call(this, method.getName(), ((args == null) ? new Object[0] : args)); + return callSequence.call(this, method.getName(), ((args == null) ? new Object[0] : args)); } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); } @@ -65,7 +65,7 @@ public void verify() { try { - callSet.verify(); + callSequence.verify(); } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); } @@ -76,7 +76,7 @@ } public void expect(String methodName, Constraint[] args) { - callSet.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createVoidStub()))); + callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createVoidStub()))); } public void expectAndReturn(String methodName, Object equalArg, Object result) { @@ -84,11 +84,11 @@ } public void expectAndReturn(String methodName, Constraint[] args, Object result) { - callSet.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result)))); + callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result)))); } public void expectAndThrow(String methodName, Constraint[] args, Throwable exception) { - callSet.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(exception)))); + callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(exception)))); } public void matchAndReturn(String methodName, Object equalArg, Object result) { @@ -96,10 +96,10 @@ } public void matchAndReturn(String methodName, Constraint[] args, Object result) { - callSet.add(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result))); + callSequence.add(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result))); } public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { - callSet.add(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(throwable))); + callSequence.add(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(throwable))); } } Index: OrderedMock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/OrderedMock.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- OrderedMock.java 11 Apr 2003 13:18:45 -0000 1.1.2.1 +++ OrderedMock.java 14 Apr 2003 18:46:52 -0000 1.1.2.2 @@ -9,11 +9,11 @@ public class OrderedMock extends Mock { public OrderedMock(Class mockedClass) { - super(mockedClass); + this(mockedClass, mockNameFromClass(mockedClass)); } public OrderedMock(Class mockedClass, String name) { - super(mockedClass, name); + super(new DefaultCallFactory(), new CallSequence(),mockedClass, name); } } |
From: Tim M. <ma...@us...> - 2003-04-14 18:47:25
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv2259/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServlet.java SimpleServletTest.java Log Message: Added CallSequence and OrderedMock This gives a usable reference implementation Index: SimpleServlet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServlet.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- SimpleServlet.java 14 Apr 2003 08:46:29 -0000 1.1.2.4 +++ SimpleServlet.java 14 Apr 2003 18:46:51 -0000 1.1.2.5 @@ -19,12 +19,13 @@ String body = request.getParameter("body"); String subject = request.getParameter("subject"); - String subjectCopy = request.getParameter("subject"); String browser = request.getParameter("browser-identifier"); + String subjectCopy = request.getParameter("subject"); //String pet = request.getParameter("favourite-pet"); - + response.setContentType("text/html"); Writer writer = response.getWriter(); + } } Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- SimpleServletTest.java 14 Apr 2003 08:46:29 -0000 1.1.2.6 +++ SimpleServletTest.java 14 Apr 2003 18:46:51 -0000 1.1.2.7 @@ -52,11 +52,11 @@ } */ public void testDoGetNew() throws ServletException, IOException { - Mock mockHttpServletResponse = new Mock(HttpServletResponse.class, "response"); - Mock mockHttpServletRequest = new OrderedMock(HttpServletRequest.class); + Mock mockHttpServletResponse = new OrderedMock(HttpServletResponse.class, "response"); + Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.matchAndReturn( "getParameter", C.args(C.eq("browser-identifier")), "MSIE-5.0" ); - mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("subject")), "Mail Subject" ); + mockHttpServletRequest.expectAndReturn( "getParameter", "subject", "Mail Subject" ); mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), "Mail Body" ); final PrintWriter contentWriter = new PrintWriter(new StringWriter()); |
From: Tim M. <ma...@us...> - 2003-04-14 18:47:07
|
Update of /cvsroot/mockobjects/mockobjects-java/src In directory sc8-pr-cvs1:/tmp/cvs-serv2259 Added Files: Tag: DynamicMockExperiment .cvsignore Log Message: Added CallSequence and OrderedMock This gives a usable reference implementation --- NEW FILE: .cvsignore --- .classpath .project |
From: Tim M. <ma...@us...> - 2003-04-14 18:47:06
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv2259/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSetTest.java Added Files: Tag: DynamicMockExperiment CallSequenceTest.java Log Message: Added CallSequence and OrderedMock This gives a usable reference implementation --- NEW FILE: CallSequenceTest.java --- /* * Created on 14-Apr-2003 */ package test.mockobjects.dynamic; import junit.framework.AssertionFailedError; import junit.framework.TestCase; import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.CallSequence; import com.mockobjects.dynamic.Mock; import com.mockobjects.util.AssertMo; public class CallSequenceTest extends TestCase { final String METHOD_A_NAME = "methodA"; final String METHOD_A_RESULT = "resultA"; final String METHOD_B_NAME = "methodB"; final String METHOD_B_RESULT = "resultB"; private static final String MOCK_NAME = "Test mock"; final Throwable METHOD_A_EXCEPTION = new DummyThrowable("Configured test throwable"); final String[] METHOD_A_ARGS = new String[] { "a1", "a2" }; final Constraint[] METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2")); final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; private CallSequence callSequence = new CallSequence(); private Mock unusedMock = null; private MockCallable methodA = new MockCallable(); private MockCallable methodB = new MockCallable(); private MockCallable mockCallable = new MockCallable(); public void testCallableThrowableThrown() throws Throwable { final Throwable throwable = new DummyThrowable(); mockCallable.setupMatchesReturn(true); mockCallable.setupCallThrow(throwable); callSequence.add(mockCallable); try { callSequence.call(unusedMock, "hello", new String[0]); } catch (Throwable ex) { assertSame("exception is caught by mock", throwable, ex); } } public void testCallFailsOnEmptyList() throws Throwable { try { callSequence.call(unusedMock, "missingMethod", new Object[0]); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage()); return; } fail("Should fail for a missing item"); } public void testCallPassedToContainedElements() throws Throwable { methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); methodA.setupMatchesReturn(true); methodA.setExpectedCall(unusedMock, METHOD_A_NAME, METHOD_A_ARGS); methodA.setupCallReturn(METHOD_A_RESULT); methodB.setExpectedCallCount(0); callSequence.add(methodA); callSequence.add(methodB); assertSame("expected result from method A", METHOD_A_RESULT, callSequence.call(unusedMock, METHOD_A_NAME, METHOD_A_ARGS)); methodA.verifyExpectations(); methodB.verifyExpectations(); } public void testCallPassedToContainedElementsOtherOrderShouldFail() throws Throwable { methodA.setupMatchesReturn(false); methodA.setupGetDescription("***methodA-description****"); methodB.setupGetDescription("***methodB-description****"); callSequence.add(methodA); callSequence.add(methodB); try { assertSame("expected result from method B", METHOD_B_RESULT, callSequence.call(unusedMock, METHOD_B_NAME, METHOD_B_ARGS)); } catch (AssertionFailedError ex) { String message = ex.getMessage(); AssertMo.assertIncludes("Should have expected error message", "Unexpected call to methodB", message); AssertMo.assertIncludes("Should have arguments in error message (1)", METHOD_B_ARGS[0], message); AssertMo.assertIncludes("Should have arguments in error message (2)", METHOD_B_ARGS[1], message); AssertMo.assertIncludes("Should have Index pointer next to correct item", methodA.getDescription() + " <<<", message); AssertMo.assertIncludes("shows set contents (A)", methodA.getDescription(), message); AssertMo.assertIncludes("shows set contents (B)", methodB.getDescription(), message); AssertMo.assertTrue("Method A should be before method B", message.indexOf(methodA.getDescription()) < message.indexOf(methodB.getDescription())); return; } fail("Should fail due to wrong order"); } public void testConfiguredResultReturned() throws Throwable { final String result = "result"; mockCallable.setupCallReturn(result); mockCallable.setupMatchesReturn(true); callSequence.add(mockCallable); assertSame("result is returned by mock", result, callSequence.call(unusedMock, "method", new Object[0])); } public void testEmptySetVerifies() throws Exception { callSequence.verify(); } public void testFailureIfNoElementMatches() throws Throwable { final String methodCName = "methodC"; final String[] methodCArgs = { "c1", "c2" }; methodA.setExpectedMatches(methodCName, methodCArgs); methodA.setupMatchesReturn(false); methodA.setExpectedCallCount(0); methodA.setupGetDescription("***methodA-description****"); methodB.setExpectedCall(unusedMock, methodCName, methodCArgs); methodB.setupMatchesReturn(false); methodB.setExpectedCallCount(0); methodB.setupGetDescription("***methodB-description****"); callSequence.add(methodA); callSequence.add(methodB); try { callSequence.call(unusedMock, methodCName, methodCArgs); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("method name is in error message", "methodC", ex.getMessage()); AssertMo.assertIncludes("argument is in error message (1)", methodCArgs[0], ex.getMessage()); AssertMo.assertIncludes("argument is in error message (2)", methodCArgs[1], ex.getMessage()); AssertMo.assertIncludes("shows set contents (A)", methodA.getDescription(), ex.getMessage()); AssertMo.assertIncludes("shows set contents (B)", methodB.getDescription(), ex.getMessage()); return; } fail("Should fail for a missing item"); } public void testVerifiesIfAllContainedElementsVerify() throws Throwable { methodA.setExpectedVerifyCalls(1); methodB.setExpectedVerifyCalls(1); callSequence.add(methodA); callSequence.add(methodB); callSequence.verify(); methodA.verifyExpectations(); methodB.verifyExpectations(); } public void testVerifyFailsIfContainedElementDoesNotVerify() throws Exception { methodA.setExpectedVerifyCalls(1); methodA.setupVerifyThrow(new AssertionFailedError("verify failed")); callSequence.add(methodA); try { callSequence.verify(); } catch (AssertionFailedError ex) { methodA.verifyExpectations(); return; } fail("Should have got a failure for contained element failing"); } public CallSequenceTest(String name) { super(name); } } Index: CallSetTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSetTest.java,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- CallSetTest.java 14 Apr 2003 08:46:29 -0000 1.1.2.7 +++ CallSetTest.java 14 Apr 2003 18:46:54 -0000 1.1.2.8 @@ -30,10 +30,6 @@ private MockCallable methodA = new MockCallable(); private MockCallable methodB = new MockCallable(); private MockCallable mockCallable = new MockCallable(); -// private MockCallable mockExpectedCall = new MockCallable(); -// private MockCallable mockReturnStub = new MockCallable(); -// private MockCallable mockThrowStub = new MockCallable(); -// private MockCallable mockVoidStub = new MockCallable(); public CallSetTest(String name) { |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv14578/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment MockTest.java DummyInterface.java CallSetTest.java Added Files: Tag: DynamicMockExperiment MockCallableAddable.java Log Message: Made CallSet a composite of Mock (with CallableAddable interface) made tests that were tricky much simpler, and first step to CallList --- NEW FILE: MockCallableAddable.java --- package test.mockobjects.dynamic; import com.mockobjects.*; import com.mockobjects.dynamic.CallableAddable; import com.mockobjects.dynamic.Callable; public class MockCallableAddable extends MockCallable implements CallableAddable{ private ExpectationCounter myAddCalls = new ExpectationCounter("MockCallableAddable.add(Callable)"); private ReturnValues myActualAddReturnValues = new VoidReturnValues("MockCallableAddable.add(Callable)", true); private ExpectationList myAddParameter0Values = new ExpectationList("MockCallableAddable.add(Callable) com.mockobjects.dynamic.Callable"); public void setExpectedAddCalls(int calls){ myAddCalls.setExpected(calls); } public void addExpectedAdd(Callable arg0){ myAddParameter0Values.addExpected(arg0); } public void add(Callable arg0){ myAddCalls.inc(); myAddParameter0Values.addActual(arg0); Object nextReturnValue = myActualAddReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); } public void setupExceptionAdd(Throwable arg){ myActualAddReturnValues.add(new ExceptionalReturnValue(arg)); } public void verifyExpectations(){ super.verifyExpectations(); myAddCalls.verify(); myAddParameter0Values.verify(); } } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.4 retrieving revision 1.8.2.5 diff -u -r1.8.2.4 -r1.8.2.5 --- MockTest.java 11 Apr 2003 13:21:16 -0000 1.8.2.4 +++ MockTest.java 14 Apr 2003 08:46:28 -0000 1.8.2.5 @@ -3,119 +3,249 @@ */ package test.mockobjects.dynamic; +import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.*; import com.mockobjects.util.*; import junit.framework.*; -/** - * @author dev - */ -public class MockTest extends TestCase { - private Mock aMock; - private DummyInterface proxy; +public class MockTest extends TestCase { private static final String MOCK_NAME = "Test mock"; - - public MockTest(String name) { + final String METHOD_NOARG_NAME = "noArgMethodVoid"; + final String METHOD_ONEARG_NAME = "oneArgMethod"; + final String METHOD_ONEARG_RESULT = "resultOArgs"; + final String METHOD_TWOARG_NAME = "twoArgMethod"; + final String METHOD_TWOARG_RESULT = "resultTwoArgs"; + final Throwable METHOD_EXCEPTION = new DummyThrowable("Configured test throwable"); + final Object[] METHOD_NOARG_ARGS = new Object[0]; + final String[] METHOD_ONEARG_ARGS = new String[] { "oneP1" }; + final Constraint[] METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1")); + final String[] METHOD_TWOARG_ARGS = new String[] { "twoP1", "twoP2" }; + final Constraint[] METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2")); + private DummyInterface proxy; + private Mock mock; + private MockCallFactory mockCallFactory = new MockCallFactory(); + private MockCallable mockCallMatch = new MockCallable(); + private MockCallable mockExpectedCall = new MockCallable(); + private MockCallable mockReturnStub = new MockCallable(); + private MockCallable mockThrowStub = new MockCallable(); + private MockCallable mockVoidStub = new MockCallable(); + private MockCallableAddable mockCallableAddable = new MockCallableAddable(); + + public MockTest(String name) throws Exception { super(name); } - + public void setUp() { - aMock = new Mock( DummyInterface.class, MOCK_NAME ); + mock = new Mock(mockCallFactory, mockCallableAddable, DummyInterface.class, MOCK_NAME); + try { - proxy = (DummyInterface)aMock.proxy(); - } - catch( ClassCastException ex ) { + proxy = (DummyInterface)mock.proxy(); + } catch (ClassCastException ex) { fail("proxy is not of expected interface type"); } } - - public void testNewMockVerifies() throws Exception { - aMock.verify(); + + public void testExpect() throws Throwable { + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expect(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); } - public void testMockNameFromClass() throws Exception { - assertEquals( "mockString", Mock.mockNameFromClass(String.class) ); + public void testExpectOne() throws Throwable { + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expect(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); } - - public void testMockToStringContainsName() { - AssertMo.assertIncludes( "result of toString() should include name", - MOCK_NAME, aMock.toString() ); + + public void testExpectAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + + mock.expectAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); } - - public void testCallMockerReceivesArgumentsFromProxy() throws Throwable { - final String methodName = "aMethod"; - final String[] expectedArgs = { "hello", "world" }; - final String[] receivedArgs = new String[2]; - - MockCallable mockMethod = new MockCallable(); - mockMethod.setExpectedMatches( methodName, expectedArgs ); - mockMethod.setupMatchesReturn(true); - mockMethod.setExpectedCall( aMock, methodName, expectedArgs ); - mockMethod.setupCallReturn( "result ignored" ); - - aMock.add( mockMethod ); - - proxy.aMethod( expectedArgs[0], expectedArgs[1] ); - - mockMethod.verifyExpectations(); + + public void testExpectAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + + mock.expectAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); } - - public void testCallMockerReceivesEmptyArrayWhenNoArguments() throws Exception { - final String methodName = "aMethodWithNoArguments"; - final Object[] expectedArgs = {}; - - MockCallable mockMethod = new MockCallable(); - mockMethod.setExpectedMatches( methodName, expectedArgs ); - mockMethod.setupMatchesReturn(true); - mockMethod.setExpectedCall( aMock, methodName, expectedArgs ); - mockMethod.setupCallReturn( "result ignored" ); - - aMock.add( mockMethod ); - - proxy.aMethodWithNoArguments(); - - mockMethod.verifyExpectations(); + + public void testExpectOneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + + mock.expectAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); } - - public void testCallMockerResultReturnedByProxy() throws Throwable { - final String result = "result"; - - aMock.add( new ReturnStub(result) ); - - assertSame( "result is returned by mock", - result, proxy.aMethod( "hello", "world" ) ); + + public void testMatchAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + + mock.matchAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); } - public void testCallMockerThrowableThrownThroughProxy() throws Throwable { - final Throwable throwable = new DummyThrowable(); - - aMock.add( new ThrowStub(throwable) ); - - try { - proxy.aMethod( "hello", "world" ); - } - catch( Throwable ex ) { - assertSame( "exception is caught by mock", - throwable, ex ); - } + public void testMatchAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + + mock.matchAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); } - - public void testCallMockerAnnotatesAssertionFailedErrors() throws Throwable { + + public void testMatchOneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + + mock.matchAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMockAnnotatesAssertionFailedErrors() + throws Throwable { final String originalMessage = "original message"; final AssertionFailedError error = new AssertionFailedError(originalMessage); - - aMock.add( new ThrowStub(error) ); - + + mockCallableAddable.setupCallThrow(new AssertionFailedError(originalMessage)); + + try { + proxy.noArgMethodVoid(); + } catch (AssertionFailedError err) { + AssertMo.assertIncludes("should contain original message", originalMessage, err.getMessage()); + AssertMo.assertIncludes("should contain mock name", MOCK_NAME, err.getMessage()); + } + } + + public void testMockNameFromClass() throws Exception { + assertEquals("mockString", Mock.mockNameFromClass(String.class)); + } + + public void testMockProxyReturnsConfiguredResult() + throws Throwable { + final String result = "configured result"; + + mockCallableAddable.setupCallReturn(result); + + assertSame("result is returned by mock", result, proxy.oneArgMethod(METHOD_TWOARG_ARGS[0])); + } + + public void testMockProxySendsAllArgument() throws Throwable { + 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(); + } + + public void testMockProxySendsEmptyArrayWhenNoArguments() + throws Exception { + mockCallableAddable.setExpectedCall(mock, METHOD_NOARG_NAME, METHOD_NOARG_ARGS); + mockCallableAddable.setupCallReturn("result ignored"); + + proxy.noArgMethodVoid(); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMockProxyThrowsConfiguredExceptions() + throws Throwable { + final Throwable throwable = new DummyThrowable(); + + mockCallableAddable.setupCallReturn(new ThrowStub(throwable)); + try { - proxy.aMethod( "hello", "world" ); + proxy.noArgMethodVoid(); + } catch (Throwable ex) { + assertSame("exception is caught by mock", throwable, ex); } - catch( AssertionFailedError err ) { - AssertMo.assertIncludes( "should contain original message", - originalMessage, err.getMessage() ); - AssertMo.assertIncludes( "should contain mock name", - MOCK_NAME, err.getMessage() ); - } + } + + public void testMockToStringContainsName() { + AssertMo.assertIncludes("result of toString() should include name", MOCK_NAME, mock.toString()); + } + + public void testMockVerifies() throws Exception { + mockCallableAddable.setExpectedVerifyCalls(1); + + mock.verify(); + + mockCallableAddable.verifyExpectations(); } } Index: DummyInterface.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/DummyInterface.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- DummyInterface.java 10 Apr 2003 21:26:36 -0000 1.1.2.2 +++ DummyInterface.java 14 Apr 2003 08:46:29 -0000 1.1.2.3 @@ -7,8 +7,8 @@ * @author dev */ public interface DummyInterface { - public String aMethod( String arg1, String arg2 ) throws Throwable; - public String oneArgMethod( Object o); + public String twoArgMethod( String arg1, String arg2 ) throws Throwable; + public String oneArgMethod( String arg1); - public void aMethodWithNoArguments(); + public void noArgMethodVoid(); } Index: CallSetTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSetTest.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- CallSetTest.java 11 Apr 2003 15:38:21 -0000 1.1.2.6 +++ CallSetTest.java 14 Apr 2003 08:46:29 -0000 1.1.2.7 @@ -9,287 +9,178 @@ import junit.framework.*; + /** * @author dev */ public class CallSetTest extends TestCase { - private MockCallFactory mockCallFactory = new MockCallFactory(); - private CallSet callSet = new CallSet(mockCallFactory); - private MockCallable mockReturnStub = new MockCallable(); - private MockCallable mockCallMatch = new MockCallable(); - private MockCallable mockExpectedCall = new MockCallable(); - private MockCallable mockThrowStub = new MockCallable(); - private MockCallable mockVoidStub = new MockCallable(); - - private Mock unusedMock = null; - 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") ); final String METHOD_A_RESULT = "resultA"; - final Throwable METHOD_A_EXCEPTION = new DummyThrowable("Configured test throwable"); - final String METHOD_B_NAME = "methodB"; - final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; final String METHOD_B_RESULT = "resultB"; - - - public CallSetTest(String name) { - super(name); - } - - public void testEmptySetVerifies() throws Exception { - callSet.verify(); - } - - public void testVerifyFailsIfContainedElementDoesNotVerify() throws Exception { - methodA.setExpectedVerifyCalls(1); - methodA.setupVerifyThrow( new AssertionFailedError("verify failed") ); - callSet.add( methodA ); - - try { - callSet.verify(); - } catch (AssertionFailedError ex) { - methodA.verifyExpectations(); - return; - } - fail("Should have got a failure for contained element failing"); - } - - public void testVerifiesIfAllContainedElementsVerify() throws Throwable { - methodA.setExpectedVerifyCalls(1); - methodB.setExpectedVerifyCalls(1); - - callSet.add( methodA ); - callSet.add( methodB ); - callSet.verify(); - - methodA.verifyExpectations(); - methodB.verifyExpectations(); - } + private static final String MOCK_NAME = "Test mock"; - public void testExpect() throws Throwable{ - mockExpectedCall.setupMatchesReturn(true); - mockExpectedCall.setupCallReturn(METHOD_A_RESULT); - - mockCallFactory.setExpectedCreateVoidStubCalls(1); - mockCallFactory.setupCreateVoidStub( mockVoidStub ); - mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockVoidStub ); - mockCallFactory.setupCreateCallMatch( mockCallMatch ); - mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); - mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); - - callSet.expect( METHOD_A_NAME, METHOD_A_CONSTRAINTS ); - - assertSame( "should be result of calling expected call", - METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); - - Verifier.verifyObject(this); - } - - public void testExpectAndReturn() throws Throwable{ - mockExpectedCall.setupMatchesReturn(true); - mockExpectedCall.setupCallReturn(METHOD_A_RESULT); - - mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); - mockCallFactory.setupCreateReturnStub( mockReturnStub ); - mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockReturnStub ); - mockCallFactory.setupCreateCallMatch( mockCallMatch ); - mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); - mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); - - callSet.expectAndReturn( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_RESULT ); - - assertSame( "should be result of calling expected call", - METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); - - Verifier.verifyObject(this); - } - - public void testMatchAndReturn() throws Throwable{ - mockCallMatch.setupMatchesReturn(true); - mockCallMatch.setupCallReturn(METHOD_A_RESULT); - - mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); - mockCallFactory.setupCreateReturnStub( mockReturnStub ); - mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockReturnStub ); - mockCallFactory.setupCreateCallMatch( mockCallMatch ); - - callSet.matchAndReturn( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_RESULT ); - - assertSame( "should be result of calling expected call", - METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); - - Verifier.verifyObject(this); - } + final Throwable METHOD_A_EXCEPTION = new DummyThrowable("Configured test throwable"); + final String[] METHOD_A_ARGS = new String[] { "a1", "a2" }; + final Constraint[] METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2")); + final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; + private CallSet callSet = new CallSet(); + private Mock unusedMock = null; - public void testMatchOneAndReturn() throws Throwable{ - final String PARAMETER = "One Arg Method"; - mockCallMatch.setupMatchesReturn(true); - mockCallMatch.setupCallReturn(METHOD_A_RESULT); - - mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); - mockCallFactory.setupCreateReturnStub( mockReturnStub ); - mockCallFactory.addExpectedCreateCallMatch( "oneArgMethod", C.args(C.eq(PARAMETER)), mockReturnStub ); - mockCallFactory.setupCreateCallMatch( mockCallMatch ); - - callSet.matchAndReturn( "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); - } + private MockCallable methodA = new MockCallable(); + private MockCallable methodB = new MockCallable(); + private MockCallable mockCallable = new MockCallable(); +// private MockCallable mockExpectedCall = new MockCallable(); +// private MockCallable mockReturnStub = new MockCallable(); +// private MockCallable mockThrowStub = new MockCallable(); +// private MockCallable mockVoidStub = new MockCallable(); - 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); - mockExpectedCall.setupCallThrow(METHOD_A_EXCEPTION); - - mockCallFactory.addExpectedCreateThrowStub(METHOD_A_EXCEPTION); - mockCallFactory.setupCreateThrowStub( mockThrowStub ); - mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockThrowStub ); - mockCallFactory.setupCreateCallMatch( mockCallMatch ); - mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); - mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); - - callSet.expectAndThrow( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_EXCEPTION ); - - try { - callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ); - } catch (DummyThrowable ex) { - Verifier.verifyObject(this); - return; - } - - fail("Should have thrown configured exception"); + public CallSetTest(String name) { + super(name); } - - public void testMatchAndThrow() throws Throwable{ - mockCallMatch.setupMatchesReturn(true); - mockCallMatch.setupCallThrow(METHOD_A_EXCEPTION); - - mockCallFactory.addExpectedCreateThrowStub(METHOD_A_EXCEPTION); - mockCallFactory.setupCreateThrowStub( mockThrowStub ); - mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockThrowStub ); - mockCallFactory.setupCreateCallMatch( mockCallMatch ); - - callSet.matchAndThrow( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_EXCEPTION ); - + + public void testCallFailsOnEmptySet() throws Throwable { try { - callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ); - } catch (DummyThrowable ex) { - Verifier.verifyObject(this); + callSet.call(unusedMock, "missingMethod", new Object[0]); + } catch (AssertionFailedError ex) { + AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage()); + return; } - - fail("Should have thrown configured exception"); + + fail("Should fail for a missing item"); } - + public void testCallPassedToContainedElements() throws Throwable { - methodA.setExpectedMatches( METHOD_A_NAME, METHOD_A_ARGS ); + methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); methodA.setupMatchesReturn(true); - methodA.setExpectedCall( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ); + methodA.setExpectedCall(unusedMock, METHOD_A_NAME, METHOD_A_ARGS); methodA.setupCallReturn(METHOD_A_RESULT); - methodB.setExpectedCallCount( 0 ); - - callSet.add( methodA ); - callSet.add( methodB ); - - assertSame( "expected result from method A", - METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); - + methodB.setExpectedCallCount(0); + + callSet.add(methodA); + callSet.add(methodB); + + assertSame("expected result from method A", METHOD_A_RESULT, + callSet.call(unusedMock, METHOD_A_NAME, METHOD_A_ARGS)); + methodA.verifyExpectations(); methodB.verifyExpectations(); } - public void testCallPassedToContainedElementsOtherOrder() throws Throwable { - methodA.setExpectedMatches( METHOD_B_NAME, METHOD_B_ARGS ); + public void testCallPassedToContainedElementsOtherOrder() + throws Throwable { + methodA.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); methodA.setupMatchesReturn(false); - methodA.setExpectedCallCount( 0 ); - methodB.setExpectedCall( unusedMock, METHOD_B_NAME, METHOD_B_ARGS ); - + methodA.setExpectedCallCount(0); + methodB.setExpectedCall(unusedMock, METHOD_B_NAME, METHOD_B_ARGS); + methodB.setupCallReturn(METHOD_B_RESULT); - methodB.setExpectedMatches( METHOD_B_NAME, METHOD_B_ARGS ); + methodB.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); methodB.setupMatchesReturn(true); - - callSet.add( methodA ); - callSet.add( methodB ); - - assertSame( "expected result from method B", - METHOD_B_RESULT, callSet.call( unusedMock, METHOD_B_NAME, METHOD_B_ARGS ) ); - + + callSet.add(methodA); + callSet.add(methodB); + + assertSame("expected result from method B", METHOD_B_RESULT, + callSet.call(unusedMock, METHOD_B_NAME, METHOD_B_ARGS)); + methodA.verifyExpectations(); methodB.verifyExpectations(); } - + + public void testConfiguredResultReturned() throws Throwable { + final String result = "result"; + + mockCallable.setupCallReturn(result); + mockCallable.setupMatchesReturn(true); + + callSet.add(mockCallable); + + assertSame("result is returned by mock", result, callSet.call(unusedMock, "method", new Object[0])); + } + + public void testCallableThrowableThrown() + throws Throwable { + final Throwable throwable = new DummyThrowable(); + + mockCallable.setupMatchesReturn(true); + mockCallable.setupCallThrow(throwable); + + callSet.add(mockCallable); + + try { + callSet.call(unusedMock, "hello", new String[0]); + } catch (Throwable ex) { + assertSame("exception is caught by mock", throwable, ex); + } + } + + public void testEmptySetVerifies() throws Exception { + callSet.verify(); + } + public void testFailureIfNoElementMatches() throws Throwable { final String methodCName = "methodC"; final String[] methodCArgs = { "c1", "c2" }; - - methodA.setExpectedMatches( methodCName, methodCArgs ); + + methodA.setExpectedMatches(methodCName, methodCArgs); methodA.setupMatchesReturn(false); - methodA.setExpectedCallCount( 0 ); + methodA.setExpectedCallCount(0); methodA.setupGetDescription("***methodA-description****"); - methodB.setExpectedCall( unusedMock, methodCName, methodCArgs ); + methodB.setExpectedCall(unusedMock, methodCName, methodCArgs); methodB.setupMatchesReturn(false); - methodB.setExpectedCallCount( 0 ); + methodB.setExpectedCallCount(0); methodB.setupGetDescription("***methodB-description****"); - - callSet.add( methodA ); - callSet.add( methodB ); - + + callSet.add(methodA); + callSet.add(methodB); + try { - callSet.call( unusedMock, methodCName, methodCArgs ); + callSet.call(unusedMock, methodCName, methodCArgs); } catch (AssertionFailedError ex) { - AssertMo.assertIncludes( "method name is in error message", - "methodC", ex.getMessage() ); - AssertMo.assertIncludes( "argument is in error message (1)", - methodCArgs[0], ex.getMessage() ); - AssertMo.assertIncludes( "argument is in error message (2)", - methodCArgs[1], ex.getMessage() ); - - AssertMo.assertIncludes( "shows set contents (A)", - methodA.getDescription(), ex.getMessage() ); - AssertMo.assertIncludes( "shows set contents (B)", - methodB.getDescription(), ex.getMessage() ); + AssertMo.assertIncludes("method name is in error message", "methodC", ex.getMessage()); + AssertMo.assertIncludes("argument is in error message (1)", methodCArgs[0], ex.getMessage()); + AssertMo.assertIncludes("argument is in error message (2)", methodCArgs[1], ex.getMessage()); + + AssertMo.assertIncludes("shows set contents (A)", methodA.getDescription(), ex.getMessage()); + AssertMo.assertIncludes("shows set contents (B)", methodB.getDescription(), ex.getMessage()); + return; } - + fail("Should fail for a missing item"); } - public void testCallFailsOnEmptySet() throws Throwable { + public void testVerifiesIfAllContainedElementsVerify() + throws Throwable { + methodA.setExpectedVerifyCalls(1); + methodB.setExpectedVerifyCalls(1); + + callSet.add(methodA); + callSet.add(methodB); + callSet.verify(); + + methodA.verifyExpectations(); + methodB.verifyExpectations(); + } + + public void testVerifyFailsIfContainedElementDoesNotVerify() + throws Exception { + methodA.setExpectedVerifyCalls(1); + methodA.setupVerifyThrow(new AssertionFailedError("verify failed")); + callSet.add(methodA); + try { - callSet.call( unusedMock, "methodC", new Object[] { "arg1", "arg2" } ); + callSet.verify(); } catch (AssertionFailedError ex) { - AssertMo.assertIncludes( "reports empty set in error message", - "no methods", ex.getMessage() ); + methodA.verifyExpectations(); + return; } - - fail("Should fail for a missing item"); - } + fail("Should have got a failure for contained element failing"); + } } |
From: Tim M. <ma...@us...> - 2003-04-14 08:46:33
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv14578/src/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServletTest.java SimpleServlet.java Log Message: Made CallSet a composite of Mock (with CallableAddable interface) made tests that were tricky much simpler, and first step to CallList Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- SimpleServletTest.java 11 Apr 2003 15:38:19 -0000 1.1.2.5 +++ SimpleServletTest.java 14 Apr 2003 08:46:29 -0000 1.1.2.6 @@ -59,12 +59,12 @@ mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("subject")), "Mail Subject" ); mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), "Mail Body" ); - final StringWriter contentWriter = new StringWriter(); + final PrintWriter contentWriter = new PrintWriter(new StringWriter()); - mockHttpServletResponse.expect( "setContentType", C.args(C.eq("text/html")) ); + mockHttpServletResponse.expect( "setContentType", "text/html"); mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); -// CallMatch m1 = mockHttpServletResponse.expect( "setContentType", C.args(C.eq("text/html")) ); +// CallMatch m1 = mockHttpServletResponse.expect( "setContentType", "text/html"); // CallMatch m2 = mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); // m1.expectBefore(m2); Index: SimpleServlet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServlet.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- SimpleServlet.java 7 Apr 2003 17:38:28 -0000 1.1.2.3 +++ SimpleServlet.java 14 Apr 2003 08:46:29 -0000 1.1.2.4 @@ -16,12 +16,15 @@ public class SimpleServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - //super.doGet(arg0, arg1); - + String body = request.getParameter("body"); String subject = request.getParameter("subject"); + String subjectCopy = request.getParameter("subject"); String browser = request.getParameter("browser-identifier"); - String pet = request.getParameter("favourite-pet"); + //String pet = request.getParameter("favourite-pet"); + + response.setContentType("text/html"); + Writer writer = response.getWriter(); } } |
From: Tim M. <ma...@us...> - 2003-04-14 08:46:33
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv14578/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSet.java Mock.java Callable.java Added Files: Tag: DynamicMockExperiment CallableAddable.java Log Message: Made CallSet a composite of Mock (with CallableAddable interface) made tests that were tricky much simpler, and first step to CallList --- NEW FILE: CallableAddable.java --- /* * Created on 14-Apr-2003 */ package com.mockobjects.dynamic; public interface CallableAddable extends Callable { public abstract void add(Callable call); } Index: CallSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSet.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- CallSet.java 11 Apr 2003 15:38:18 -0000 1.1.2.6 +++ CallSet.java 14 Apr 2003 08:46:25 -0000 1.1.2.7 @@ -10,97 +10,64 @@ import junit.framework.*; + /** * @author dev */ -public class CallSet implements Callable { +public class CallSet implements Callable, CallableAddable { private List expectedCalls = new ArrayList(); - private CallFactory callFactory; - - + public CallSet() { - this( new DefaultCallFactory() ); - } - - public CallSet( CallFactory callFactory ) { - this.callFactory = callFactory; } - public Object call(Mock mock, String methodName, Object[] args) throws Throwable { + public Object call(Mock mock, String methodName, Object[] args) + throws Throwable { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { - Callable element = (Callable) call.next(); - if(element.matches(methodName, args)) { + Callable element = (Callable)call.next(); + + if (element.matches(methodName, args)) { return element.call(mock, methodName, args); } } - + StringBuffer buf = new StringBuffer(); buf.append("Unexpected call to "); - buf.append( AssertMo.methodToString( methodName, args ) ); - buf.append( "\n" ); - buf.append( "Expected " ); - buf.append( getDescription() ); - throw new AssertionFailedError( buf.toString() ); + buf.append(AssertMo.methodToString(methodName, args)); + buf.append("\n"); + buf.append("Expected "); + buf.append(getDescription()); + throw new AssertionFailedError(buf.toString()); } - + public String getDescription() { - if( expectedCalls.isEmpty() ) { + if (expectedCalls.isEmpty()) { return "no methods"; } else { StringBuffer buf = new StringBuffer(); - - buf.append( "one of:\n" ); - for( Iterator i = expectedCalls.iterator(); i.hasNext(); ) { - buf.append( ((Callable)i.next()).getDescription() ); - buf.append( "\n" ); + + buf.append("one of:\n"); + + for (Iterator i = expectedCalls.iterator(); i.hasNext();) { + buf.append(((Callable)i.next()).getDescription()); + buf.append("\n"); } - - return buf.toString(); + + return buf.toString(); } } - - public void expect( String methodName, Constraint[] args) { - add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createVoidStub()))); - } - - public void expectAndReturn( String methodName, Object equalArg, Object result ) { - expectAndReturn(methodName, C.args(C.eq(equalArg)), result); - } - public void expectAndReturn( String methodName, Constraint[] args, Object result ) { - add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createReturnStub(result)))); - } - - public void expectAndThrow( String methodName, Constraint[] args, Throwable exception ) { - add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(exception)))); + public boolean matches(String methodName, Object[] args) { + throw new Error("not implemented"); } + public void verify() { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { - Callable element = (Callable) call.next(); + Callable element = (Callable)call.next(); element.verify(); } - } public void add(Callable call) { expectedCalls.add(call); - } - - public void matchAndReturn( String methodName, Object equalArg, Object result ) { - matchAndReturn(methodName, C.args(C.eq(equalArg)), result); - } - - public void matchAndReturn( String methodName, Constraint[] args, Object result ) { - add( callFactory.createCallMatch( methodName, args, - callFactory.createReturnStub(result) ) ); - } - - public void matchAndThrow( String methodName, Constraint[] args, Throwable throwable ) { - add( callFactory.createCallMatch( methodName, args, - callFactory.createThrowStub(throwable) ) ); - } - - public boolean matches(String methodName, Object[] args) { - throw new Error("not implemented"); } } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.2 retrieving revision 1.16.2.3 diff -u -r1.16.2.2 -r1.16.2.3 --- Mock.java 7 Apr 2003 14:26:52 -0000 1.16.2.2 +++ Mock.java 14 Apr 2003 08:46:27 -0000 1.16.2.3 @@ -6,63 +6,100 @@ import java.lang.reflect.*; +import com.mockobjects.constraint.Constraint; + import junit.framework.*; /** * @author dev */ -public class Mock extends CallSet implements InvocationHandler { +public class Mock implements InvocationHandler { private String name; private Object proxy; - - - public Mock( Class mockedClass, String name) { + private CallFactory callFactory; + private CallableAddable callSet; + + public Mock(CallFactory callFactory, CallableAddable callableAddable, Class mockedClass, String name) { this.name = name; - this.proxy = Proxy.newProxyInstance( getClass().getClassLoader(), - new Class[] { mockedClass }, - this ); + this.callFactory = callFactory; + this.callSet = callableAddable; + this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this); } - - public Mock( Class mockedClass ) { - this( mockedClass, mockNameFromClass(mockedClass) ); + + public Mock(Class mockedClass, String name) { + this(new DefaultCallFactory(), new CallSet(), mockedClass, mockNameFromClass(mockedClass)); } - - public static String mockNameFromClass( Class c ) { + + public Mock(Class mockedClass) { + this(mockedClass, mockNameFromClass(mockedClass)); + } + + public static String mockNameFromClass(Class c) { String name = c.getName(); int dotIndex = name.lastIndexOf('.'); - if( dotIndex >= 0 ) { - return "mock" + name.substring(dotIndex + 1 ); + + if (dotIndex >= 0) { + return "mock" + name.substring(dotIndex + 1); } else { return "mock" + name; } } - + public String toString() { return name; } - + public Object proxy() { return proxy; } - public Object invoke( Object proxy, Method method, Object[] args ) - throws Throwable - { + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { try { - return call( this, method.getName(), (args == null ? new Object[0] : args) ); - } - catch( AssertionFailedError ex ) { - throw new AssertionFailedError( name + ": " + ex.getMessage() ); + return callSet.call(this, method.getName(), ((args == null) ? new Object[0] : args)); + } catch (AssertionFailedError ex) { + throw new AssertionFailedError(name + ": " + ex.getMessage()); } } - + public void verify() { try { - super.verify(); - } - catch( AssertionFailedError ex ) { - throw new AssertionFailedError( name + ": " + ex.getMessage() ); + callSet.verify(); + } catch (AssertionFailedError ex) { + throw new AssertionFailedError(name + ": " + ex.getMessage()); } + } + + public void expect(String methodName, Object equalArg) { + expect(methodName, C.args(C.eq(equalArg))); + } + + public void expect(String methodName, Constraint[] args) { + callSet.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createVoidStub()))); + } + + public void expectAndReturn(String methodName, Object equalArg, Object result) { + expectAndReturn(methodName, C.args(C.eq(equalArg)), result); + } + + public void expectAndReturn(String methodName, Constraint[] args, Object result) { + callSet.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result)))); + } + + public void expectAndThrow(String methodName, Constraint[] args, Throwable exception) { + callSet.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(exception)))); + } + + public void matchAndReturn(String methodName, Object equalArg, Object result) { + matchAndReturn(methodName, C.args(C.eq(equalArg)), result); + } + + public void matchAndReturn(String methodName, Constraint[] args, Object result) { + callSet.add(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result))); + } + + public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { + callSet.add(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(throwable))); } } Index: Callable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/Callable.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- Callable.java 11 Apr 2003 13:18:46 -0000 1.1.2.1 +++ Callable.java 14 Apr 2003 08:46:27 -0000 1.1.2.2 @@ -8,7 +8,6 @@ public interface Callable extends Verifiable { String getDescription(); - Object call( Mock mock, String methodName, Object[] args ) throws Throwable; boolean matches(String methodName, Object[] args); |
From: Griffin C. <gri...@ya...> - 2003-04-14 00:35:39
|
Hello all! This is a announcement of the new DotNetMock has been released, version 0.4. Below is the change log: MockObject.cs - Marked Fail(), AssertTrue(), AssertEquals() Obsolete MockObject.cs - Added MockName Property for name variable MockObject.cs - Changed to implement IMockObject interface NullObject.cs - Added Name property for name variable IMockObject.cs - Added IMockObject interface for custom MockObjects MockDataReader.cs - Fixed indexing bug MockDataParameterCollection - Fixed Verify() bug AbstractExpectationCollection.cs - Fixed ClearActual() bug. was really ClearExpected() MockDbConnection.cs - State, ConnectionTimeout, & Command setups were fixed MockXPathNodeIterator.cs - Added XPathNodeIterator MockXPathDocument.cs - Added XPathDocument MockXPathNodeIterator.cs - Added XPathNodeIterator IMockObject.cs - Changed className to methodName in NotImplemented() MockXPathNavigator.cs - Added XPathNavigator Added VisualStudioTemplates for C# MockDataParameterCollection.cs - Changed Verify() method to not fail for no expected parameters. ExpectationCounter.cs - Changed Verify() method to only Verify if the object HasExpectations Plus other minor fixes.... Check it out if you get a chance and throw some feedback my way if you get a chance. Thanks, Griffin ===== Griffin Caprio "Your child against mine. The winner will be hailed, the loser will be booed until my throat hurts!" - Homer Simpson to Marge __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com |
From: Tim M. <ma...@us...> - 2003-04-11 15:38:55
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv805/src/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServletTest.java Log Message: expect and VoidReturnStub Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- SimpleServletTest.java 10 Apr 2003 21:27:06 -0000 1.1.2.4 +++ SimpleServletTest.java 11 Apr 2003 15:38:19 -0000 1.1.2.5 @@ -27,33 +27,33 @@ public SimpleServletTest(String name) { super(name); } - -// public void testDoGet() throws ServletException, IOException { -// Mock mockHttpServletResponse = new Mock(HttpServletResponse.class); -// Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); -// -// //CallSequence calls = new CallSequence(); -// //calls.add("getParameter", "body", "this is the body"); -// //calls.add("getParameter", "subject", "mail from tim"); -// //calls.add("getParameterValues", "recipients", new String[] {"na...@te...", "st...@mp..."} ); -// -// CallSequence params = new CallSequence(); -// params.expectAndReturn( new Constraint[] { C.eq("body") }, "this is the body" ); -// params.expectAndReturn( new Constraint[] { C.eq("subject") }, "mail from tim" ); -// params.expectAndReturn( new Constraint[] { C.eq("recipients") }, new String[] { "nat...@b1...", "st...@m3..." } ); -// -// mockHttpServletRequest.expect( "getParameter", params ); -// -// SimpleServlet aServlet = new SimpleServlet(); -// aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); -// -// mockHttpServletRequest.verify(); -// mockHttpServletResponse.verify(); -// } - +/* + public void testDoGetOldStyle() throws ServletException, IOException { + Mock mockHttpServletResponse = new Mock(HttpServletResponse.class); + Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); + + CallSequence calls = new CallSequence(); + calls.add("getParameter", "body", "this is the body"); + calls.add("getParameter", "subject", "mail from tim"); + calls.add("getParameterValues", "recipients", new String[] {"na...@te...", "st...@mp..."} ); + + CallSequence params = new CallSequence(); + params.expectAndReturn( new Constraint[] { C.eq("body") }, "this is the body" ); + params.expectAndReturn( new Constraint[] { C.eq("subject") }, "mail from tim" ); + params.expectAndReturn( new Constraint[] { C.eq("recipients") }, new String[] { "nat...@b1...", "st...@m3..." } ); + + mockHttpServletRequest.expect( "getParameter", params ); + + SimpleServlet aServlet = new SimpleServlet(); + aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); + + mockHttpServletRequest.verify(); + mockHttpServletResponse.verify(); + } +*/ public void testDoGetNew() throws ServletException, IOException { Mock mockHttpServletResponse = new Mock(HttpServletResponse.class, "response"); - Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); + Mock mockHttpServletRequest = new OrderedMock(HttpServletRequest.class); mockHttpServletRequest.matchAndReturn( "getParameter", C.args(C.eq("browser-identifier")), "MSIE-5.0" ); mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("subject")), "Mail Subject" ); @@ -61,9 +61,12 @@ final StringWriter contentWriter = new StringWriter(); -// CallSequence seq = mockHttpServletResponse.expectSequence(); -// seq.expectVoid( "setContentType", C.args(C.eq("text/html")) ); -// seq.expectAndReturn( "getWriter", C.args(), contentWriter ); + mockHttpServletResponse.expect( "setContentType", C.args(C.eq("text/html")) ); + mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); + +// CallMatch m1 = mockHttpServletResponse.expect( "setContentType", C.args(C.eq("text/html")) ); +// CallMatch m2 = mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); +// m1.expectBefore(m2); SimpleServlet aServlet = new SimpleServlet(); aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv805/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSet.java DefaultCallFactory.java CallFactory.java ExpectedCall.java Added Files: Tag: DynamicMockExperiment VoidStub.java Log Message: expect and VoidReturnStub --- NEW FILE: VoidStub.java --- /* * Created on 11-Apr-2003 */ package com.mockobjects.dynamic; public class VoidStub extends CallStub { public String getDescription() { return "returns <void>"; } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { return null; } } Index: CallSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSet.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- CallSet.java 11 Apr 2003 13:18:43 -0000 1.1.2.5 +++ CallSet.java 11 Apr 2003 15:38:18 -0000 1.1.2.6 @@ -59,6 +59,21 @@ } } + public void expect( String methodName, Constraint[] args) { + add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createVoidStub()))); + } + + public void expectAndReturn( String methodName, Object equalArg, Object result ) { + expectAndReturn(methodName, C.args(C.eq(equalArg)), result); + } + + public void expectAndReturn( String methodName, Constraint[] args, Object result ) { + add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createReturnStub(result)))); + } + + public void expectAndThrow( String methodName, Constraint[] args, Throwable exception ) { + add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(exception)))); + } public void verify() { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { Callable element = (Callable) call.next(); @@ -83,19 +98,6 @@ public void matchAndThrow( String methodName, Constraint[] args, Throwable throwable ) { add( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(throwable) ) ); - } - - - - public void expectAndReturn( String methodName, Object equalArg, Object result ) { - expectAndReturn(methodName, C.args(C.eq(equalArg)), result); - } - - public void expectAndReturn( String methodName, Constraint[] args, Object result ) { - add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createReturnStub(result)))); - } - public void expectAndThrow( String methodName, Constraint[] args, Throwable exception ) { - add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(exception)))); } public boolean matches(String methodName, Object[] args) { Index: DefaultCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DefaultCallFactory.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- DefaultCallFactory.java 11 Apr 2003 13:18:44 -0000 1.1.2.2 +++ DefaultCallFactory.java 11 Apr 2003 15:38:18 -0000 1.1.2.3 @@ -26,4 +26,8 @@ return new CallMatch( methodName, constraints, call ); } + public Callable createVoidStub() { + return new VoidStub(); + } + } Index: CallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallFactory.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallFactory.java 11 Apr 2003 13:18:45 -0000 1.1.2.2 +++ CallFactory.java 11 Apr 2003 15:38:18 -0000 1.1.2.3 @@ -11,6 +11,7 @@ public interface CallFactory { Callable createReturnStub( Object result ); Callable createThrowStub( Throwable throwable ); + Callable createVoidStub(); Callable createExpectedCall( Callable call ); Callable createCallMatch( String methodName, Constraint[] constraints, Callable call ); } Index: ExpectedCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/ExpectedCall.java,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -u -r1.2.2.3 -r1.2.2.4 --- ExpectedCall.java 11 Apr 2003 13:18:45 -0000 1.2.2.3 +++ ExpectedCall.java 11 Apr 2003 15:38:18 -0000 1.2.2.4 @@ -9,31 +9,31 @@ * @author dev */ public class ExpectedCall implements Callable { - private Callable decorated; + private Callable delegate; private boolean wasCalled = false; - public ExpectedCall( Callable decorated ) { - this.decorated = decorated; + public ExpectedCall( Callable delegate ) { + this.delegate = delegate; } public String getDescription() { - return decorated.getDescription() + " [mandatory]"; + return delegate.getDescription() + " [mandatory]"; } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { wasCalled = true; - return decorated.call( mock, methodName, args ); + return delegate.call( mock, methodName, args ); } public boolean matches(String methodName, Object[] args) { - return decorated.matches( methodName, args ); + return delegate.matches( methodName, args ); } public void verify() { if( !wasCalled ) { - throw new AssertionFailedError( decorated.getDescription() + " was expected but not called" ); + throw new AssertionFailedError( delegate.getDescription() + " was expected but not called" ); } - decorated.verify(); + delegate.verify(); } } |
From: Tim M. <ma...@us...> - 2003-04-11 15:38:27
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv805/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment MockCallFactory.java CallSetTest.java Log Message: expect and VoidReturnStub Index: MockCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockCallFactory.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- MockCallFactory.java 11 Apr 2003 13:21:16 -0000 1.1.2.2 +++ MockCallFactory.java 11 Apr 2003 15:38:20 -0000 1.1.2.3 @@ -5,13 +5,15 @@ import com.mockobjects.dynamic.Callable; import com.mockobjects.constraint.Constraint; -public class MockCallFactory implements CallFactory{ +public class MockCallFactory implements CallFactory, Verifiable { private ExpectationCounter myCreateReturnStubCalls = new ExpectationCounter("MockCallFactory.createReturnStub(Object)"); private ReturnValues myActualCreateReturnStubReturnValues = new ReturnValues("MockCallFactory.createReturnStub(Object)", true); private ExpectationList myCreateReturnStubParameter0Values = new ExpectationList("MockCallFactory.createReturnStub(Object) java.lang.Object"); 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 myCreateVoidStubCalls = new ExpectationCounter("MockCallFactory.createVoidStub()"); + private ReturnValues myActualCreateVoidStubReturnValues = new ReturnValues("MockCallFactory.createVoidStub()", true); 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"); @@ -71,6 +73,26 @@ myActualCreateThrowStubReturnValues.add(arg); } + public void setExpectedCreateVoidStubCalls(int calls){ + myCreateVoidStubCalls.setExpected(calls); + } + + public Callable createVoidStub(){ + myCreateVoidStubCalls.inc(); + Object nextReturnValue = myActualCreateVoidStubReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (Callable) nextReturnValue; + } + + public void setupExceptionCreateVoidStub(Throwable arg){ + myActualCreateVoidStubReturnValues.add(new ExceptionalReturnValue(arg)); + } + + public void setupCreateVoidStub(Callable arg){ + myActualCreateVoidStubReturnValues.add(arg); + } + public void setExpectedCreateExpectedCallCalls(int calls){ myCreateExpectedCallCalls.setExpected(calls); } @@ -130,6 +152,7 @@ myCreateReturnStubParameter0Values.verify(); myCreateThrowStubCalls.verify(); myCreateThrowStubParameter0Values.verify(); + myCreateVoidStubCalls.verify(); myCreateExpectedCallCalls.verify(); myCreateExpectedCallParameter0Values.verify(); myCreateCallMatchCalls.verify(); Index: CallSetTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSetTest.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- CallSetTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.5 +++ CallSetTest.java 11 Apr 2003 15:38:21 -0000 1.1.2.6 @@ -19,6 +19,7 @@ private MockCallable mockCallMatch = new MockCallable(); private MockCallable mockExpectedCall = new MockCallable(); private MockCallable mockThrowStub = new MockCallable(); + private MockCallable mockVoidStub = new MockCallable(); private Mock unusedMock = null; private MockCallable methodA = new MockCallable(); @@ -68,22 +69,41 @@ methodB.verifyExpectations(); } - public void testExpectAndReturn() throws Throwable{ + public void testExpect() throws Throwable{ mockExpectedCall.setupMatchesReturn(true); mockExpectedCall.setupCallReturn(METHOD_A_RESULT); - mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); - mockCallFactory.setupCreateReturnStub( mockReturnStub ); - mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockReturnStub ); + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub( mockVoidStub ); + mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockVoidStub ); mockCallFactory.setupCreateCallMatch( mockCallMatch ); mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); - callSet.expectAndReturn( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_RESULT ); + callSet.expect( METHOD_A_NAME, METHOD_A_CONSTRAINTS ); assertSame( "should be result of calling expected call", METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); + Verifier.verifyObject(this); + } + + public void testExpectAndReturn() throws Throwable{ + mockExpectedCall.setupMatchesReturn(true); + mockExpectedCall.setupCallReturn(METHOD_A_RESULT); + + mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); + mockCallFactory.setupCreateReturnStub( mockReturnStub ); + mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockReturnStub ); + mockCallFactory.setupCreateCallMatch( mockCallMatch ); + mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); + mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); + + callSet.expectAndReturn( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_RESULT ); + + assertSame( "should be result of calling expected call", + METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); + Verifier.verifyObject(this); } |
From: Tim M. <ma...@us...> - 2003-04-11 13:21:21
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv21961/src/core/test/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment ConstraintsTest.java Log Message: Test updates for CallSet rename and expectAndReturn modification Index: ConstraintsTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint/ConstraintsTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- ConstraintsTest.java 7 Apr 2003 14:26:56 -0000 1.1.2.1 +++ ConstraintsTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.2 @@ -8,10 +8,9 @@ import java.util.EventObject; +import junit.framework.*; - -public class ConstraintsTest - extends junit.framework.TestCase +public class ConstraintsTest extends TestCase { class True implements Constraint { public boolean eval( Object o ) { return true; } @@ -52,6 +51,12 @@ assertTrue( p.eval( new Integer(1) ) ); assertTrue( !p.eval(i2) ); } + + public void testIsEqualEquals() throws Exception { + assertEquals("Should be equal", new IsEqual("a"), new IsEqual("a")); + assertFalse("Should not be equal - same type", new IsEqual("a").equals(new IsEqual("b"))); + assertFalse("Should not be equal - different type", new IsEqual("a").equals("b")); + } public void testIsGreaterThan() { Constraint p = new IsGreaterThan( new Integer(1) ); |
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 --- |
From: Tim M. <ma...@us...> - 2003-04-11 13:20:25
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory sc8-pr-cvs1:/tmp/cvs-serv21071/src/core/com/mockobjects Added Files: Tag: DynamicMockExperiment VoidReturnValues.java ExceptionalReturnValue.java ReturnValues.java Log Message: Added the mockmaker returnValue classes that really are primitives that should have been in the library anyway (they possibly duplicate some objects we have - this should be resolved with them) --- NEW FILE: VoidReturnValues.java --- package com.mockobjects; /** * Sequence of void values as required by MockMaker * This is a generic class that should have been introduced to the mockobjects code stream instead of * being separately included in org.mockobjects. * It is possibly similar to a ReturnObjectList? */ public class VoidReturnValues extends ReturnValues { public VoidReturnValues() { } public VoidReturnValues(String name, boolean keepUsingLastReturnValue) { super(name, keepUsingLastReturnValue); } public VoidReturnValues(boolean keepUsingLastReturnValue) { super(keepUsingLastReturnValue); } public Object getNext() { return myContents.isEmpty() ? null : pop(); } } --- NEW FILE: ExceptionalReturnValue.java --- package com.mockobjects; /** * Sequence of exception values as required by MockMaker * This is a generic class that should have been introduced to the mockobjects code stream instead of * being separately included in org.mockobjects. * It is possibly similar to a ReturnObjectList? */ public class ExceptionalReturnValue { private Throwable exception; public ExceptionalReturnValue( Throwable exception ) { this.exception = exception; } public Throwable getException() { return exception; } } --- NEW FILE: ReturnValues.java --- package com.mockobjects; import junit.framework.*; import java.util.*; /** * Sequence values as required by MockMaker * This is a generic class that should have been introduced to the mockobjects code stream instead of * being separately included in org.mockobjects. * It is possibly similar to a ReturnObjectList? */ public class ReturnValues { private String myName; protected Vector myContents = new Vector(); private boolean myKeepUsingLastReturnValue = false; public ReturnValues() { this("Generate me with a useful name!",true); } public ReturnValues(String name, boolean keepUsingLastReturnValue) { myName = name; myKeepUsingLastReturnValue = keepUsingLastReturnValue; } public ReturnValues(boolean keepUsingLastReturnValue) { this("Generate me with a useful name!", keepUsingLastReturnValue); } public void add(Object element){ myContents.addElement(element); } public void addAll(Collection returnValues){ myContents.addAll(returnValues); } public Object getNext() { if (myContents.isEmpty()) { throw new AssertionFailedError(getClass().getName() + "[" + myName + "] was not setup with enough values"); } return pop(); } public boolean isEmpty() { return myContents.size() == 0; } protected Object pop() { Object result = myContents.firstElement(); boolean shouldNotRemoveElement = myContents.size() == 1 && myKeepUsingLastReturnValue; if (!shouldNotRemoveElement) { myContents.removeElementAt(0); } return result; } } |
From: Tim M. <ma...@us...> - 2003-04-11 13:18:54
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv19788/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSet.java DefaultCallFactory.java CallStub.java CallFactory.java ExpectedCall.java CallMatch.java Added Files: Tag: DynamicMockExperiment OrderedMock.java Callable.java Removed Files: Tag: DynamicMockExperiment CallMocker.java Log Message: Renamed CallMocker to Callable - added expectAndReturn(String, Object, Object) --- NEW FILE: OrderedMock.java --- /* * Created on 11-Apr-2003 */ package com.mockobjects.dynamic; /** * @author Administrator */ public class OrderedMock extends Mock { public OrderedMock(Class mockedClass) { super(mockedClass); } public OrderedMock(Class mockedClass, String name) { super(mockedClass, name); } } --- NEW FILE: Callable.java --- /* * Created on 04-Apr-2003 */ package com.mockobjects.dynamic; import com.mockobjects.*; public interface Callable extends Verifiable { String getDescription(); Object call( Mock mock, String methodName, Object[] args ) throws Throwable; boolean matches(String methodName, Object[] args); } Index: CallSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSet.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- CallSet.java 10 Apr 2003 21:24:43 -0000 1.1.2.4 +++ CallSet.java 11 Apr 2003 13:18:43 -0000 1.1.2.5 @@ -13,7 +13,7 @@ /** * @author dev */ -public class CallSet implements CallMocker { +public class CallSet implements Callable { private List expectedCalls = new ArrayList(); private CallFactory callFactory; @@ -28,7 +28,7 @@ public Object call(Mock mock, String methodName, Object[] args) throws Throwable { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { - CallMocker element = (CallMocker) call.next(); + Callable element = (Callable) call.next(); if(element.matches(methodName, args)) { return element.call(mock, methodName, args); } @@ -51,7 +51,7 @@ buf.append( "one of:\n" ); for( Iterator i = expectedCalls.iterator(); i.hasNext(); ) { - buf.append( ((CallMocker)i.next()).getDescription() ); + buf.append( ((Callable)i.next()).getDescription() ); buf.append( "\n" ); } @@ -61,19 +61,18 @@ public void verify() { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { - CallMocker element = (CallMocker) call.next(); + Callable element = (Callable) call.next(); element.verify(); } } - public void add(CallMocker call) { + public void add(Callable call) { expectedCalls.add(call); } public void matchAndReturn( String methodName, Object equalArg, Object result ) { - add( callFactory.createCallMatch( methodName, C.args(C.eq(equalArg)), - callFactory.createReturnStub(result) ) ); + matchAndReturn(methodName, C.args(C.eq(equalArg)), result); } public void matchAndReturn( String methodName, Constraint[] args, Object result ) { @@ -86,10 +85,15 @@ callFactory.createThrowStub(throwable) ) ); } + + + public void expectAndReturn( String methodName, Object equalArg, Object result ) { + expectAndReturn(methodName, C.args(C.eq(equalArg)), result); + } + public void expectAndReturn( String methodName, Constraint[] args, Object result ) { add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createReturnStub(result)))); } - public void expectAndThrow( String methodName, Constraint[] args, Throwable exception ) { add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(exception)))); } Index: DefaultCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DefaultCallFactory.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DefaultCallFactory.java 7 Apr 2003 17:38:22 -0000 1.1.2.1 +++ DefaultCallFactory.java 11 Apr 2003 13:18:44 -0000 1.1.2.2 @@ -10,19 +10,19 @@ */ public class DefaultCallFactory implements CallFactory { - public CallMocker createReturnStub(Object result) { + public Callable createReturnStub(Object result) { return new ReturnStub(result); } - public CallMocker createThrowStub( Throwable exception ) { + public Callable createThrowStub( Throwable exception ) { return new ThrowStub(exception); } - public CallMocker createExpectedCall(CallMocker call) { + public Callable createExpectedCall(Callable call) { return new ExpectedCall(call); } - public CallMocker createCallMatch(String methodName, Constraint[] constraints, CallMocker call) { + public Callable createCallMatch(String methodName, Constraint[] constraints, Callable call) { return new CallMatch( methodName, constraints, call ); } Index: CallStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallStub.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallStub.java 7 Apr 2003 14:26:54 -0000 1.1.2.1 +++ CallStub.java 11 Apr 2003 13:18:44 -0000 1.1.2.2 @@ -7,7 +7,7 @@ * @author dev */ public abstract class CallStub - implements CallMocker + implements Callable { public boolean matches(String methodName, Object[] args) { return true; Index: CallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallFactory.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallFactory.java 7 Apr 2003 17:38:23 -0000 1.1.2.1 +++ CallFactory.java 11 Apr 2003 13:18:45 -0000 1.1.2.2 @@ -9,8 +9,8 @@ * @author dev */ public interface CallFactory { - CallMocker createReturnStub( Object result ); - CallMocker createThrowStub( Throwable throwable ); - CallMocker createExpectedCall( CallMocker call ); - CallMocker createCallMatch( String methodName, Constraint[] constraints, CallMocker call ); + Callable createReturnStub( Object result ); + Callable createThrowStub( Throwable throwable ); + Callable createExpectedCall( Callable call ); + Callable createCallMatch( String methodName, Constraint[] constraints, Callable call ); } Index: ExpectedCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/ExpectedCall.java,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -r1.2.2.2 -r1.2.2.3 --- ExpectedCall.java 7 Apr 2003 17:38:22 -0000 1.2.2.2 +++ ExpectedCall.java 11 Apr 2003 13:18:45 -0000 1.2.2.3 @@ -8,11 +8,11 @@ /** * @author dev */ -public class ExpectedCall implements CallMocker { - private CallMocker decorated; +public class ExpectedCall implements Callable { + private Callable decorated; private boolean wasCalled = false; - public ExpectedCall( CallMocker decorated ) { + public ExpectedCall( Callable decorated ) { this.decorated = decorated; } Index: CallMatch.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallMatch.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallMatch.java 7 Apr 2003 17:38:24 -0000 1.1.2.1 +++ CallMatch.java 11 Apr 2003 13:18:46 -0000 1.1.2.2 @@ -8,13 +8,13 @@ import com.mockobjects.constraint.*; import com.mockobjects.util.*; -public class CallMatch extends Assert implements CallMocker +public class CallMatch extends Assert implements Callable { private String methodName; private Constraint[] constraints; - private CallMocker decorated; + private Callable decorated; - public CallMatch( String methodName, Constraint[] constraints, CallMocker decorated ) { + public CallMatch( String methodName, Constraint[] constraints, Callable decorated ) { this.methodName = methodName; this.constraints = (Constraint[])constraints.clone(); this.decorated = decorated; --- CallMocker.java DELETED --- |
From: Tim M. <ma...@us...> - 2003-04-11 13:17:10
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv18515/src/core/com/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment IsLessThan.java IsEqual.java IsGreaterThan.java Log Message: Constraint update - reluctantly had to introduce .equals to test matchOneAndReturn + small comment cleanup Index: IsLessThan.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsLessThan.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- IsLessThan.java 24 Nov 2002 11:20:19 -0000 1.2 +++ IsLessThan.java 11 Apr 2003 13:17:04 -0000 1.2.2.1 @@ -11,8 +11,6 @@ { private Comparable _object; - /** Creates a new instance of IsLessThan - */ public IsLessThan(Comparable o) { _object = o; } Index: IsEqual.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsEqual.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- IsEqual.java 7 Apr 2003 17:38:50 -0000 1.2.2.1 +++ IsEqual.java 11 Apr 2003 13:17:04 -0000 1.2.2.2 @@ -12,8 +12,6 @@ { private Object _object; - /** Creates a new instance of IsEqual - */ public IsEqual( Object o ) { _object = o; } @@ -24,5 +22,9 @@ public String toString() { return _object.toString(); + } + + public boolean equals(Object anObject) { + return anObject.getClass().equals(this.getClass()) && eval(((IsEqual)anObject)._object); } } Index: IsGreaterThan.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsGreaterThan.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- IsGreaterThan.java 24 Nov 2002 11:20:19 -0000 1.2 +++ IsGreaterThan.java 11 Apr 2003 13:17:04 -0000 1.2.2.1 @@ -5,14 +5,13 @@ package com.mockobjects.constraint; -/** Is the value greater than another {@link java.lang.Comparable} value? +/** + * Is the value greater than another {@link java.lang.Comparable} value? */ public class IsGreaterThan implements Constraint { private Comparable _object; - /** Creates a new instance of IsGreaterThan - */ public IsGreaterThan( Comparable o ) { _object = o; } |
From: Steve F. <sm...@us...> - 2003-04-10 21:27:11
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3721/src/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServletTest.java Log Message: renamed permit to match Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- SimpleServletTest.java 7 Apr 2003 17:38:25 -0000 1.1.2.3 +++ SimpleServletTest.java 10 Apr 2003 21:27:06 -0000 1.1.2.4 @@ -55,7 +55,7 @@ Mock mockHttpServletResponse = new Mock(HttpServletResponse.class, "response"); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); - mockHttpServletRequest.permitAndReturn( "getParameter", C.args(C.eq("browser-identifier")), "MSIE-5.0" ); + mockHttpServletRequest.matchAndReturn( "getParameter", C.args(C.eq("browser-identifier")), "MSIE-5.0" ); mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("subject")), "Mail Subject" ); mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), "Mail Body" ); |
From: Steve F. <sm...@us...> - 2003-04-10 21:26:40
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3376/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment DummyInterface.java Log Message: added oneArgMethod Index: DummyInterface.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/DummyInterface.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DummyInterface.java 7 Apr 2003 14:27:00 -0000 1.1.2.1 +++ DummyInterface.java 10 Apr 2003 21:26:36 -0000 1.1.2.2 @@ -8,6 +8,7 @@ */ public interface DummyInterface { public String aMethod( String arg1, String arg2 ) throws Throwable; + public String oneArgMethod( Object o); public void aMethodWithNoArguments(); } |
From: Steve F. <sm...@us...> - 2003-04-10 21:26:14
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3069/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSetTest.java Log Message: renamed constant values Added test for matchOneArgument Index: CallSetTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSetTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- CallSetTest.java 7 Apr 2003 17:38:49 -0000 1.1.2.3 +++ CallSetTest.java 10 Apr 2003 21:26:09 -0000 1.1.2.4 @@ -23,15 +23,15 @@ private Mock unusedMock = null; private MockCallMocker methodA = new MockCallMocker(); private MockCallMocker methodB = new MockCallMocker(); - final String methodAName = "methodA"; - final String[] methodAArgs = new String[] { "a1", "a2" }; - final Constraint[] methodAConstraints = C.args( C.eq("a1"), C.eq("a2") ); - final String methodAResult = "resultA"; - final Throwable methodAException = new DummyThrowable("Configured test throwable"); - - final String methodBName = "methodB"; - final String[] methodBArgs = new String[] { "b1", "b2" }; - final String methodBResult = "resultB"; + 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") ); + final String METHOD_A_RESULT = "resultA"; + final Throwable METHOD_A_EXCEPTION = new DummyThrowable("Configured test throwable"); + + final String METHOD_B_NAME = "methodB"; + final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; + final String METHOD_B_RESULT = "resultB"; public CallSetTest(String name) { @@ -70,55 +70,73 @@ public void testExpectAndReturn() throws Throwable{ mockExpectedCall.setupMatchesReturn(true); - mockExpectedCall.setupCallReturn(methodAResult); + mockExpectedCall.setupCallReturn(METHOD_A_RESULT); - mockCallFactory.addExpectedCreateReturnStub( methodAResult ); + mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); mockCallFactory.setupCreateReturnStub( mockReturnStub ); - mockCallFactory.addExpectedCreateCallMatch( methodAName, methodAConstraints, mockReturnStub ); + mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockReturnStub ); mockCallFactory.setupCreateCallMatch( mockCallMatch ); mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); - callSet.expectAndReturn( methodAName, methodAConstraints, methodAResult ); + callSet.expectAndReturn( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_RESULT ); assertSame( "should be result of calling expected call", - methodAResult, callSet.call( unusedMock, methodAName, methodAArgs ) ); + METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); Verifier.verifyObject(this); } public void testPermitAndReturn() throws Throwable{ mockCallMatch.setupMatchesReturn(true); - mockCallMatch.setupCallReturn(methodAResult); + mockCallMatch.setupCallReturn(METHOD_A_RESULT); - mockCallFactory.addExpectedCreateReturnStub( methodAResult ); + mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); mockCallFactory.setupCreateReturnStub( mockReturnStub ); - mockCallFactory.addExpectedCreateCallMatch( methodAName, methodAConstraints, mockReturnStub ); + mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockReturnStub ); mockCallFactory.setupCreateCallMatch( mockCallMatch ); - callSet.permitAndReturn( methodAName, methodAConstraints, methodAResult ); + callSet.matchAndReturn( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_RESULT ); assertSame( "should be result of calling expected call", - methodAResult, callSet.call( unusedMock, methodAName, methodAArgs ) ); + METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); Verifier.verifyObject(this); } + public void testPermitOneAndReturn() throws Throwable{ + final String PARAMETER = "One Arg Method"; + mockCallMatch.setupMatchesReturn(true); + mockCallMatch.setupCallReturn(METHOD_A_RESULT); + + mockCallFactory.addExpectedCreateReturnStub( METHOD_A_RESULT ); + mockCallFactory.setupCreateReturnStub( mockReturnStub ); + mockCallFactory.addExpectedCreateCallMatch( "oneArgMethod", C.args(C.eq(PARAMETER)), mockReturnStub ); + mockCallFactory.setupCreateCallMatch( mockCallMatch ); + + callSet.matchAndReturn( "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); - mockExpectedCall.setupCallThrow(methodAException); + mockExpectedCall.setupCallThrow(METHOD_A_EXCEPTION); - mockCallFactory.addExpectedCreateThrowStub(methodAException); + mockCallFactory.addExpectedCreateThrowStub(METHOD_A_EXCEPTION); mockCallFactory.setupCreateThrowStub( mockThrowStub ); - mockCallFactory.addExpectedCreateCallMatch( methodAName, methodAConstraints, mockThrowStub ); + mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockThrowStub ); mockCallFactory.setupCreateCallMatch( mockCallMatch ); mockCallFactory.addExpectedCreateExpectedCall( mockCallMatch ); mockCallFactory.setupCreateExpectedCall( mockExpectedCall ); - callSet.expectAndThrow( methodAName, methodAConstraints, methodAException ); + callSet.expectAndThrow( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_EXCEPTION ); try { - callSet.call( unusedMock, methodAName, methodAArgs ); + callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ); } catch (DummyThrowable ex) { Verifier.verifyObject(this); return; @@ -129,17 +147,17 @@ public void testPermitAndThrow() throws Throwable{ mockCallMatch.setupMatchesReturn(true); - mockCallMatch.setupCallThrow(methodAException); + mockCallMatch.setupCallThrow(METHOD_A_EXCEPTION); - mockCallFactory.addExpectedCreateThrowStub(methodAException); + mockCallFactory.addExpectedCreateThrowStub(METHOD_A_EXCEPTION); mockCallFactory.setupCreateThrowStub( mockThrowStub ); - mockCallFactory.addExpectedCreateCallMatch( methodAName, methodAConstraints, mockThrowStub ); + mockCallFactory.addExpectedCreateCallMatch( METHOD_A_NAME, METHOD_A_CONSTRAINTS, mockThrowStub ); mockCallFactory.setupCreateCallMatch( mockCallMatch ); - callSet.permitAndThrow( methodAName, methodAConstraints, methodAException ); + callSet.matchAndThrow( METHOD_A_NAME, METHOD_A_CONSTRAINTS, METHOD_A_EXCEPTION ); try { - callSet.call( unusedMock, methodAName, methodAArgs ); + callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ); } catch (DummyThrowable ex) { Verifier.verifyObject(this); return; @@ -149,10 +167,10 @@ } public void testCallPassedToContainedElements() throws Throwable { - methodA.setExpectedMatches( methodAName, methodAArgs ); + methodA.setExpectedMatches( METHOD_A_NAME, METHOD_A_ARGS ); methodA.setupMatchesReturn(true); - methodA.setExpectedCall( unusedMock, methodAName, methodAArgs ); - methodA.setupCallReturn(methodAResult); + methodA.setExpectedCall( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ); + methodA.setupCallReturn(METHOD_A_RESULT); methodB.setExpectedCallCount( 0 ); @@ -160,27 +178,27 @@ callSet.add( methodB ); assertSame( "expected result from method A", - methodAResult, callSet.call( unusedMock, methodAName, methodAArgs ) ); + METHOD_A_RESULT, callSet.call( unusedMock, METHOD_A_NAME, METHOD_A_ARGS ) ); methodA.verifyExpectations(); methodB.verifyExpectations(); } public void testCallPassedToContainedElementsOtherOrder() throws Throwable { - methodA.setExpectedMatches( methodBName, methodBArgs ); + methodA.setExpectedMatches( METHOD_B_NAME, METHOD_B_ARGS ); methodA.setupMatchesReturn(false); methodA.setExpectedCallCount( 0 ); - methodB.setExpectedCall( unusedMock, methodBName, methodBArgs ); + methodB.setExpectedCall( unusedMock, METHOD_B_NAME, METHOD_B_ARGS ); - methodB.setupCallReturn(methodBResult); - methodB.setExpectedMatches( methodBName, methodBArgs ); + methodB.setupCallReturn(METHOD_B_RESULT); + methodB.setExpectedMatches( METHOD_B_NAME, METHOD_B_ARGS ); methodB.setupMatchesReturn(true); callSet.add( methodA ); callSet.add( methodB ); assertSame( "expected result from method B", - methodBResult, callSet.call( unusedMock, methodBName, methodBArgs ) ); + METHOD_B_RESULT, callSet.call( unusedMock, METHOD_B_NAME, METHOD_B_ARGS ) ); methodA.verifyExpectations(); methodB.verifyExpectations(); |
From: Steve F. <sm...@us...> - 2003-04-10 21:24:48
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv1948/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSet.java Log Message: Changed permitAndReturn to matchAndReturn Index: CallSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSet.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- CallSet.java 7 Apr 2003 17:38:23 -0000 1.1.2.3 +++ CallSet.java 10 Apr 2003 21:24:43 -0000 1.1.2.4 @@ -71,12 +71,17 @@ expectedCalls.add(call); } - public void permitAndReturn( String methodName, Constraint[] args, Object result ) { + public void matchAndReturn( String methodName, Object equalArg, Object result ) { + add( callFactory.createCallMatch( methodName, C.args(C.eq(equalArg)), + callFactory.createReturnStub(result) ) ); + } + + public void matchAndReturn( String methodName, Constraint[] args, Object result ) { add( callFactory.createCallMatch( methodName, args, callFactory.createReturnStub(result) ) ); } - public void permitAndThrow( String methodName, Constraint[] args, Throwable throwable ) { + public void matchAndThrow( String methodName, Constraint[] args, Throwable throwable ) { add( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(throwable) ) ); } |
From: Steve F. <sm...@us...> - 2003-04-10 20:36:09
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv32671/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment C.java Log Message: Removed eq (Object[]) Added eq(object, object) Index: C.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- C.java 10 Apr 2003 01:04:11 -0000 1.1.2.2 +++ C.java 10 Apr 2003 20:35:59 -0000 1.1.2.3 @@ -30,14 +30,21 @@ return new IsEqual(o); } - public static Constraint[] eq( Object[] o ) { - Constraint[] result = new Constraint[o.length]; - for (int i = 0; i < result.length; i++) { - result[i] = new IsEqual(o[i]); - } + public static Constraint[] eq( Object o0, Object o1 ) { + Constraint[] result = new Constraint[2]; + result[0] = eq(o0); + result[1] = eq(01); return result; } + public static Constraint[] eq( Object o0, Object o1, Object o2 ) { + Constraint[] result = new Constraint[3]; + result[0] = eq(o0); + result[1] = eq(01); + result[2] = eq(02); + return result; + } + public static Constraint eq( int n ) { return new IsEqual( new Integer(n) ); } |
From: Jeff M. <cus...@us...> - 2003-04-10 10:39:16
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv26633/src/j2ee/1.3/com/mockobjects/servlet Modified Files: MockHttpServletRequest.java Log Message: Change servlet paramaters to use ReturnObjectBag Index: MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- MockHttpServletRequest.java 18 Mar 2003 14:28:43 -0000 1.14 +++ MockHttpServletRequest.java 10 Apr 2003 10:39:12 -0000 1.15 @@ -20,8 +20,8 @@ public class MockHttpServletRequest extends MockObject implements HttpServletRequest { - private Dictionary myParameters = new Hashtable(); - private Dictionary myHeaders = new Hashtable(); + private final ReturnObjectBag myParameters = new ReturnObjectBag("parameters"); + private final ReturnObjectBag myHeaders = new ReturnObjectBag("headers"); private final ReturnValue myHttpSession = new ReturnValue("session"); private final ReturnValue myContentTypeToReturn = new ReturnValue("content type"); private final ReturnValue myContextPath = new ReturnValue("context path"); @@ -32,19 +32,21 @@ private final ReturnValue protocol = new ReturnValue("protocol"); private final ReturnValue inputStream = new ReturnValue("input stream"); private final ReturnValue myUserPrincipal = new ReturnValue("user principal"); - private Vector myAttributesNames; + private final ReturnValue myAttributesNames = new ReturnValue("attribute names"); private final ReturnValue queryString = new ReturnValue("query string"); private final ReturnValue scheme = new ReturnValue("scheme"); private final ReturnValue serverName = new ReturnValue("server name"); private final ReturnValue reader = new ReturnValue("reader"); - - private ExpectationSet mySetAttributes = new ExpectationSet("HttpServletRequest.setAttribute"); - private ExpectationSet myRemoveAttributes = new ExpectationSet("HttpServletRequest.removeAttribute"); - private ReturnObjectList myAttributesToReturn = new ReturnObjectList("attributes"); - private ExpectationValue myContentType = new ExpectationValue("content type"); - private ExpectationList myGetAttributeNames = new ExpectationList("get attribute names"); + private final ExpectationSet mySetAttributes = new ExpectationSet("HttpServletRequest.setAttribute"); + private final ExpectationSet myRemoveAttributes = new ExpectationSet("HttpServletRequest.removeAttribute"); + private final ReturnObjectList myAttributesToReturn = new ReturnObjectList("attributes"); + private final ExpectationValue myContentType = new ExpectationValue("content type"); + private final ExpectationList myGetAttributeNames = new ExpectationList("get attribute names"); private final ReturnValue servletPath = new ReturnValue("servlet path"); private final ReturnValue parameterMap = new ReturnValue("parameter map"); + private final ReturnValue myParameterNames = new ReturnValue("parameter names"); + private final ReturnValue requestDispatcher = new ReturnValue("request dispatcher"); + private final ExpectationValue requestDispatcherURI = new ExpectationValue("request dispatcher uri"); public void setupGetAttribute(Object anAttributeToReturn) { myAttributesToReturn.addObjectToReturn(anAttributeToReturn); @@ -59,12 +61,12 @@ return myAttributesToReturn.nextReturnObject(); } - public void setupGetAttrubuteNames(Vector attributeNames) { - myAttributesNames = attributeNames; + public void setupGetAttrubuteNames(Enumeration attributeNames) { + myAttributesNames.setValue(attributeNames); } public Enumeration getAttributeNames() { - return myAttributesNames.elements(); + return (Enumeration) myAttributesNames.getValue(); } public String getAuthType() { @@ -116,8 +118,8 @@ return 0; } - public String getHeader(String arg1) { - return (String) myHeaders.get(arg1); + public String getHeader(String key) { + return (String) myHeaders.getNextReturnObject(key); } public Enumeration getHeaderNames() { @@ -170,12 +172,16 @@ return values[0]; } + public void setupGetParameterNames(Enumeration names) { + this.myParameterNames.setValue(names); + } + public Enumeration getParameterNames() { - return myParameters.keys(); + return (Enumeration) myParameterNames.getValue(); } public String[] getParameterValues(String key) { - return (String[]) myParameters.get(key); + return (String[]) myParameters.getNextReturnObject(key); } public String getPathInfo() { @@ -230,10 +236,17 @@ return null; } - public RequestDispatcher getRequestDispatcher( - String arg1) { - notImplemented(); - return null; + public void setupGetRequestDispatcher(RequestDispatcher requestDispatcher){ + this.requestDispatcher.setValue(requestDispatcher); + } + + public RequestDispatcher getRequestDispatcher(String uri) { + this.requestDispatcherURI.setActual(uri); + return (RequestDispatcher)requestDispatcher.getValue(); + } + + public void setExpectedRequestDispatcherURI(String uri){ + this.requestDispatcherURI.setExpected(uri); } public String getRequestedSessionId() { @@ -340,28 +353,16 @@ new MapEntry(attributeName, attributeValue)); } - public void setNoActualParameters() { - setupNoParameters(); - } - public void setupAddParameter(String paramName, String[] values) { - myParameters.put(paramName, values); + myParameters.putObjectToReturn(paramName, values); } public void setupAddParameter(String paramName, String value) { setupAddParameter(paramName, new String[]{value}); } - public void setupNoParameters() { - myParameters = new Hashtable(); - } - public void setupAddHeader(String headerName, String value) { - myHeaders.put(headerName, value); - } - - public void setupNoHeaders() { - myHeaders = new Hashtable(); + myHeaders.putObjectToReturn(headerName, value); } public void setupPathInfo(String pathInfo) { |
From: Jeff M. <cus...@us...> - 2003-04-10 10:37:42
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql In directory sc8-pr-cvs1:/tmp/cvs-serv25779/src/jdk/common/com/mockobjects/sql Modified Files: MockResultSet.java CommonMockMultiRowResultSet.java Log Message: Provided better error message for out of bounds values for getObject Index: MockResultSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/MockResultSet.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MockResultSet.java 31 Dec 2002 14:44:26 -0000 1.5 +++ MockResultSet.java 10 Apr 2003 10:37:39 -0000 1.6 @@ -25,6 +25,7 @@ private final ExpectationCounter myCloseCalls; protected final ExpectationCounter myNextCalls; + protected final String name; private final ReturnValue myMetaData = new ReturnValue("meta data"); private final ReturnValue myStatement = new ReturnValue("statement"); @@ -33,7 +34,11 @@ this(MockResultSet.class.getName()); } + /** + * @param name Label used to identify mock when it errors + */ public MockResultSet(String name) { + this.name = name; myCloseCalls = new ExpectationCounter(name + ".close"); myNextCalls = new ExpectationCounter(name + ".next"); } Index: CommonMockMultiRowResultSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockMultiRowResultSet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CommonMockMultiRowResultSet.java 9 Dec 2002 18:20:12 -0000 1.3 +++ CommonMockMultiRowResultSet.java 10 Apr 2003 10:37:39 -0000 1.4 @@ -1,5 +1,7 @@ package com.mockobjects.sql; +import com.mockobjects.util.AssertMo; + import java.sql.SQLException; /** @@ -18,6 +20,9 @@ super(); } + /** + * @param name Label used to identify mock when it errors + */ public CommonMockMultiRowResultSet(String name) { super(name); } @@ -36,6 +41,9 @@ public Object getObject(int columnIndex) throws SQLException { throwGetExceptionIfAny(); + if (columnIndex > myRows[myRowOffset].length || columnIndex < 1) { + AssertMo.fail("Column " + columnIndex + " not found in " + name); + } return myRows[myRowOffset][columnIndex - 1]; } |
From: Jeff M. <cus...@us...> - 2003-04-10 10:34:48
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io In directory sc8-pr-cvs1:/tmp/cvs-serv24851/src/jdk/common/com/mockobjects/io Modified Files: MockFile.java Log Message: Implemented getAbsolutePath Index: MockFile.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockFile.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MockFile.java 18 Mar 2003 14:28:45 -0000 1.5 +++ MockFile.java 10 Apr 2003 10:34:44 -0000 1.6 @@ -26,6 +26,7 @@ private final ReturnValue myFilesToReturn = new ReturnValue("files"); private final ReturnValue file = new ReturnValue("real file"); private final ReturnValue myPath = new ReturnValue("path"); + private final ReturnValue absolutePath = new ReturnValue("absolute path"); public void setupGetName(final String name) { this.fileName.setValue(name); @@ -79,9 +80,12 @@ return false; } + public void setupGetAbsolutePath(String absolutePath) { + this.absolutePath.setValue(absolutePath); + } + public String getAbsolutePath() { - notImplemented(); - return null; + return (String)absolutePath.getValue(); } public File getAbsoluteFile() { |