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: Steve F. <sm...@us...> - 2003-04-16 22:17:07
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv24985/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment ExpectedCall.java Log Message: ExpectedCalls are now only valid for one call. After that they will not match. Index: ExpectedCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/ExpectedCall.java,v retrieving revision 1.2.2.5 retrieving revision 1.2.2.6 diff -u -r1.2.2.5 -r1.2.2.6 --- ExpectedCall.java 15 Apr 2003 22:22:59 -0000 1.2.2.5 +++ ExpectedCall.java 16 Apr 2003 22:17:04 -0000 1.2.2.6 @@ -26,7 +26,7 @@ } public boolean matches(String methodName, Object[] args) { - return delegate.matches( methodName, args ); + return (! wasCalled) && delegate.matches( methodName, args ); } public void verify() { |
From: Steve F. <sm...@us...> - 2003-04-16 22:16:28
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv24804/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSetTest.java Log Message: Tidy up Index: CallSetTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSetTest.java,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -u -r1.1.2.8 -r1.1.2.9 --- CallSetTest.java 14 Apr 2003 18:46:54 -0000 1.1.2.8 +++ CallSetTest.java 16 Apr 2003 22:16:25 -0000 1.1.2.9 @@ -18,7 +18,6 @@ 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" }; |
From: Steve F. <sm...@us...> - 2003-04-16 22:16:15
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv24729/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallMatchTest.java Log Message: Tidy up Index: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallMatchTest.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- CallMatchTest.java 16 Apr 2003 16:31:47 -0000 1.1.2.4 +++ CallMatchTest.java 16 Apr 2003 22:16:08 -0000 1.1.2.5 @@ -167,7 +167,6 @@ public void testCallMatchesWithAnyArguments() throws Throwable { String[] args = new String[] {"anyArg" }; - MockConstraint[] constraints = new MockConstraint[0]; mockCallable.setExpectedMatches( METHOD_NAME, args ); mockCallable.setupMatchesReturn(true); |
From: Steve F. <sm...@us...> - 2003-04-16 22:15:51
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv24592/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment Mock.java Log Message: Replaced long with int to avoid downcast exceptions Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.6 retrieving revision 1.16.2.7 diff -u -r1.16.2.6 -r1.16.2.7 --- Mock.java 16 Apr 2003 16:31:43 -0000 1.16.2.6 +++ Mock.java 16 Apr 2003 22:15:47 -0000 1.16.2.7 @@ -114,8 +114,8 @@ this.expectAndReturn(methodName, new Boolean(result)); } - public void expectAndReturn(String methodName, long result) { - this.expectAndReturn(methodName, new Long(result)); + public void expectAndReturn(String methodName, int result) { + this.expectAndReturn(methodName, new Integer(result)); } public void expectAndReturn(String methodName, Object singleEqualArg, Object result) { @@ -126,8 +126,8 @@ 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, Object singleEqualArg, int result) { + this.expectAndReturn(methodName, singleEqualArg, new Integer(result)); } public void expectAndReturn(String methodName, Constraint[] args, Object result) { @@ -138,8 +138,8 @@ 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 expectAndReturn(String methodName, Constraint[] args, int result) { + this.expectAndReturn(methodName, args, new Integer(result)); } public void expectAndThrow(String methodName, Throwable exception) { @@ -162,8 +162,8 @@ this.matchAndReturn(methodName, new Boolean(result)); } - public void matchAndReturn(String methodName, long result) { - this.matchAndReturn(methodName, new Long(result)); + public void matchAndReturn(String methodName, int result) { + this.matchAndReturn(methodName, new Integer(result)); } public void matchAndReturn(String methodName, Object singleEqualArg, Object result) { @@ -174,16 +174,16 @@ 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, int singleEqualArg, Object result) { + this.matchAndReturn(methodName, new Integer(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, Object singleEqualArg, int result) { + this.matchAndReturn(methodName, singleEqualArg, new Integer(result)); } public void matchAndReturn(String methodName, Constraint[] args, Object result) { @@ -194,8 +194,8 @@ 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 matchAndReturn(String methodName, Constraint[] args, int result) { + this.matchAndReturn(methodName, args, new Integer(result)); } public void matchAndThrow(String methodName, Throwable throwable) { @@ -210,8 +210,8 @@ 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, int singleEqualArg, Throwable throwable) { + this.matchAndThrow(methodName,new Integer(singleEqualArg), throwable); } public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { |
From: Steve F. <sm...@us...> - 2003-04-16 22:15:13
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv24343/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSet.java Log Message: Tidied up imports Index: CallSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSet.java,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -u -r1.1.2.8 -r1.1.2.9 --- CallSet.java 16 Apr 2003 16:31:43 -0000 1.1.2.8 +++ CallSet.java 16 Apr 2003 22:15:08 -0000 1.1.2.9 @@ -3,12 +3,11 @@ */ package com.mockobjects.dynamic; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; -import com.mockobjects.constraint.*; -import com.mockobjects.util.*; - -import junit.framework.*; +import junit.framework.AssertionFailedError; /** |
From: Steve F. <sm...@us...> - 2003-04-16 22:14:50
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv24150/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSequence.java Log Message: Tidied up imports Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.4.2.4 retrieving revision 1.4.2.5 diff -u -r1.4.2.4 -r1.4.2.5 --- CallSequence.java 16 Apr 2003 17:20:29 -0000 1.4.2.4 +++ CallSequence.java 16 Apr 2003 22:14:46 -0000 1.4.2.5 @@ -4,12 +4,9 @@ package com.mockobjects.dynamic; import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; import junit.framework.AssertionFailedError; - -import com.mockobjects.util.AssertMo; public class CallSequence implements Callable, CallableAddable { |
From: Vincent M. <vm...@pi...> - 2003-04-16 17:46:35
|
> -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of > Jeff Martin > Sent: 16 April 2003 13:57 > To: MockObjects > Subject: Re: [MO-java-dev] Java Dynamic Mocks - going to Head? > > > > - Jeff, I'd like to pull the alt code out as a separate library. What do > > you think? > > Fine by me, only thing of note is that moving forward I'd like to use > the convension of project-library-version.jar for jars as this fits the > rpm system. > > e.g. mockobjects-core-0.8.jar not mockobjects-0.8-core.jar +10! I have to rename the jars whenever I upload them to the Maven ibiblio repository! (http://www.ibiblio.org/maven/mockobjects/jars/). Thanks -Vincent > > -- > Jeff Martin <je...@mk...> > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Vincent M. <vm...@pi...> - 2003-04-16 17:46:12
|
Hi Tim, I have been using the DynaMocks for a while now on several projects (using CVS builds as there were no releases). I have not been following very closely the changes you brought to the experimental branch. Are the new DynaMocks very different from the other ones? How easy is it for me to migrate? I guess I should take a look but I am very much in a hurry and any help will be greatly appreciated. Maybe some docs about how to use the new dyna mocks, etc? Thanks -Vincent > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of Tim > Mackinnon > Sent: 16 April 2003 10:23 > To: Mockobjects-Java-Dev > Subject: [MO-java-dev] Java Dynamic Mocks - going to Head? > > Guys - > > First of all, sorry for missing Xtc - I've got the dynamic bug and want to > see the library in a state that it can be used in many projects. I think > its > important to convey the power and simplicity of mocks (we all know this, > but > there are so many bad examples out there...). > > Anyway - I tried using the branch in the e2x codebase and as always, on a > real project there are often little subtleties that catch you out. As John > Nolan was around working on his own little pet project we bounced ideas of > each other to get things done. > > Anyway - the library is working out quite well now and we should consider > rolling it in to the head stream soom! (Maybe a day or two more of "in > usage" testing, and comments from anyone else who is interested - but to > be > honest making it available in the head should allow greater changes). > > Here are some points: > > 1) To test the dynamic stuff, we used Traditional Mocks - it became a pain > hand coding them, especially on larger interfaces, so we took the decision > to use MockMaker. This worked well, however their are some ReturnXXX > objects > that it uses that should be in the base library. In the branch I have just > put them in - however they duplicate some existing functionality. I propse > we resolve this duplication in a second pass as it requires updates to > code > that mockmaker generates. Having the additional duplication allows an > exisiting generated mock to be updated by simply removing 3 import lines. > To > get a full solution we need to get all the tools running on a single > platform - and you use the right one for the right job. > > 2) The Callable interface has a "matches" method, this doesn't feel right > for all callables, its required for CallBag to operate - others don't need > it. This should be removed and implemented as a private decoration for > CallBag. > > 3) Steve's exellent suggestion of having: > > Callable c1 = mock.expect("setContentType".....) > Callable c2 = mock.expect("getWriter".....) > c1.expectBefore(c2) > > has not yet been implemented. This should work quite easily, but the focus > has been on UnorderdMock and OrderedMock. > > 4) As you can use mocks as expected values themselves - there was some > ugliness with the proxies needing to detect equality of mocks (you can see > this in the invoke method). I'm not sure if there is a better way to do > this. > > 5) I think Mocks should probably register with something so that we can do > the Verifier.verify on both instance variables and local variables in a > test. I am still seeing lots of accidently unverified mocks > > Overall the sample test case is looking very good (I have included it > again > below). How does everyone feel going ahead with a merge (I can probably > get > Chris Cottee to help me merge it in at e2x)? > > Tim > > public void testDoGetNew() throws ServletException, IOException { > 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", > "subject", "Mail > Subject" ); > // Alternative syntax > mockHttpServletRequest.expectAndReturn( "getParameter", > C.args(C.eq("body")), "Mail Body" ); > > final PrintWriter contentWriter = new PrintWriter(new > StringWriter()); > > mockHttpServletResponse.expect( "setContentType", > "text/html"); > mockHttpServletResponse.expectAndReturn( "getWriter", > contentWriter ); > > // Still to do, instead of making response an OrderedMock > // CallMatch m1 = mockHttpServletResponse.expect( > "setContentType", > "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()); > > mockHttpServletRequest.verify(); > mockHttpServletResponse.verify(); > } > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Tim M. <ma...@us...> - 2003-04-16 17:21:12
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv27819/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSequence.java Log Message: Missing test for call sequence index checking. Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.4.2.3 retrieving revision 1.4.2.4 diff -u -r1.4.2.3 -r1.4.2.4 --- CallSequence.java 16 Apr 2003 16:31:44 -0000 1.4.2.3 +++ CallSequence.java 16 Apr 2003 17:20:29 -0000 1.4.2.4 @@ -41,7 +41,8 @@ } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { - if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods"); + if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(methodName, args)); + if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, recieved: " + DynamicUtil.methodToString(methodName, args)); Callable nextCall = (Callable)expectedCalls.get(callIndex++); if (nextCall.matches(methodName, args)) |
From: Tim M. <ma...@us...> - 2003-04-16 17:20:39
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv27819/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSequenceTest.java Log Message: Missing test for call sequence index checking. Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSequenceTest.java,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -u -r1.5.2.1 -r1.5.2.2 --- CallSequenceTest.java 14 Apr 2003 18:46:55 -0000 1.5.2.1 +++ CallSequenceTest.java 16 Apr 2003 17:20:32 -0000 1.5.2.2 @@ -3,122 +3,147 @@ */ 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; +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + + public class CallSequenceTest extends TestCase { + private static final String MOCK_NAME = "Test mock"; 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 String METHOD_B_RESULT = "resultB"; 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 { + + public CallSequenceTest(String name) { + super(name); + } + + 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 testCallFailsWithTooManyCalls() throws Throwable { + mockCallable.setupMatchesReturn(true); + mockCallable.setupCallReturn(METHOD_A_RESULT); + callSequence.add(mockCallable); + callSequence.call(unusedMock, "willdefinitelyMatch", new Object[0]); + + try { + callSequence.call(unusedMock, "oneMethodTooMany", new Object[0]); + } catch (AssertionFailedError ex) { + AssertMo.assertIncludes("reports one method call too many", "too many", ex.getMessage()); + + return; + } + + fail("Should fail for calling too many times"); + } + 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)); - + + 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) { + 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); @@ -127,56 +152,53 @@ 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); + fail("Should have got a failure for contained element failing"); } - } |
From: Tim M. <ma...@us...> - 2003-04-16 16:32:22
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv6154/core/test/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment ConstraintsTest.java Log Message: Fixed proxy error reporting when used as an expectation Index: ConstraintsTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint/ConstraintsTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- ConstraintsTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.2 +++ ConstraintsTest.java 16 Apr 2003 16:31:48 -0000 1.1.2.3 @@ -5,6 +5,9 @@ package test.mockobjects.constraint; import com.mockobjects.constraint.*; +import com.mockobjects.dynamic.Mock; + +import test.mockobjects.dynamic.DummyInterface; import java.util.EventObject; @@ -50,6 +53,14 @@ assertTrue( p.eval(i1) ); assertTrue( p.eval( new Integer(1) ) ); assertTrue( !p.eval(i2) ); + } + + public void testIsEqualToStringOnProxyArgument() { + // Required for error message reporting + Mock mockDummyInterface = new Mock(DummyInterface.class, "MockName"); + Constraint p = new IsEqual(mockDummyInterface.proxy()); + + assertEquals("Should get resolved toString() with no expectation error", "MockName", p.toString()); } public void testIsEqualEquals() throws Exception { |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6154/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment MockTest.java ExpectedCallTest.java CallMatchTest.java Added Files: Tag: DynamicMockExperiment DynamicUtilTest.java Log Message: Fixed proxy error reporting when used as an expectation --- NEW FILE: DynamicUtilTest.java --- /* * Created on 16-Apr-2003 */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.DynamicUtil; import com.mockobjects.dynamic.Mock; import com.mockobjects.util.AssertMo; import junit.framework.TestCase; /** * @author e2x */ public class DynamicUtilTest extends TestCase { public DynamicUtilTest(String name) { super(name); } public void testMethodToStringWithoutProxyArg() throws Exception { String[] args = new String[] {"arg1", "arg2" }; String result = DynamicUtil.methodToString("methodName", args); AssertMo.assertIncludes("Should contain method name", "methodName", result); AssertMo.assertIncludes("Should contain firstArg", "arg1", result); AssertMo.assertIncludes("Should contain second Arg", "arg2", result); } public void testMethodToStringWithProxyArg() throws Exception { Mock mockDummyInterface = new Mock(DummyInterface.class, "DummyMock"); Object[] args = new Object[] {"arg1", mockDummyInterface.proxy()}; String result = DynamicUtil.methodToString("methodName", args); AssertMo.assertIncludes("Should contain method name", "methodName", result); AssertMo.assertIncludes("Should contain firstArg", "arg1", result); AssertMo.assertIncludes("Should contain second Arg", "DummyMock", result); } } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.6 retrieving revision 1.8.2.7 diff -u -r1.8.2.6 -r1.8.2.7 --- MockTest.java 15 Apr 2003 22:22:56 -0000 1.8.2.6 +++ MockTest.java 16 Apr 2003 16:31:46 -0000 1.8.2.7 @@ -367,12 +367,17 @@ boolean IGNORED_RESULT = true; CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT)); mockCallFactory.setupCreateReturnStub(ret); - mockCallFactory.setupCreateCallMatch(new CallMatch("call",C.ANY_ARGS,ret)); + mockCallFactory.setupCreateCallMatch(new CallMatch("call",C.anyArgs(1),ret)); mockCallableAddable.setupCallReturn(new Boolean(false)); - mock.matchAndReturn("call", C.ANY_ARGS, IGNORED_RESULT); + mock.matchAndReturn("call", C.anyArgs(1), IGNORED_RESULT); assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); Verifier.verifyObject(this); } + + public void testProxygetMockName() throws Exception { + assertEquals("Should get a mock name without touching the underlying mock", MOCK_NAME, DynamicUtil.getProxyName(proxy)); + mock.verify(); // should not fail on a getMockName call + } } Index: ExpectedCallTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/ExpectedCallTest.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- ExpectedCallTest.java 15 Apr 2003 22:22:55 -0000 1.1.2.4 +++ ExpectedCallTest.java 16 Apr 2003 16:31:47 -0000 1.1.2.5 @@ -16,7 +16,7 @@ final String RESULT = "result!"; final String METHOD_NAME = "methodName"; final Object[] ARGS = { "arg1", "arg2" }; - final String DECORATED_DESCRIPTION = AssertMo.methodToString( METHOD_NAME, ARGS ); + final String DECORATED_DESCRIPTION = DynamicUtil.methodToString( METHOD_NAME, ARGS ); Mock ignoredMock = null; MockCallable mockCallable = new MockCallable(); Index: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallMatchTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- CallMatchTest.java 15 Apr 2003 22:22:56 -0000 1.1.2.3 +++ CallMatchTest.java 16 Apr 2003 16:31:47 -0000 1.1.2.4 @@ -125,9 +125,9 @@ AssertMo.assertIncludes("Should show index of failed argument", "1", ex.getMessage() ); AssertMo.assertIncludes("Should show expected arguments", - AssertMo.join(constraints), ex.getMessage()); + DynamicUtil.join(constraints), ex.getMessage()); AssertMo.assertIncludes("Should show actual arguments", - AssertMo.join(args), ex.getMessage()); + DynamicUtil.join(args), ex.getMessage()); } assertTrue("Should fail is call doesn't give an exception", passed); @@ -161,7 +161,20 @@ CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertTrue( "call should matche", call.matches( METHOD_NAME, args) ); + assertTrue( "call should match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); + } + + public void testCallMatchesWithAnyArguments() throws Throwable { + String[] args = new String[] {"anyArg" }; + MockConstraint[] constraints = new MockConstraint[0]; + + mockCallable.setExpectedMatches( METHOD_NAME, args ); + mockCallable.setupMatchesReturn(true); + + CallMatch call = new CallMatch( METHOD_NAME, C.anyArgs(1), mockCallable ); + + assertTrue( "call should match", call.matches( METHOD_NAME, args) ); mockCallable.verifyExpectations(); } |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6154/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSet.java Mock.java CallMatch.java C.java CallSequence.java Added Files: Tag: DynamicMockExperiment DynamicUtil.java Log Message: Fixed proxy error reporting when used as an expectation --- NEW FILE: DynamicUtil.java --- /* * Created on 16-Apr-2003 */ package com.mockobjects.dynamic; import java.lang.reflect.Method; import java.lang.reflect.Proxy; public class DynamicUtil { public static String getProxyName(Object element) { if(Proxy.isProxyClass(element.getClass())) { try { Method mockNameMethod = Mock.class.getDeclaredMethod("getMockName", new Class[0]); Object result = Proxy.getInvocationHandler(element).invoke(element, mockNameMethod, new Object[0]); return result.toString(); } catch (Throwable e) { return element.getClass().getName(); } } return element.toString(); } public static String methodToString( String name, Object[] args ) { StringBuffer buf = new StringBuffer(); buf.append(name); buf.append("("); buf.append(DynamicUtil.join(args)); buf.append(")"); return buf.toString(); } public static String join( Object[] elements ) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < elements.length; i++) { if( i > 0 ) buf.append(", "); buf.append( "<" ); Object element = elements[i]; buf.append(DynamicUtil.getProxyName(element)); buf.append( ">" ); } return buf.toString(); } } Index: CallSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSet.java,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- CallSet.java 14 Apr 2003 08:46:25 -0000 1.1.2.7 +++ CallSet.java 16 Apr 2003 16:31:43 -0000 1.1.2.8 @@ -32,7 +32,7 @@ StringBuffer buf = new StringBuffer(); buf.append("Unexpected call to "); - buf.append(AssertMo.methodToString(methodName, args)); + buf.append(DynamicUtil.methodToString(methodName, args)); buf.append("\n"); buf.append("Expected "); buf.append(getDescription()); Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.5 retrieving revision 1.16.2.6 diff -u -r1.16.2.5 -r1.16.2.6 --- Mock.java 15 Apr 2003 22:22:58 -0000 1.16.2.5 +++ Mock.java 16 Apr 2003 16:31:43 -0000 1.16.2.6 @@ -28,7 +28,7 @@ } public Mock(Class mockedClass, String name) { - this(new DefaultCallFactory(), new CallSet(), mockedClass, mockNameFromClass(mockedClass)); + this(new DefaultCallFactory(), new CallSet(), mockedClass, name); } public Mock(Class mockedClass) { @@ -234,5 +234,28 @@ */ public void expectAndThrow(String methodName, CallSequence deprecated, Throwable throwable) { throw new AssertionFailedError("method is deprecated! Use: new OrderedMock() instead..."); + } + + /** @deprecated @see expect + */ + public void expectVoid(String methodName, Constraint[] args) { + this.expect(methodName, args); + } + + /** @deprecated @see expect + */ + public void expectVoid(String methodName, Object equalArg) { + this.expect(methodName,equalArg); + } + + /** @deprecated @see expect + */ + public void expectVoid(String methodName) { + this.expect(methodName); + } + + /** @deprecated Not required, as if methodName is called, you will get a an exception + */ + public void expectNotCalled(String methodName) { } } Index: CallMatch.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallMatch.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- CallMatch.java 15 Apr 2003 22:22:57 -0000 1.1.2.3 +++ CallMatch.java 16 Apr 2003 16:31:44 -0000 1.1.2.4 @@ -30,8 +30,8 @@ if( !constraints[i].eval(args[i]) ) { throw new AssertionFailedError( AssertMo.expectedErrorMessage( methodName + " received incorrect argument " + i, - AssertMo.join(constraints), - AssertMo.join(args) ) ); + DynamicUtil.join(constraints), + DynamicUtil.join(args) ) ); } } @@ -54,7 +54,7 @@ } public String getDescription() { - return AssertMo.methodToString(methodName, constraints); + return DynamicUtil.methodToString(methodName, constraints); } // Implemented to aid visualisation in an IDE debugger Index: C.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- C.java 15 Apr 2003 22:23:00 -0000 1.1.2.4 +++ C.java 16 Apr 2003 16:31:44 -0000 1.1.2.5 @@ -19,7 +19,6 @@ public static final Constraint IS_ZERO = eq(new Integer(0)); 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]; @@ -105,6 +104,8 @@ public static Constraint isA( Class c ) { return new IsInstanceOf(c); } + + /* Helper methods for succinctly constructing Constraint arrays */ @@ -124,4 +125,13 @@ public static Constraint[] args(Constraint p1, Constraint p2, Constraint p3) { return new Constraint[] {p1, p2, p3}; } + + public static Constraint[] anyArgs( int argCount) { + Constraint[] result = new Constraint[argCount]; + for (int i = 0; i < result.length; i++) { + result[i] = new IsAnything(); + } + + return result; + } } Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -u -r1.4.2.2 -r1.4.2.3 --- CallSequence.java 14 Apr 2003 18:46:53 -0000 1.4.2.2 +++ CallSequence.java 16 Apr 2003 16:31:44 -0000 1.4.2.3 @@ -49,7 +49,7 @@ StringBuffer buf = new StringBuffer(); buf.append("Unexpected call to "); - buf.append(AssertMo.methodToString(methodName, args)); + buf.append(DynamicUtil.methodToString(methodName, args)); buf.append("\n"); buf.append("Expected "); buf.append(getDescription()); |
From: Tim M. <ma...@us...> - 2003-04-16 16:31:52
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util In directory sc8-pr-cvs1:/tmp/cvs-serv6154/core/com/mockobjects/util Modified Files: Tag: DynamicMockExperiment AssertMo.java Log Message: Fixed proxy error reporting when used as an expectation Index: AssertMo.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util/AssertMo.java,v retrieving revision 1.2.4.3 retrieving revision 1.2.4.4 diff -u -r1.2.4.3 -r1.2.4.4 --- AssertMo.java 15 Apr 2003 22:23:00 -0000 1.2.4.3 +++ AssertMo.java 16 Apr 2003 16:31:48 -0000 1.2.4.4 @@ -1,12 +1,9 @@ package com.mockobjects.util; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import junit.framework.Assert; import junit.framework.AssertionFailedError; import com.mockobjects.Verifiable; -import com.mockobjects.dynamic.Mock; public class AssertMo extends Assert { @@ -104,44 +101,10 @@ fail(message); } - public static String join( Object[] elements ) { - StringBuffer buf = new StringBuffer(); - - for (int i = 0; i < elements.length; i++) { - if( i > 0 ) buf.append(", "); - buf.append( "<" ); - Object element = elements[i]; - if(Proxy.isProxyClass(element.getClass())) { - try { - Method mockNameMethod = Mock.class.getDeclaredMethod("getMockName", new Class[0]); - Object result = Proxy.getInvocationHandler(element).invoke(element, mockNameMethod, new Object[0]); - buf.append(result); - } catch (Throwable e) { - buf.append(element.getClass()); - } - } else { - buf.append( elements[i].toString() ); - } - buf.append( ">" ); - } - - return buf.toString(); - } - public static String expectedErrorMessage(String description, String expectedMsg, String receivedMsg) { return description + ":\n" + "\tExpected: " + expectedMsg + "\n" + "\tReceived: " + receivedMsg + "\n"; } - public static String methodToString( String name, Object[] args ) { - StringBuffer buf = new StringBuffer(); - - buf.append(name); - buf.append("("); - buf.append(join(args)); - buf.append(")"); - - return buf.toString(); - } } |
From: Tim M. <ma...@us...> - 2003-04-16 16:31:52
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv6154/core/com/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment IsEqual.java Log Message: Fixed proxy error reporting when used as an expectation Index: IsEqual.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsEqual.java,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -u -r1.2.2.3 -r1.2.2.4 --- IsEqual.java 15 Apr 2003 22:23:00 -0000 1.2.2.3 +++ IsEqual.java 16 Apr 2003 16:31:47 -0000 1.2.2.4 @@ -4,6 +4,9 @@ */ package com.mockobjects.constraint; +import com.mockobjects.dynamic.DynamicUtil; + + /** Is the value equal to another value, as tested by the * {@link java.lang.Object#equals} method? @@ -21,7 +24,7 @@ } public String toString() { - return _object.toString(); + return DynamicUtil.getProxyName(_object); } public boolean equals(Object anObject) { |
From: Jeff M. <je...@mk...> - 2003-04-16 11:56:04
|
> - Jeff, I'd like to pull the alt code out as a separate library. What do > you think? Fine by me, only thing of note is that moving forward I'd like to use the convension of project-library-version.jar for jars as this fits the rpm system. e.g. mockobjects-core-0.8.jar not mockobjects-0.8-core.jar -- Jeff Martin <je...@mk...> |
From: Steve F. <st...@m3...> - 2003-04-16 11:36:12
|
About time someone had the time to finish up the library! Here's some things I think we ought to do: - announce on MO-java-users, I have no idea whether anyone out there is using this stuff. - it would be really, really nice if someone would volunteer to help clean up the build. It's lotsa fun to write new features, but there's some boring stuff to do as well. In particular, we need to split out the website and maybe move to the Wiki that Joe's so kindly set up. - there's also a noticeable amount of duplication in the code. Who will take responsibility for tidying it up after the initial commit? - Jeff, I'd like to pull the alt code out as a separate library. What do you think? Tim Mackinnon wrote: > Anyway - the library is working out quite well now and we should consider > rolling it in to the head stream soom! (Maybe a day or two more of "in > usage" testing, and comments from anyone else who is interested - but to be > honest making it available in the head should allow greater changes). > > Here are some points: > > 1) To test the dynamic stuff, we used Traditional Mocks - it became a pain > hand coding them, especially on larger interfaces, so we took the decision > to use MockMaker. This worked well, however their are some ReturnXXX objects > [...] How about moving the mockmaker stuff into a holding package, or at least commenting it? Right now it's confusing and there are no cues for what to use. > 2) The Callable interface has a "matches" method, this doesn't feel right > for all callables, its required for CallBag to operate - others don't need > it. This should be removed and implemented as a private decoration for > CallBag. How else can we tell if an incorrect method call has been made? I thought that was part of what matches did? > 4) As you can use mocks as expected values themselves - there was some > ugliness with the proxies needing to detect equality of mocks (you can see > this in the invoke method). I'm not sure if there is a better way to do > this. Can we have an example of how this is used? Also, what's this "getMockName" thing? > 5) I think Mocks should probably register with something so that we can do > the Verifier.verify on both instance variables and local variables in a > test. I am still seeing lots of accidently unverified mocks you mean (gasp) a global collection? Is this a problem because of the structure of your tests? S. -- "A LISP programmer knows the value of everything but the cost of nothing. A C programmer knows the cost of everything but the value of nothing." (Todd Proebsting) |
From: Nat P. <nat...@b1...> - 2003-04-16 11:33:48
|
The way it would work is that the sequence would be added to the mock and therefore be checked to see if it matched any incoming call. The sequence would match if the callable at its head matched. Once the callable hasBeenCalled, the head would be dequeued and the sequence would then match subsequent calls against the new head. This achieves the current behaviour, makes it easier to define sequences of more than two calls, allows more flexible combinations of sequences and selections, and does not need any changes to the mock class itself because all code to deal with sequences is in the CallSequence class, and just "falls out" of the current design. Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Steve Freeman" <st...@m3...> To: "Mockobjects-Java-Dev" <moc...@li...> Sent: Wednesday, April 16, 2003 12:17 PM Subject: Re: [MO-java-dev] Java Dynamic Mocks - going to Head? > Nat Pryce wrote: > >>Callable c1 = mock.expect("setContentType".....) > >>Callable c2 = mock.expect("getWriter".....) > >>c1.expectBefore(c2) > >> > > In the new design, this would be accomplished by organising "setContentType" > > and "getWriter" into a CallSequence and adding the call sequence to the > > Mock. > > > > CallCollection seq = mock.expectSequence(); > > seq.expectVoid( "setContentType", ... ); > > seq.expectAndReturn( "getWriter", ... ); > > > > The expectBefore method will be quite messy to implement in the current > > design. Since there is already a way to achieve the same effect, I'd > > suggest not implementing expectBefore. > > We went round this a few times in discussion. We can think of three > common cases: > - I don't care about the order: > Mock > - I care about the whole sequence: > OrderedMock > - I don't care about the order /except/ for these two: > Mock plus annotations. > > The problem with getting the sequence is how to relate it to the rest of > the expectations? And I wanted to avoid having toggles and state and > general complication. The implementation is actually quite easy if the > Calleable supports a hasBeenCalled() property (we did it in the old > version). And (to me, at least) it's easier to read. > > S. > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Steve F. <st...@m3...> - 2003-04-16 11:17:07
|
Nat Pryce wrote: >>Callable c1 = mock.expect("setContentType".....) >>Callable c2 = mock.expect("getWriter".....) >>c1.expectBefore(c2) >> > In the new design, this would be accomplished by organising "setContentType" > and "getWriter" into a CallSequence and adding the call sequence to the > Mock. > > CallCollection seq = mock.expectSequence(); > seq.expectVoid( "setContentType", ... ); > seq.expectAndReturn( "getWriter", ... ); > > The expectBefore method will be quite messy to implement in the current > design. Since there is already a way to achieve the same effect, I'd > suggest not implementing expectBefore. We went round this a few times in discussion. We can think of three common cases: - I don't care about the order: Mock - I care about the whole sequence: OrderedMock - I don't care about the order /except/ for these two: Mock plus annotations. The problem with getting the sequence is how to relate it to the rest of the expectations? And I wanted to avoid having toggles and state and general complication. The implementation is actually quite easy if the Calleable supports a hasBeenCalled() property (we did it in the old version). And (to me, at least) it's easier to read. S. |
From: Nat P. <nat...@b1...> - 2003-04-16 10:12:14
|
Sorry for being incomunicado for the last few days. I haven't had a chance to see the latest changes -- it seems next to impossible to get BT to acknowledge that they can install a phone line to my boat let alone broadband! I'd like the chance to meet up and check out / comment on the latest updates. Are you (Tim) going to be at XTC this week? Perhaps we could hammer out the CallSequence class. > 2) The Callable interface has a "matches" method, this doesn't feel right > for all callables, its required for CallBag to operate - others don't need > it. This should be removed and implemented as a private decoration for > CallBag. For a CallSequence it will also need a "complete" method that returns true if the Callable can be removed from the front of the sequence. Personally, I feel comfortable having these methods in the Callable interface, but if the Decorator approach works that will be great. > 3) Steve's exellent suggestion of having: > > Callable c1 = mock.expect("setContentType".....) > Callable c2 = mock.expect("getWriter".....) > c1.expectBefore(c2) > > has not yet been implemented. This should work quite easily, but the focus > has been on UnorderdMock and OrderedMock. In the new design, this would be accomplished by organising "setContentType" and "getWriter" into a CallSequence and adding the call sequence to the Mock. CallCollection seq = mock.expectSequence(); seq.expectVoid( "setContentType", ... ); seq.expectAndReturn( "getWriter", ... ); The expectBefore method will be quite messy to implement in the current design. Since there is already a way to achieve the same effect, I'd suggest not implementing expectBefore. |
From: Tim M. <tim...@po...> - 2003-04-16 08:18:52
|
Guys - First of all, sorry for missing Xtc - I've got the dynamic bug and want to see the library in a state that it can be used in many projects. I think its important to convey the power and simplicity of mocks (we all know this, but there are so many bad examples out there...). Anyway - I tried using the branch in the e2x codebase and as always, on a real project there are often little subtleties that catch you out. As John Nolan was around working on his own little pet project we bounced ideas of each other to get things done. Anyway - the library is working out quite well now and we should consider rolling it in to the head stream soom! (Maybe a day or two more of "in usage" testing, and comments from anyone else who is interested - but to be honest making it available in the head should allow greater changes). Here are some points: 1) To test the dynamic stuff, we used Traditional Mocks - it became a pain hand coding them, especially on larger interfaces, so we took the decision to use MockMaker. This worked well, however their are some ReturnXXX objects that it uses that should be in the base library. In the branch I have just put them in - however they duplicate some existing functionality. I propse we resolve this duplication in a second pass as it requires updates to code that mockmaker generates. Having the additional duplication allows an exisiting generated mock to be updated by simply removing 3 import lines. To get a full solution we need to get all the tools running on a single platform - and you use the right one for the right job. 2) The Callable interface has a "matches" method, this doesn't feel right for all callables, its required for CallBag to operate - others don't need it. This should be removed and implemented as a private decoration for CallBag. 3) Steve's exellent suggestion of having: Callable c1 = mock.expect("setContentType".....) Callable c2 = mock.expect("getWriter".....) c1.expectBefore(c2) has not yet been implemented. This should work quite easily, but the focus has been on UnorderdMock and OrderedMock. 4) As you can use mocks as expected values themselves - there was some ugliness with the proxies needing to detect equality of mocks (you can see this in the invoke method). I'm not sure if there is a better way to do this. 5) I think Mocks should probably register with something so that we can do the Verifier.verify on both instance variables and local variables in a test. I am still seeing lots of accidently unverified mocks Overall the sample test case is looking very good (I have included it again below). How does everyone feel going ahead with a merge (I can probably get Chris Cottee to help me merge it in at e2x)? Tim public void testDoGetNew() throws ServletException, IOException { 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", "subject", "Mail Subject" ); // Alternative syntax mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), "Mail Body" ); final PrintWriter contentWriter = new PrintWriter(new StringWriter()); mockHttpServletResponse.expect( "setContentType", "text/html"); mockHttpServletResponse.expectAndReturn( "getWriter", contentWriter ); // Still to do, instead of making response an OrderedMock // CallMatch m1 = mockHttpServletResponse.expect( "setContentType", "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()); mockHttpServletRequest.verify(); mockHttpServletResponse.verify(); } --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6206/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment DummyInterface.java ExpectedCallTest.java MockCallable.java MockTest.java CallMatchTest.java Log Message: Improved error reporting for Proxy's as expectation values Added additional conveniance methods for primitive types Added deprecated expect methods to make library conversion easy Got distracted and have missed XtC completely... Index: DummyInterface.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/DummyInterface.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- DummyInterface.java 14 Apr 2003 08:46:29 -0000 1.1.2.3 +++ DummyInterface.java 15 Apr 2003 22:22:55 -0000 1.1.2.4 @@ -11,4 +11,5 @@ public String oneArgMethod( String arg1); public void noArgMethodVoid(); + public String noArgMethod(); } Index: ExpectedCallTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/ExpectedCallTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- ExpectedCallTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.3 +++ ExpectedCallTest.java 15 Apr 2003 22:22:55 -0000 1.1.2.4 @@ -13,26 +13,26 @@ */ public class ExpectedCallTest extends TestCase { - final String result = "result!"; - final String methodName = "methodName"; - final Object[] args = { "arg1", "arg2" }; - final String decoratedDescription = AssertMo.methodToString( methodName, args ); + final String RESULT = "result!"; + final String METHOD_NAME = "methodName"; + final Object[] ARGS = { "arg1", "arg2" }; + final String DECORATED_DESCRIPTION = AssertMo.methodToString( METHOD_NAME, ARGS ); Mock ignoredMock = null; - MockCallable mockDecorated = new MockCallable(); - ExpectedCall call = new ExpectedCall( mockDecorated ); + MockCallable mockCallable = new MockCallable(); + ExpectedCall call = new ExpectedCall( mockCallable ); public ExpectedCallTest(String name) { super(name); } public void setUp() { - mockDecorated.setupGetDescription(decoratedDescription); + mockCallable.setupGetDescription(DECORATED_DESCRIPTION); } public void testDescription() { AssertMo.assertIncludes( "should contain decorated's description", - decoratedDescription, call.getDescription() ); + DECORATED_DESCRIPTION, call.getDescription() ); AssertMo.assertIncludes( "should say that decorated call is mandatory", "mandatory", call.getDescription() ); } @@ -43,7 +43,7 @@ } catch( AssertionFailedError ex ) { AssertMo.assertIncludes( "should include description of expected call", - decoratedDescription, ex.getMessage() ); + DECORATED_DESCRIPTION, ex.getMessage() ); return; } @@ -51,52 +51,52 @@ } public void testVerifiesIfCalled() throws Throwable { - mockDecorated.setupCallReturn( result ); - mockDecorated.setExpectedVerifyCalls(1); + mockCallable.setupCallReturn( RESULT ); + mockCallable.setExpectedVerifyCalls(1); - call.call( ignoredMock, methodName, args ); + call.call( ignoredMock, METHOD_NAME, ARGS ); call.verify(); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testMatchesDelegated() throws Throwable { - mockDecorated.setExpectedMatches( methodName, args ); - mockDecorated.setupMatchesReturn(true); - assertTrue( "returns matches to be true", call.matches( methodName, args ) ); - mockDecorated.verifyExpectations(); + mockCallable.setExpectedMatches( METHOD_NAME, ARGS ); + mockCallable.setupMatchesReturn(true); + assertTrue( "returns matches to be true", call.matches( METHOD_NAME, ARGS ) ); + mockCallable.verifyExpectations(); } public void testCallArgumentsPassedThrough() throws Throwable { - mockDecorated.setExpectedCall(ignoredMock, methodName, args); - mockDecorated.setupCallReturn(result); + mockCallable.setExpectedCall(ignoredMock, METHOD_NAME, ARGS); + mockCallable.setupCallReturn(RESULT); - call.call( ignoredMock, methodName, args ); - mockDecorated.verifyExpectations(); + call.call( ignoredMock, METHOD_NAME, ARGS ); + mockCallable.verifyExpectations(); } public void testDecoratedResultPassedThrough() throws Throwable { - mockDecorated.setupCallReturn(result); + mockCallable.setupCallReturn(RESULT); assertSame( "should return decorated's result", - result, call.call( ignoredMock, methodName, args ) ); - mockDecorated.verifyExpectations(); + RESULT, call.call( ignoredMock, METHOD_NAME, ARGS ) ); + mockCallable.verifyExpectations(); } public void testDecoratedExceptionPassedThrough() throws Throwable { final Throwable exception = new DummyThrowable(); - mockDecorated.setupCallThrow(exception); + mockCallable.setupCallThrow(exception); try { - call.call( ignoredMock, methodName, args ); + call.call( ignoredMock, METHOD_NAME, ARGS ); fail("expected decorated's throwable to be thrown"); } catch( DummyThrowable ex ) { // expected } - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } } Index: MockCallable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockCallable.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- MockCallable.java 11 Apr 2003 13:21:16 -0000 1.1.2.1 +++ MockCallable.java 15 Apr 2003 22:22:56 -0000 1.1.2.2 @@ -19,6 +19,7 @@ private ExpectationValue matchesMethodName = new ExpectationValue("matches.methodName"); private ExpectationList matchesArgs = new ExpectationList("matches.args"); private ReturnValue matchesResult = new ReturnValue("matches.return"); + private ExpectationCounter matchesCount = new ExpectationCounter("matches.count"); private ExpectationCounter verifyCount = new ExpectationCounter("verify.count"); private AssertionFailedError verifyError = null; @@ -62,6 +63,10 @@ matchesArgs.addExpectedMany(args); } + public void setExpectedMatchesCount(int count) { + matchesCount.setExpected(count); + } + public void setupMatchesReturn( boolean result ) { matchesResult.setValue(result); } @@ -69,6 +74,7 @@ public boolean matches(String methodName, Object[] args) { matchesMethodName.setActual(methodName); matchesArgs.addActualMany(args); + matchesCount.inc(); return matchesResult.getBooleanValue(); } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.5 retrieving revision 1.8.2.6 diff -u -r1.8.2.5 -r1.8.2.6 --- MockTest.java 14 Apr 2003 08:46:28 -0000 1.8.2.5 +++ MockTest.java 15 Apr 2003 22:22:56 -0000 1.8.2.6 @@ -13,8 +13,10 @@ public class MockTest extends TestCase { private static final String MOCK_NAME = "Test mock"; final String METHOD_NOARG_NAME = "noArgMethodVoid"; + final String METHOD_NOARGANDRETURN_NAME = "noArgMethod"; + final String METHOD_NOARGANDRETURN_RESULT = "resultNoArgs"; final String METHOD_ONEARG_NAME = "oneArgMethod"; - final String METHOD_ONEARG_RESULT = "resultOArgs"; + final String METHOD_ONEARG_RESULT = "result1Args"; final String METHOD_TWOARG_NAME = "twoArgMethod"; final String METHOD_TWOARG_RESULT = "resultTwoArgs"; final Throwable METHOD_EXCEPTION = new DummyThrowable("Configured test throwable"); @@ -47,7 +49,7 @@ } } - public void testExpect() throws Throwable { + public void testExpectManyAndVoid() throws Throwable { mockCallFactory.setExpectedCreateVoidStubCalls(1); mockCallFactory.setupCreateVoidStub(mockVoidStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub); @@ -63,7 +65,71 @@ mockCallableAddable.verifyExpectations(); } - public void testExpectOne() throws Throwable { + public void testExpectNoneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expectAndReturn(METHOD_NOARGANDRETURN_NAME, METHOD_NOARGANDRETURN_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectNoneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expectAndThrow(METHOD_NOARGANDRETURN_NAME, METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectOneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expectAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectNoneAndVoid() throws Throwable { + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAdd(mockExpectedCall); + + mock.expect(METHOD_NOARG_NAME); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectOneAndVoid() throws Throwable { mockCallFactory.setExpectedCreateVoidStubCalls(1); mockCallFactory.setupCreateVoidStub(mockVoidStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub); @@ -79,7 +145,7 @@ mockCallableAddable.verifyExpectations(); } - public void testExpectAndReturn() throws Throwable { + public void testExpectManyAndReturn() throws Throwable { mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); @@ -96,7 +162,7 @@ mockCallableAddable.verifyExpectations(); } - public void testExpectAndThrow() throws Throwable { + public void testExpectManyAndThrow() throws Throwable { mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); @@ -130,7 +196,7 @@ mockCallableAddable.verifyExpectations(); } - public void testMatchAndReturn() throws Throwable { + public void testMatchManyAndReturn() throws Throwable { mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); @@ -145,7 +211,37 @@ mockCallableAddable.verifyExpectations(); } - public void testMatchAndThrow() throws Throwable { + public void testMatchNoneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_NOARGANDRETURN_RESULT); + + mock.matchAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMatchOneAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + + mock.matchAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMatchManyAndThrow() throws Throwable { mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); @@ -174,6 +270,21 @@ Verifier.verifyObject(this); mockCallableAddable.verifyExpectations(); } + + public void testMatchNoneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + + mockCallableAddable.addExpectedAdd(mockCallMatch); + mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + + mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } public void testMockAnnotatesAssertionFailedErrors() throws Throwable { @@ -207,7 +318,6 @@ mockCallableAddable.setExpectedCall(mock, METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS); mockCallableAddable.setupCallReturn("result ignored"); - //mock.invoke(unusedProxy, METHOD_A_METHOD, METHOD_A_ARGS); proxy.twoArgMethod(METHOD_TWOARG_ARGS[0], METHOD_TWOARG_ARGS[1]); mockCallableAddable.verifyExpectations(); @@ -247,5 +357,22 @@ mock.verify(); mockCallableAddable.verifyExpectations(); + } + + public void testProxyEquality() throws Exception { + assertTrue("Should handle proxy equality without checking expectations", proxy.equals(proxy)); + } + + public void testProxyInEquality() throws Exception { + boolean IGNORED_RESULT = true; + CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT)); + mockCallFactory.setupCreateReturnStub(ret); + mockCallFactory.setupCreateCallMatch(new CallMatch("call",C.ANY_ARGS,ret)); + mockCallableAddable.setupCallReturn(new Boolean(false)); + + mock.matchAndReturn("call", C.ANY_ARGS, IGNORED_RESULT); + assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); + + Verifier.verifyObject(this); } } Index: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallMatchTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallMatchTest.java 11 Apr 2003 13:21:16 -0000 1.1.2.2 +++ CallMatchTest.java 15 Apr 2003 22:22:56 -0000 1.1.2.3 @@ -11,10 +11,10 @@ public class CallMatchTest extends TestCase { - final String methodName = "methodName"; + final String METHOD_NAME = "methodName"; Mock mock = new Mock(DummyInterface.class,"mock"); - MockCallable mockDecorated = new MockCallable(); - CallMatch call = new CallMatch( methodName, new Constraint[0], mockDecorated ); + MockCallable mockCallable = new MockCallable(); + CallMatch call = new CallMatch( METHOD_NAME, new Constraint[0], mockCallable ); public CallMatchTest(String name) { super(name); @@ -24,38 +24,38 @@ final Object[] arguments = new Object[0]; final String result = "result"; - mockDecorated.setExpectedCall( mock, methodName, arguments ); - mockDecorated.setupCallReturn( result ); + mockCallable.setExpectedCall( mock, METHOD_NAME, arguments ); + mockCallable.setupCallReturn( result ); - call.call(mock, methodName, arguments); + call.call(mock, METHOD_NAME, arguments); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testUncalledCallVerifies() { - mockDecorated.setExpectedVerifyCalls(1); + mockCallable.setExpectedVerifyCalls(1); call.verify(); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testSuccessfulCallVerifies() throws Throwable { - mockDecorated.setExpectedVerifyCalls(1); - mockDecorated.setupCallReturn("result"); + mockCallable.setExpectedVerifyCalls(1); + mockCallable.setupCallReturn("result"); call.call( mock, "methodName", new Object[0] ); call.verify(); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testMultipleCallsSucceed() throws Throwable { - mockDecorated.setupCallReturn("result"); + mockCallable.setupCallReturn("result"); - call.call( mock, methodName, new Object[0] ); - call.call( mock, methodName, new Object[0] ); + call.call( mock, METHOD_NAME, new Object[0] ); + call.call( mock, METHOD_NAME, new Object[0] ); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testArgumentsCheckedAgainstConstraints() throws Throwable { @@ -65,17 +65,17 @@ new MockConstraint( "constraint2", args[1], true ), new MockConstraint( "constraint3", args[2], true ) }; - mockDecorated.setupCallReturn("result"); + mockCallable.setupCallReturn("result"); - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - call.call( mock, methodName, args ); + call.call( mock, METHOD_NAME, args ); for( int i = 0; i < constraints.length; i++ ) { constraints[i].verify(); } - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testWrongNumberOfArguments() throws Throwable { @@ -86,11 +86,11 @@ new MockConstraint( "constraint3", args[1], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); boolean passed = true; try { - call.call( mock, methodName, args ); + call.call( mock, METHOD_NAME, args ); passed = false; } catch (AssertionFailedError ex) { AssertMo.assertIncludes("Should show expected number of arguments", @@ -98,11 +98,11 @@ AssertMo.assertIncludes("Should show actual number of arguments", Integer.toString(args.length), ex.getMessage()); AssertMo.assertIncludes("Should include the method name", - methodName, ex.getMessage()); + METHOD_NAME, ex.getMessage()); } assertTrue("Should fail is call doesn't give an exception", passed); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testConstraintFailure() throws Throwable { @@ -113,15 +113,15 @@ new MockConstraint( "constraintC", args[2], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); boolean passed = true; try { - call.call( mock, methodName, args ); + call.call( mock, METHOD_NAME, args ); passed = false; } catch (AssertionFailedError ex) { AssertMo.assertIncludes("Should include the method name", - methodName, ex.getMessage()); + METHOD_NAME, ex.getMessage()); AssertMo.assertIncludes("Should show index of failed argument", "1", ex.getMessage() ); AssertMo.assertIncludes("Should show expected arguments", @@ -131,7 +131,7 @@ } assertTrue("Should fail is call doesn't give an exception", passed); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } @@ -143,16 +143,41 @@ new MockConstraint( "constraint3", args[2], true ) }; - mockDecorated.setExpectedMatches( methodName, args ); - mockDecorated.setupMatchesReturn(true); + mockCallable.setExpectedMatches( METHOD_NAME, args ); + mockCallable.setupMatchesReturn(true); - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertTrue( "call matches", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertTrue( "call matches", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } - public void testCallDoesNotMatchIfDecoratedDoesNotMatch() throws Throwable { + public void testCallMatchesWithNoArguments() throws Throwable { + String[] args = new String[0]; + MockConstraint[] constraints = new MockConstraint[0]; + + mockCallable.setExpectedMatches( METHOD_NAME, args ); + mockCallable.setupMatchesReturn(true); + + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); + + assertTrue( "call should matche", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); + } + + public void testCallMatchesWithNoArgumentsAndCalleeHasArguments() throws Throwable { + String[] args = new String[] {"arg1", "arg2"}; + MockConstraint[] constraints = new MockConstraint[0]; + + mockCallable.setExpectedMatchesCount(0); + + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); + + assertFalse( "call should not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); + } + + public void testCallDoesNotMatchIfDelegateDoesNotMatch() throws Throwable { String[] args = { "arg1", "arg2", "arg3" }; MockConstraint[] constraints = { new MockConstraint( "constraint1", args[0], true ), @@ -160,20 +185,20 @@ new MockConstraint( "constraint3", args[2], true ) }; - mockDecorated.setExpectedMatches( methodName, args ); - mockDecorated.setupMatchesReturn(false); + mockCallable.setExpectedMatches( METHOD_NAME, args ); + mockCallable.setupMatchesReturn(false); - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertFalse( "call does not match when decorated does not match", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertFalse( "call does not match when delegate does not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } public void testCallDoesNotMatchWhenWrongName() throws Throwable { - CallMatch call = new CallMatch( methodName, new Constraint[0], mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, new Constraint[0], mockCallable ); assertFalse( "call does not match", call.matches( "anotherName", new Object[0]) ); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } public void testCallDoesNotMatchWhenWrongNumberOfArguments() throws Throwable { @@ -184,10 +209,10 @@ new MockConstraint( "constraint3", args[1], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertFalse( "call does not match", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertFalse( "call does not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } public void testCallDoesNotMatchWhenConstraintIsViolated() throws Throwable { @@ -198,23 +223,23 @@ new MockConstraint( "constraintC", args[2], true ) }; - CallMatch call = new CallMatch( methodName, (Constraint[])constraints, mockDecorated ); + CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - assertFalse( "call does not match", call.matches( methodName, args) ); - mockDecorated.verifyExpectations(); + assertFalse( "call does not match", call.matches( METHOD_NAME, args) ); + mockCallable.verifyExpectations(); } public void testMatchesAfterCalls() throws Throwable { - mockDecorated.setupCallReturn("result"); - mockDecorated.setupMatchesReturn(true); + mockCallable.setupCallReturn("result"); + mockCallable.setupMatchesReturn(true); - CallMatch call = new CallMatch(methodName, C.args(), mockDecorated ); + CallMatch call = new CallMatch(METHOD_NAME, C.args(), mockCallable ); - call.call( mock, methodName, new Object[0] ); - assertTrue( "matches after first call", call.matches( methodName, new Object[0]) ); - call.call( mock, methodName, new Object[0] ); - assertTrue( "matches after further calls", call.matches( methodName, new Object[0]) ); + call.call( mock, METHOD_NAME, new Object[0] ); + assertTrue( "matches after first call", call.matches( METHOD_NAME, new Object[0]) ); + call.call( mock, METHOD_NAME, new Object[0] ); + assertTrue( "matches after further calls", call.matches( METHOD_NAME, new Object[0]) ); - mockDecorated.verifyExpectations(); + mockCallable.verifyExpectations(); } } |
From: Tim M. <ma...@us...> - 2003-04-15 22:23:04
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory sc8-pr-cvs1:/tmp/cvs-serv6206/core/com/mockobjects Modified Files: Tag: DynamicMockExperiment AbstractExpectationCollection.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: AbstractExpectationCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/AbstractExpectationCollection.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- AbstractExpectationCollection.java 5 Nov 2002 16:02:36 -0000 1.5 +++ AbstractExpectationCollection.java 15 Apr 2003 22:23:00 -0000 1.5.2.1 @@ -22,6 +22,8 @@ } public void addActualMany(Object[] items) { + if(items == null) return; + for (int i = 0; i < items.length; ++i) { addActual(items[i]); } |
From: Tim M. <ma...@us...> - 2003-04-15 22:23:04
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv6206/core/com/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment IsEqual.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: IsEqual.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsEqual.java,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -r1.2.2.2 -r1.2.2.3 --- IsEqual.java 11 Apr 2003 13:17:04 -0000 1.2.2.2 +++ IsEqual.java 15 Apr 2003 22:23:00 -0000 1.2.2.3 @@ -25,6 +25,6 @@ } public boolean equals(Object anObject) { - return anObject.getClass().equals(this.getClass()) && eval(((IsEqual)anObject)._object); + return eval(anObject); } } |
From: Tim M. <ma...@us...> - 2003-04-15 22:23:04
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util In directory sc8-pr-cvs1:/tmp/cvs-serv6206/core/com/mockobjects/util Modified Files: Tag: DynamicMockExperiment AssertMo.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: AssertMo.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util/AssertMo.java,v retrieving revision 1.2.4.2 retrieving revision 1.2.4.3 diff -u -r1.2.4.2 -r1.2.4.3 --- AssertMo.java 7 Apr 2003 14:27:02 -0000 1.2.4.2 +++ AssertMo.java 15 Apr 2003 22:23:00 -0000 1.2.4.3 @@ -1,8 +1,12 @@ package com.mockobjects.util; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + import junit.framework.Assert; import junit.framework.AssertionFailedError; import com.mockobjects.Verifiable; +import com.mockobjects.dynamic.Mock; public class AssertMo extends Assert { @@ -106,7 +110,18 @@ for (int i = 0; i < elements.length; i++) { if( i > 0 ) buf.append(", "); buf.append( "<" ); - buf.append( elements[i].toString() ); + Object element = elements[i]; + if(Proxy.isProxyClass(element.getClass())) { + try { + Method mockNameMethod = Mock.class.getDeclaredMethod("getMockName", new Class[0]); + Object result = Proxy.getInvocationHandler(element).invoke(element, mockNameMethod, new Object[0]); + buf.append(result); + } catch (Throwable e) { + buf.append(element.getClass()); + } + } else { + buf.append( elements[i].toString() ); + } buf.append( ">" ); } |