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: Nat P. <nat...@b1...> - 2003-07-02 09:18:27
|
How about NOT using the call factory to create the decorator chains for toString in the constructor. Instead, create them explicitly with the new operator. The CallFactory was created so that we could test how the Mock constructed objects in response to other calls. If we have Tim's unit tests for toString then we don't need to use the CallFactory to test the mocking of toString in the constructor. Does that make sense? Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: <st...@m3...> To: <tim...@po...> Cc: <st...@m3...>; <moc...@li...> Sent: Wednesday, July 02, 2003 10:04 AM Subject: RE: [MO-java-dev] DynaMock proxy toString issue I don't believe so (I have done a little of this mock stuff before ;-). I was trying to implement Chris's idea of using the matching infrastructure to implement the special methods. It's not hard to code, but a pain to write the tests. I also suspect that MockMaker generates too much stuff. There are 24 methods on MockCallFactory of which 4 are the supported interface. It has to be possible to simplify that. S. > These tests would work exactly as specified - I think the way you are trying > to solve the problem is wrong (e.g. you have misunderstood the metaphor that > all the other tests are based on). > > Don't add the methods as defaults on construction (I think this would break > most objects in any design) - you just need to check if the method is > toString, and if an expectation/match has been set on the mock for it. > > It is literally changing the following method in mock: > > private boolean isMockNameGetter(Method method, Object[] args) { > return (method.getName().equals("toString")) && (args == null); > // to also check for expectation you need something like > // && !calls.hasCall("toString",args); > } > > > -----Original Message----- > > From: moc...@li... > > [mailto:moc...@li...]On Behalf Of > > Steve Freeman > > Sent: 02 July 2003 04:08 > > To: moc...@li... > > Subject: Re: [MO-java-dev] DynaMock proxy toString issue > > > > > > Tim Mackinnon wrote: > > > Not sure why the tests would be pain, isn't just a case of > > adding the two > > > following tests to mock? > > > > > > public void testProxyToStringWithNoToStringExpectation() > > throws Exception { > > > mockCallableAddable.addExpectedHasCall("toString", > > METHOD_NOARG_ARGS); > > > mockCallableAddable.setupHasCall(false); > > > > > > assertEquals("Should get mock name", MOCK_NAME, > > mock.proxy().toString()); > > > mock.verify(); > > > } > > > > no. If the methods are added as defaults on Mock, during construction, > > you have to fix the other tests so that calls to > > MockCallFactory.createReturnStub() don't fail because it's short of a > > return value. Which suggests that the callFactory is overspecified. > > > > > There is a smell, in some of the other tests because the > > CallFactory is a > > > bit over-used, it generates several types of stubs decorating > > each other (so > > > you have to set each of them up). I would say that this should be better > > > encapsulated so you just set one expectation on the > > mockCallFactory - the > > > tests would simplify and your code would be better. > > > > Exactly. > > > > S. > > > > > > > > ------------------------------------------------------- > > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > > Data Reports, E-commerce, Portals, and Forums are available now. > > Download today and enter to win an XBOX or Visual Studio .NET. > > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > > _______________________________________________ > > Mockobjects-java-dev mailing list > > Moc...@li... > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > > > --- > > Incoming mail is certified Virus Free. > > Checked by AVG anti-virus system (http://www.grisoft.com). > > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: <st...@m3...> - 2003-07-02 09:04:41
|
I don't believe so (I have done a little of this mock stuff before ;-). I w= as trying to implement Chris's idea of using the matching infrastructure to= implement the special methods. It's not hard to code, but a pain to write = the tests.=20 I also suspect that MockMaker generates too much stuff. There are 24 method= s on MockCallFactory of which 4 are the supported interface. It has to be p= ossible to simplify that. S. > These tests would work exactly as specified - I think the way you are try= ing > to solve the problem is wrong (e.g. you have misunderstood the metaphor t= hat > all the other tests are based on). >=20 > Don't add the methods as defaults on construction (I think this would bre= ak > most objects in any design) - you just need to check if the method is > toString, and if an expectation/match has been set on the mock for it. >=20 > It is literally changing the following method in mock: >=20 > private boolean isMockNameGetter(Method method, Object[] args) { > return (method.getName().equals("toString")) && (args =3D=3D null); > // to also check for expectation you need something like > // && !calls.hasCall("toString",args); > } >=20 > > -----Original Message----- > > From: moc...@li... > > [mailto:moc...@li...]On Behalf Of > > Steve Freeman > > Sent: 02 July 2003 04:08 > > To: moc...@li... > > Subject: Re: [MO-java-dev] DynaMock proxy toString issue > > > > > > Tim Mackinnon wrote: > > > Not sure why the tests would be pain, isn't just a case of > > adding the two > > > following tests to mock? > > > > > > public void testProxyToStringWithNoToStringExpectation() > > throws Exception { > > > mockCallableAddable.addExpectedHasCall("toString", > > METHOD_NOARG_ARGS); > > > mockCallableAddable.setupHasCall(false); > > > > > > assertEquals("Should get mock name", MOCK_NAME, > > mock.proxy().toString()); > > > mock.verify(); > > > } > > > > no. If the methods are added as defaults on Mock, during construction, > > you have to fix the other tests so that calls to > > MockCallFactory.createReturnStub() don't fail because it's short of a > > return value. Which suggests that the callFactory is overspecified. > > > > > There is a smell, in some of the other tests because the > > CallFactory is a > > > bit over-used, it generates several types of stubs decorating > > each other (so > > > you have to set each of them up). I would say that this should be bet= ter > > > encapsulated so you just set one expectation on the > > mockCallFactory - the > > > tests would simplify and your code would be better. > > > > Exactly. > > > > S. > > > > > > > > ------------------------------------------------------- > > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > > Data Reports, E-commerce, Portals, and Forums are available now. > > Download today and enter to win an XBOX or Visual Studio .NET. > > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > > _______________________________________________ > > Mockobjects-java-dev mailing list > > Moc...@li... > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > > > --- > > Incoming mail is certified Virus Free. > > Checked by AVG anti-virus system (http://www.grisoft.com). > > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 |
From: Tim M. <tim...@po...> - 2003-07-02 06:30:28
|
These tests would work exactly as specified - I think the way you are trying to solve the problem is wrong (e.g. you have misunderstood the metaphor that all the other tests are based on). Don't add the methods as defaults on construction (I think this would break most objects in any design) - you just need to check if the method is toString, and if an expectation/match has been set on the mock for it. It is literally changing the following method in mock: private boolean isMockNameGetter(Method method, Object[] args) { return (method.getName().equals("toString")) && (args == null); // to also check for expectation you need something like // && !calls.hasCall("toString",args); } > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Steve Freeman > Sent: 02 July 2003 04:08 > To: moc...@li... > Subject: Re: [MO-java-dev] DynaMock proxy toString issue > > > Tim Mackinnon wrote: > > Not sure why the tests would be pain, isn't just a case of > adding the two > > following tests to mock? > > > > public void testProxyToStringWithNoToStringExpectation() > throws Exception { > > mockCallableAddable.addExpectedHasCall("toString", > METHOD_NOARG_ARGS); > > mockCallableAddable.setupHasCall(false); > > > > assertEquals("Should get mock name", MOCK_NAME, > mock.proxy().toString()); > > mock.verify(); > > } > > no. If the methods are added as defaults on Mock, during construction, > you have to fix the other tests so that calls to > MockCallFactory.createReturnStub() don't fail because it's short of a > return value. Which suggests that the callFactory is overspecified. > > > There is a smell, in some of the other tests because the > CallFactory is a > > bit over-used, it generates several types of stubs decorating > each other (so > > you have to set each of them up). I would say that this should be better > > encapsulated so you just set one expectation on the > mockCallFactory - the > > tests would simplify and your code would be better. > > Exactly. > > S. > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 |
From: Steve F. <st...@m3...> - 2003-07-02 03:47:26
|
Added to CVS. S. Francois Beausoleil wrote: > Hi ! >=20 > I need functionnality equivalent to expect(String, Object), but for > match(). Currently, in 0.09, there are matchAndReturn methods, but no > simple match(String). In this specific test instance, it does not matt= er > how many times I call method X as it has been asserted elsewhere that t= he > correct number of calls is made. >=20 > Instead of: > mock.expect("eat", C.ANY_ARGS); >=20 > I would like: > mock.match("eat", C.ANY_ARGS); >=20 > This is something like the nice mock feature I spoke about a few weeks > back. What I want is no exception if I call the method 100 times or 10 > times. >=20 > Thanks ! > Fran=E7ois > -- > Francois Beausoleil > Developer of Java Gui Builder > http://jgb.sourceforge.net/ >=20 >=20 > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/0= 1 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Steve F. <sm...@us...> - 2003-07-02 03:46:21
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv18960/src/core/test/mockobjects/dynamic Modified Files: MockTest.java Log Message: Added match() methods for methods that return void. Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- MockTest.java 12 Jun 2003 22:45:16 -0000 1.12 +++ MockTest.java 2 Jul 2003 03:46:18 -0000 1.13 @@ -226,16 +226,31 @@ mockCallableAddable.verifyExpectations(); } - public void testMatchManyAndReturn() throws Throwable { - mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); + public void testMatchNoneAndVoid() throws Throwable { + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub); + mockCallFactory.setupCreateCallSignature(mockCallMatch); + + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_NOARGANDRETURN_RESULT); + + mock.match(METHOD_NOARG_NAME); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMatchNoneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); - mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); + mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub); mockCallFactory.setupCreateCallSignature(mockCallMatch); mockCallableAddable.addExpectedAddMatch(mockCallMatch); - mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); + mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); - mock.matchAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT); + mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT); Verifier.verifyObject(this); mockCallableAddable.verifyExpectations(); @@ -256,6 +271,37 @@ mockCallableAddable.verifyExpectations(); } + public void testMatchOneAndVoid() throws Throwable { + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub); + mockCallFactory.setupCreateCallSignature(mockCallMatch); + mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch); + mockCallFactory.setupCreateCallExpectation(mockExpectedCall); + + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + + mock.match(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testMatchOneAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub); + mockCallFactory.setupCreateCallSignature(mockCallMatch); + + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); + + mock.matchAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + public void testMatchOneAndThrow() throws Throwable { mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); @@ -271,46 +317,47 @@ mockCallableAddable.verifyExpectations(); } - public void testMatchManyAndThrow() throws Throwable { - mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); - mockCallFactory.setupCreateThrowStub(mockThrowStub); - mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); + public void testMatchManyAndVoid() throws Throwable { + mockCallFactory.setExpectedCreateVoidStubCalls(1); + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub); mockCallFactory.setupCreateCallSignature(mockCallMatch); + mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch); + mockCallFactory.setupCreateCallExpectation(mockExpectedCall); mockCallableAddable.addExpectedAddMatch(mockCallMatch); - mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); - mock.matchAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); + mock.match(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); Verifier.verifyObject(this); mockCallableAddable.verifyExpectations(); } - - public void testMatchOneAndReturn() throws Throwable { - mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT); + + public void testMatchManyAndReturn() throws Throwable { + mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); - mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub); + mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); mockCallFactory.setupCreateCallSignature(mockCallMatch); mockCallableAddable.addExpectedAddMatch(mockCallMatch); - mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); + mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); - mock.matchAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT); + mock.matchAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT); Verifier.verifyObject(this); mockCallableAddable.verifyExpectations(); } - - public void testMatchNoneAndReturn() throws Throwable { - mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT); - mockCallFactory.setupCreateReturnStub(mockReturnStub); - mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub); + + public void testMatchManyAndThrow() throws Throwable { + mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); mockCallFactory.setupCreateCallSignature(mockCallMatch); mockCallableAddable.addExpectedAddMatch(mockCallMatch); - mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); + mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); - mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT); + mock.matchAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); Verifier.verifyObject(this); mockCallableAddable.verifyExpectations(); |
From: Steve F. <sm...@us...> - 2003-07-02 03:46:21
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv18960/src/core/com/mockobjects/dynamic Modified Files: Mock.java Log Message: Added match() methods for methods that return void. Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Mock.java 12 Jun 2003 22:45:12 -0000 1.23 +++ Mock.java 2 Jul 2003 03:46:18 -0000 1.24 @@ -168,6 +168,26 @@ calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createThrowStub(exception)))); } + public void match(String methodName) { + match(methodName, C.NO_ARGS); + } + + public void match(String methodName, Object singleEqualArg) { + match(methodName, createConstraintMatcher(singleEqualArg)); + } + + public void match(String methodName, int singleEqualArg) { + match(methodName, new Integer(singleEqualArg)); + } + + public void match(String methodName, boolean singleEqualArg) { + match(methodName, new Boolean(singleEqualArg)); + } + + public void match(String methodName, ConstraintMatcher args) { + calls.addMatch(callFactory.createCallSignature(methodName, args, callFactory.createVoidStub())); + } + public void matchAndReturn(String methodName, Object result) { this.matchAndReturn(methodName, C.NO_ARGS, result); } @@ -272,4 +292,5 @@ */ public void expectNotCalled(String methodName) { } + } |
From: Steve F. <st...@m3...> - 2003-07-02 03:21:31
|
Tim Mackinnon wrote: > Not sure why the tests would be pain, isn't just a case of adding the two > following tests to mock? > > public void testProxyToStringWithNoToStringExpectation() throws Exception { > mockCallableAddable.addExpectedHasCall("toString", METHOD_NOARG_ARGS); > mockCallableAddable.setupHasCall(false); > > assertEquals("Should get mock name", MOCK_NAME, mock.proxy().toString()); > mock.verify(); > } no. If the methods are added as defaults on Mock, during construction, you have to fix the other tests so that calls to MockCallFactory.createReturnStub() don't fail because it's short of a return value. Which suggests that the callFactory is overspecified. > There is a smell, in some of the other tests because the CallFactory is a > bit over-used, it generates several types of stubs decorating each other (so > you have to set each of them up). I would say that this should be better > encapsulated so you just set one expectation on the mockCallFactory - the > tests would simplify and your code would be better. Exactly. S. |
From: Tim M. <tim...@po...> - 2003-07-02 00:45:35
|
Not sure why the tests would be pain, isn't just a case of adding the two following tests to mock? public void testProxyToStringWithNoToStringExpectation() throws Exception { mockCallableAddable.addExpectedHasCall("toString", METHOD_NOARG_ARGS); mockCallableAddable.setupHasCall(false); assertEquals("Should get mock name", MOCK_NAME, mock.proxy().toString()); mock.verify(); } public void testProxyToStringWithToStringExpectation() throws Exception { final String result = "configured result"; mockCallableAddable.addExpectedHasCall("toString", METHOD_NOARG_ARGS); mockCallableAddable.setupHasCall(true); mockCallableAddable.setupCall(result); assertEquals("Should get mock name", MOCK_NAME, mock.proxy().toString()); mock.verify(); } Thus - the mockCallableAddable (and I will admit its badly named -the name ideas was you can send calls to it but also add expectations and matches) - would expect to be asked if it has a "toString" call (i.e. a call to a new method called HasCall on CallableAddable), we configure the mock either true or false, in the true case you also have to setup a result that you assert should be true. Its not a big deal. There is a smell, in some of the other tests because the CallFactory is a bit over-used, it generates several types of stubs decorating each other (so you have to set each of them up). I would say that this should be better encapsulated so you just set one expectation on the mockCallFactory - the tests would simplify and your code would be better. Its simply the tests reflecting a poor design decision made at 4:30pm on day one. Actually it was a good decision then, becuase it meant we moved on - we have not been good at refactoring the code - but this was a spare time coding excercise. Tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Steve Freeman > Sent: 01 July 2003 23:58 > To: moc...@li... > Subject: Re: [MO-java-dev] DynaMock proxy toString issue > > > chris cottee wrote: > > I think there need to be some functional tests for Mock as well as the > > mocked unit tests. Functional tests > > are (in this case) better at expressing the intent of the code since > > they are effectively examples of usage. > > Agreed. We've talked about writing some fit tests that would apply to > both the java and C# versions. > > I'm beginning to find the current unit tests problematic too. I've been > trying to add Chris's idea of just adding some default matches for > methods like toString() and it's a right pain (and shouldn't necessarily > be visible in the tests). > > Chris are you implementing all this in 0.09. If so, I'll stop. Also, I > suggest you break up your proposed additional unit tests into 4 specific > tests, rather than one big one. > > Steve > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 |
From: Tim M. <tim...@po...> - 2003-07-02 00:11:20
|
The functional test is in examples (the package name probably bad). This was the functional test we used to drive the thing. It may be slightly incomplete but it shows most of the usage. You are correct that its missing an example of using matchAndReturn twice - it does show expectAndReturn twice however. > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > chris cottee > Sent: 01 July 2003 23:46 > To: Tim Mackinnon; moc...@li...; Nat Pryce > Subject: Re: [MO-java-dev] DynaMock proxy toString issue > > > I think there need to be some functional tests for Mock as well as the > mocked unit tests. Functional tests > are (in this case) better at expressing the intent of the code since they > are effectively examples of usage. > > For instance what is the intended behaviour of the Mock if you setup a > match and then call it more than once? How about for OrderedMock? > > I have to look at the tests for CallSequence and CallBag (in the 0.09 > release) to figure this out which means that I have to > read the implementation to tell that Mock uses these things and I can't > tell from the tests what the intent is, it is easier to read the code. I > chose this example because the test is easy if you have setup a mock and > proxy > > public void testMatchAndReturn() throws Throwable { > mock.matchAndReturn(METHOD_NOARGANDRETURN_NAME, > METHOD_NOARGANDRETURN_RESULT); > mock.verify(); > for (int i = 0; i < 4; i++) { > assertEquals("should get expected result every time:" + i, > METHOD_NOARGANDRETURN_RESULT, proxy.noArgMethod()); > } > > mock.verify(); > } > And it passes on Mock and fails on OrderedMock in both 0.09 versions and > Nat's branch. Now I don't know if OrderedMock > is supposed to treat matches differently to Mock or not and I really have > no way of telling. My feeling is that this is a > bug and that the only difference between Mock and OrderedMock > should be the > way they handle the order of expected calls, in all other ways the > behaviour should be identical. > > Is this right? > Chris. > > > > > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 |
From: Tim M. <tim...@po...> - 2003-07-01 23:35:52
|
Just as small comment, I would say the unit tests for dynamock haven't been through the ringer with different people so they probably need a bit of refactoring (not that this is an excuse). That said - what Chris is trying to do shouldn't be too hard if he paired with either nat or myself (you are trying to do this without a knowledge spread which is understandably difficult especially as dynamock was written in essentially two intense days by only two people). I will say we made some quite radical changes during the two days, and a bit afterwards and the tests weren't too hard to modify. So Yes - remembering how the old mocks work is crucial to reading the tests - we probably should back port the old mocks to the new format (but no-one has the time). I will restate that at the time, initially we didn't do mock style tests for dynamock and they really stalled our development (I distinctly remember this). You will also probably need MockMaker if you are playing around with the interfaces so you can easily regenerate the old mocks (doing it by hand is very time consuming). Functional testing is not really the answer (definitely its not a replacement for unit tests, i see too many people write fucntional tests, or very high level unit tests and then they feel they have the justification to hack for several hours getting their "test first test" to run. Its bad news!). There is a simple functional test for dynamock, its in the examples package, called SimpleServletTest - it was used as our way of expressing features we wanted to work, we then dropped down to unit test to get those features to work. It does have the downside that its servlet based, but it was the quickest example I could think of to show nat all of the types of interactions we had to deal with (and it drove the matchAndReturn syntax). Tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Steve Freeman > Sent: 01 July 2003 23:58 > To: moc...@li... > Subject: Re: [MO-java-dev] DynaMock proxy toString issue > > > chris cottee wrote: > > I think there need to be some functional tests for Mock as well as the > > mocked unit tests. Functional tests > > are (in this case) better at expressing the intent of the code since > > they are effectively examples of usage. > > Agreed. We've talked about writing some fit tests that would apply to > both the java and C# versions. > > I'm beginning to find the current unit tests problematic too. I've been > trying to add Chris's idea of just adding some default matches for > methods like toString() and it's a right pain (and shouldn't necessarily > be visible in the tests). > > Chris are you implementing all this in 0.09. If so, I'll stop. Also, I > suggest you break up your proposed additional unit tests into 4 specific > tests, rather than one big one. > > Steve > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 |
From: Steve F. <st...@m3...> - 2003-07-01 22:58:11
|
chris cottee wrote: > I think there need to be some functional tests for Mock as well as the > mocked unit tests. Functional tests > are (in this case) better at expressing the intent of the code since > they are effectively examples of usage. Agreed. We've talked about writing some fit tests that would apply to both the java and C# versions. I'm beginning to find the current unit tests problematic too. I've been trying to add Chris's idea of just adding some default matches for methods like toString() and it's a right pain (and shouldn't necessarily be visible in the tests). Chris are you implementing all this in 0.09. If so, I'll stop. Also, I suggest you break up your proposed additional unit tests into 4 specific tests, rather than one big one. Steve |
From: chris c. <drc...@ya...> - 2003-07-01 22:45:48
|
I think there need to be some functional tests for Mock as well as the mocked unit tests. Functional tests are (in this case) better at expressing the intent of the code since they are effectively examples of usage. For instance what is the intended behaviour of the Mock if you setup a match and then call it more than once? How about for OrderedMock? I have to look at the tests for CallSequence and CallBag (in the 0.09 release) to figure this out which means that I have to read the implementation to tell that Mock uses these things and I can't tell from the tests what the intent is, it is easier to read the code. I chose this example because the test is easy if you have setup a mock and proxy public void testMatchAndReturn() throws Throwable { mock.matchAndReturn(METHOD_NOARGANDRETURN_NAME, METHOD_NOARGANDRETURN_RESULT); mock.verify(); for (int i = 0; i < 4; i++) { assertEquals("should get expected result every time:" + i, METHOD_NOARGANDRETURN_RESULT, proxy.noArgMethod()); } mock.verify(); } And it passes on Mock and fails on OrderedMock in both 0.09 versions and Nat's branch. Now I don't know if OrderedMock is supposed to treat matches differently to Mock or not and I really have no way of telling. My feeling is that this is a bug and that the only difference between Mock and OrderedMock should be the way they handle the order of expected calls, in all other ways the behaviour should be identical. Is this right? Chris. |
From: Nat P. <nat...@b1...> - 2003-07-01 08:24:01
|
From: "Tim Mackinnon" <tim...@po...> > > Alternatively I would suggest not using mocks to test Mock, I don't think > > you need to. I think plain old fashioned exo-testing would cut it. > > I can comment that Nat and I tried that when we redid the current version > test first - and the tests we were writing were very hard and not driving > our design. One problem we found with exo-testing is that it is suffers from combinatorial explosion. The number of combinations of all possible decorators and stubs is HUGE! For example, there are three types of stubs in v0.09 (and I've added another), decorators to match method name, arguments and check an expectated call, and the argument check can take different numbers and types of constraint. The new dynamic mock is designed in terms of collaborating, pluggable objects. It's situations like this that mocks are perfect for because exo-testing alone becomes very difficult. Unfortunately, it does lead to mocks-testing-mocks headaches. Hopefully the documentation on the mockobjects Wiki and the examples in the source distribution will be helpful. Both need further work. > We also found that using mock maker was a big time saver too (hand > coding some of our interface changes was just too painful as well). Again, dynamic mocks would help here, but using the dynamock library to test itself is just too meta, even for my deranged tastes! Cheers, Nat. |
From: Tim M. <tim...@po...> - 2003-06-30 22:53:07
|
> Alternatively I would suggest not using mocks to test Mock, I don't think > you need to. I think plain old fashioned exo-testing would cut it. This > would have the advantage of providing examples of usage and > decoupling the > test from implementation, making it simpler to integrate with Nat's I can comment that Nat and I tried that when we redid the current version test first - and the tests we were writing were very hard and not driving our design. We took the stance that we would use the old mock implementations to help, and this gave us a huge productivity boost (we decided not to use dynamics to test dynamics as that is a brain bender) - honest. We also found that using mock maker was a big time saver too (hand coding some of our interface changes was just too painful as well). Tim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 |
From: chris c. <drc...@ya...> - 2003-06-30 08:03:33
|
On Sat, 28 Jun 2003 20:19:36 +0100, Nat Pryce <nat...@b1...> wrote: > From: "Steve Freeman" <st...@m3...> >> As per solutions, you might want to look at the branch for Nat's latest >> version. Some of the names have changed. > > I think the proposed solution is very neat, and could probably also be > used > to move the checks for and processing of "magic" calls from the Mock > class > into Callable objects. > > However, how would it work with the OrderedMock class? > > Cheers, > Nat. > > > I raised the question because I wondered what people thought about changing the contract of a proxy: that it would always respond to toString unless you explicitly told it not to. It had crossed my mind that this might cause trouble with OrderedMock but I think that handling the call to toString by adding a match in the constructor is an implementation detail really, very nice if it can be made to work but if we have to do something clunky then so be it. I'd want to think about what matching in an OrderedMock should mean though: should you have to match in the correct order? My instinct is no, matching should be allowed in any order.Any thoughts on that? Anyway given this broadly positive response (-no-one has said it's a *very* stupid idea yet) I shall knock something up on the train to work, in particular tests of Mock and OrderedMock. Cheers, Chris |
From: chris c. <drc...@ya...> - 2003-06-30 08:02:45
|
Hi Steve, here is the failing test of the DynamicUtil in DynamicUtilTest public void testProxyToString() throws Exception { Mock mockDummyInterface = new Mock(DummyInterface.class, "an example"); DummyInterface proxyDummyInterface = (DummyInterface) mockDummyInterface.proxy(); assertEquals("should get correct string", "an example", DynamicUtil.proxyToString(proxyDummyInterface)); assertEquals("should get correct string for array", "[<an example>]", DynamicUtil.proxyToString(new DummyInterface[] { proxyDummyInterface })); List list = new ArrayList(); list.add(proxyDummyInterface); assertEquals("should get correct string for list", "[an example]", DynamicUtil.proxyToString(list)); class MyClass { DummyInterface aField; MyClass(DummyInterface aDummy) { aField = aDummy; } public String toString() { return "myClass contains:" + aField; } } MyClass myClass = new MyClass(proxyDummyInterface); assertEquals("should get string back from contained field", "myClass contains:", DynamicUtil.proxyToString(myClass)); } The first two asserts pass, the second two do not. The other thing I would like to do is refactor the MockTest. I want to do this because I tried out my one line change to Mock and it made every single test fail. In trying to fix them I noticed that there is a lot of duplication in the test and that some small changes to the CallFactory interface would make the test a great deal simpler. For instance replacing this method in Mock public void expect(String methodName, ConstraintMatcher args) { calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createVoidStub()))); } with something like this: public void expect(String methodName, ConstraintMatcher args) { calls.addExpect(callFactory.createCallExpectation(methodName, args)); } and having changed the DefaultCallFactory to handle it would make it a lot simpler to setup the expectations in the MockTest. Alternatively I would suggest not using mocks to test Mock, I don't think you need to. I think plain old fashioned exo-testing would cut it. This would have the advantage of providing examples of usage and decoupling the test from implementation, making it simpler to integrate with Nat's changes. Chris |
From: Tim M. <tim...@po...> - 2003-06-29 22:57:14
|
Yes its missing in 0.09 - we should add this into the current head version (its trivial to do). Francois subclass Mock and add the sugar if you need it immediately. I would also advocate adding Chris' toString suggestion as well. In the meantime - while there is some push for Nat's branch going on - Sorry I'm not yet convinced by the direction. I'm particularly not convinced by adding additional names like matchNameAndReturn, nor the explosion of all generated types. There is a lot of discussion required to make that branch acceptable. Tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Francois Beausoleil > Sent: 29 June 2003 02:48 > To: moc...@li... > Subject: [MO-java-dev] How to match and not return ? > > > Hi ! > > I need functionnality equivalent to expect(String, Object), but for > match(). Currently, in 0.09, there are matchAndReturn methods, but no > simple match(String). In this specific test instance, it does not matter > how many times I call method X as it has been asserted elsewhere that the > correct number of calls is made. > > Instead of: > mock.expect("eat", C.ANY_ARGS); > > I would like: > mock.match("eat", C.ANY_ARGS); > > This is something like the nice mock feature I spoke about a few weeks > back. What I want is no exception if I call the method 100 times or 10 > times. > > Thanks ! > François > -- > Francois Beausoleil > Developer of Java Gui Builder > http://jgb.sourceforge.net/ > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 |
From: Nat P. <nat...@b1...> - 2003-06-29 08:59:04
|
That method is missing in 0.09. In my branch there is a method matchVoid( String, Object ) [and overloads] that does what you want. However, I would not advise using that branch in a production project. Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Francois Beausoleil" <fb...@us...> To: <moc...@li...> Sent: Sunday, June 29, 2003 2:47 AM Subject: [MO-java-dev] How to match and not return ? Hi ! I need functionnality equivalent to expect(String, Object), but for match(). Currently, in 0.09, there are matchAndReturn methods, but no simple match(String). In this specific test instance, it does not matter how many times I call method X as it has been asserted elsewhere that the correct number of calls is made. Instead of: mock.expect("eat", C.ANY_ARGS); I would like: mock.match("eat", C.ANY_ARGS); This is something like the nice mock feature I spoke about a few weeks back. What I want is no exception if I call the method 100 times or 10 times. Thanks ! François -- Francois Beausoleil Developer of Java Gui Builder http://jgb.sourceforge.net/ ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Francois B. <fb...@us...> - 2003-06-29 01:47:48
|
Hi ! I need functionnality equivalent to expect(String, Object), but for match(). Currently, in 0.09, there are matchAndReturn methods, but no simple match(String). In this specific test instance, it does not matter how many times I call method X as it has been asserted elsewhere that the correct number of calls is made. Instead of: mock.expect("eat", C.ANY_ARGS); I would like: mock.match("eat", C.ANY_ARGS); This is something like the nice mock feature I spoke about a few weeks back. What I want is no exception if I call the method 100 times or 10 times. Thanks ! Fran=E7ois -- Francois Beausoleil Developer of Java Gui Builder http://jgb.sourceforge.net/ |
From: Nat P. <nat...@b1...> - 2003-06-28 19:23:07
|
From: "Steve Freeman" <st...@m3...> > As per solutions, you might want to look at the branch for Nat's latest > version. Some of the names have changed. I think the proposed solution is very neat, and could probably also be used to move the checks for and processing of "magic" calls from the Mock class into Callable objects. However, how would it work with the OrderedMock class? Cheers, Nat. |
From: Steve F. <st...@m3...> - 2003-06-28 00:39:30
|
Would you care to write some failing tests? As per solutions, you might want to look at the branch for Nat's latest version. Some of the names have changed. S. chris cottee wrote: > Hi all, > there's a bug/limitation in the DynamicUtil.proxyToString method > that I'd like to fix. It can't handle proxies in collections or where > the toString is called indirectly because the proxy is a field in some > other class. The reason this is irritating is that the > DynamicUtil.proxyToString method is used in displaying constraints when > call has not been matched. The result of this limitation is that if you > have an unexpected call and some other call has proxies in the > constraints indirectly then the failure message is masked by an > unexpected call to toString. > a code snippet might make this clearer: > ... > Action proxyAction1 = (Action) mockAction1.proxy(); > Action proxyAction2 = (Action) mockAction2.proxy(); > Collection listOfActions = new TestVector(proxyAction1, proxyAction2); > > mockConfigVersion.expectAndReturn("applyToSubConfigs", > C.eq(versionRepository, listOfActions), true); > ... > > The DynamicUtil.proxyToString will not be able to display the > listOfActions properly so any failed expectation on mockConfigVersion > will be hidden by an unexpected call to "toString" on mockAction1. Lots > of time will then be spent stepping > through the code to find which call went wrong. This has happened to me > often enough to be a nuisance. > > The solution I propose is to not use the DynamicUtil to handle the > toString and instead make the default behaviour of a proxy toString call > to be to return the name of the mock. This would be overriden if an > expectation was set on the toString or you could use the reset method to > clear it. The reason I think it should be done this way is that I can't > see how the DynamicUtil can be made to handle all the possible ways that > the toString might be called on the proxy. Also I think it is unusual to > need to set an expectation on toString (I have never done it other than > to get around this bug) but less unusual to use proxies inside other > objects which are used in constraints. The way I had thought of > implementing this behaviour is to add a match of toString into the > callableAddable of the Mock on construction. > > Any thoughts? > Chris > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: chris c. <drc...@ya...> - 2003-06-27 23:21:39
|
Hi all, there's a bug/limitation in the DynamicUtil.proxyToString method that I'd like to fix. It can't handle proxies in collections or where the toString is called indirectly because the proxy is a field in some other class. The reason this is irritating is that the DynamicUtil.proxyToString method is used in displaying constraints when call has not been matched. The result of this limitation is that if you have an unexpected call and some other call has proxies in the constraints indirectly then the failure message is masked by an unexpected call to toString. a code snippet might make this clearer: ... Action proxyAction1 = (Action) mockAction1.proxy(); Action proxyAction2 = (Action) mockAction2.proxy(); Collection listOfActions = new TestVector(proxyAction1, proxyAction2); mockConfigVersion.expectAndReturn("applyToSubConfigs", C.eq(versionRepository, listOfActions), true); ... The DynamicUtil.proxyToString will not be able to display the listOfActions properly so any failed expectation on mockConfigVersion will be hidden by an unexpected call to "toString" on mockAction1. Lots of time will then be spent stepping through the code to find which call went wrong. This has happened to me often enough to be a nuisance. The solution I propose is to not use the DynamicUtil to handle the toString and instead make the default behaviour of a proxy toString call to be to return the name of the mock. This would be overriden if an expectation was set on the toString or you could use the reset method to clear it. The reason I think it should be done this way is that I can't see how the DynamicUtil can be made to handle all the possible ways that the toString might be called on the proxy. Also I think it is unusual to need to set an expectation on toString (I have never done it other than to get around this bug) but less unusual to use proxies inside other objects which are used in constraints. The way I had thought of implementing this behaviour is to add a match of toString into the callableAddable of the Mock on construction. Any thoughts? Chris |
From: Steve F. <sm...@us...> - 2003-06-27 16:08:44
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory sc8-pr-cvs1:/tmp/cvs-serv8236/src/core/com/mockobjects Modified Files: Tag: Nat_reworks_dynamics_from_0_09 ExpectationSegment.java ReturnObjectBag.java ReturnObjectList.java ExpectationList.java ExpectationMap.java ExpectationSet.java MapEntry.java ReturnValues.java ExpectationCollection.java Log Message: Further changes from Nat Index: ExpectationSegment.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ExpectationSegment.java,v retrieving revision 1.1 retrieving revision 1.1.8.1 diff -u -r1.1 -r1.1.8.1 --- ExpectationSegment.java 29 Jul 2001 19:50:24 -0000 1.1 +++ ExpectationSegment.java 27 Jun 2003 16:03:03 -0000 1.1.8.1 @@ -1,6 +1,6 @@ package com.mockobjects; -import com.mockobjects.util.*; +import com.mockobjects.util.AssertMo; public class ExpectationSegment extends AbstractExpectation { private String myExpectedSegment; Index: ReturnObjectBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ReturnObjectBag.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- ReturnObjectBag.java 23 Apr 2003 11:52:46 -0000 1.4 +++ ReturnObjectBag.java 27 Jun 2003 16:03:03 -0000 1.4.2.1 @@ -1,11 +1,10 @@ package com.mockobjects; -import com.mockobjects.ReturnObjectList; -import com.mockobjects.Verifiable; +import java.util.Hashtable; +import java.util.Iterator; + import com.mockobjects.util.AssertMo; import com.mockobjects.util.Null; - -import java.util.*; /** * The ReturnObjectBag is a map containing instances of ReturnObjectList. Index: ReturnObjectList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ReturnObjectList.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- ReturnObjectList.java 23 Apr 2003 11:52:46 -0000 1.5 +++ ReturnObjectList.java 27 Jun 2003 16:03:03 -0000 1.5.2.1 @@ -1,8 +1,8 @@ package com.mockobjects; -import com.mockobjects.util.AssertMo; - import java.util.Vector; + +import com.mockobjects.util.AssertMo; /** * <p>This class allows a list of objects to be setup which can be used whilst.The Index: ExpectationList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ExpectationList.java,v retrieving revision 1.2 retrieving revision 1.2.6.1 diff -u -r1.2 -r1.2.6.1 --- ExpectationList.java 22 Aug 2002 18:03:49 -0000 1.2 +++ ExpectationList.java 27 Jun 2003 16:03:03 -0000 1.2.6.1 @@ -1,6 +1,8 @@ package com.mockobjects; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; + import junit.framework.Assert; public class ExpectationList extends AbstractExpectationCollection { Index: ExpectationMap.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ExpectationMap.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- ExpectationMap.java 14 May 2003 14:59:34 -0000 1.2 +++ ExpectationMap.java 27 Jun 2003 16:03:03 -0000 1.2.2.1 @@ -1,6 +1,6 @@ package com.mockobjects; -import java.util.*; +import java.util.HashMap; public class ExpectationMap implements Expectation, Verifiable { private HashMap myEntries; Index: ExpectationSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ExpectationSet.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- ExpectationSet.java 14 May 2003 14:59:34 -0000 1.3 +++ ExpectationSet.java 27 Jun 2003 16:03:03 -0000 1.3.2.1 @@ -1,9 +1,9 @@ package com.mockobjects; -import com.mockobjects.util.AssertMo; - import java.util.Collection; import java.util.HashSet; + +import com.mockobjects.util.AssertMo; public class ExpectationSet extends AbstractExpectationCollection { private HashSet myExpectedItems = new HashSet(); Index: MapEntry.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/MapEntry.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- MapEntry.java 14 May 2003 14:59:34 -0000 1.3 +++ MapEntry.java 27 Jun 2003 16:03:03 -0000 1.3.2.1 @@ -1,9 +1,9 @@ package com.mockobjects; -import com.mockobjects.util.Null; - import java.lang.reflect.Array; import java.util.Map; + +import com.mockobjects.util.Null; /** * A public MapEntry data type that can be used where the Map.Entry interface is required Index: ReturnValues.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ReturnValues.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- ReturnValues.java 18 May 2003 20:59:36 -0000 1.2 +++ ReturnValues.java 27 Jun 2003 16:03:03 -0000 1.2.2.1 @@ -1,7 +1,9 @@ package com.mockobjects; -import junit.framework.*; -import java.util.*; +import java.util.Collection; +import java.util.Vector; + +import junit.framework.AssertionFailedError; /** * Sequence values as required by MockMaker Index: ExpectationCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ExpectationCollection.java,v retrieving revision 1.2 retrieving revision 1.2.8.1 diff -u -r1.2 -r1.2.8.1 --- ExpectationCollection.java 27 Aug 2001 01:14:31 -0000 1.2 +++ ExpectationCollection.java 27 Jun 2003 16:03:03 -0000 1.2.8.1 @@ -1,6 +1,7 @@ package com.mockobjects; -import java.util.*; +import java.util.Enumeration; +import java.util.Iterator; /** * An <EM>ExpectationCollection</EM> is an expectation that supports multiple values, such as lists |
From: Steve F. <sm...@us...> - 2003-06-27 16:05:54
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/tools In directory sc8-pr-cvs1:/tmp/cvs-serv8236/src/core/com/mockobjects/tools Modified Files: Tag: Nat_reworks_dynamics_from_0_09 Boxer.java Log Message: Further changes from Nat Index: Boxer.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/tools/Attic/Boxer.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- Boxer.java 26 Jun 2003 17:32:48 -0000 1.1.2.2 +++ Boxer.java 27 Jun 2003 16:03:03 -0000 1.1.2.3 @@ -10,8 +10,14 @@ import java.lang.reflect.Modifier; import java.util.*; +/** Warning: this tool generates code containing a potentially dangerous pun + */ public class Boxer { + static boolean parameterShouldBeBoxed( Class type ) { + return type == Object.class; + } + static final String INDENT1 = " "; static final String INDENT2 = INDENT1+INDENT1; @@ -163,6 +169,8 @@ for( Iterator oi = overloads.iterator(); oi.hasNext(); ) { Class[] arguments = (Class[])oi.next(); + expandedOverloads.add(arguments); + for( Iterator bi = BOXES.keySet().iterator(); bi.hasNext(); ) { Class primitiveType = (Class)bi.next(); @@ -176,8 +184,27 @@ return expandedOverloads; } - static List listOverloadsForMethod( Class[] parameterTypes ) { + static void removeUnnecessaryOverloads( Method m, List overloads ) { + ListIterator i = overloads.listIterator(); + + filteringMethods: while( i.hasNext() ) { + Class[] overloadedParameterTypes = (Class[])i.next(); + + try { + m.getDeclaringClass().getMethod( m.getName(), + overloadedParameterTypes ); + i.remove(); + } + catch( NoSuchMethodException ex ) { + continue filteringMethods; + } + } + } + + static List listOverloadsForMethod( Method m ) { + Class[] parameterTypes = m.getParameterTypes(); List overloads = new ArrayList(); + overloads.add(parameterTypes); for( int i = 0; i < parameterTypes.length; i++ ) { @@ -186,7 +213,9 @@ } } - return overloads; + removeUnnecessaryOverloads( m, overloads ); + + return overloads; } static void generateBoxExpression( PrintWriter out, @@ -219,7 +248,7 @@ out.print( m.getDeclaringClass().getName() ); out.print("."); } else { - out.print("super."); + out.print("super."); } out.print(m.getName()); out.print("("); @@ -227,7 +256,7 @@ for( int i = 0; i < originalParameterTypes.length; i++ ) { if( i > 0 ) out.print(", "); - if( parameterShouldBeBoxed(originalParameterTypes[i]) ) { + if( originalParameterTypes[i] != overloadedParameterTypes[i] ) { generateBoxExpression( out, overloadedParameterTypes[i], parameterName(i) ); } else { @@ -238,10 +267,6 @@ out.println(");"); } - static boolean parameterShouldBeBoxed( Class type ) { - return type == Object.class; - } - static void generateOverloadedMethod( PrintWriter out, Method m, Class[] overloadedParameterTypes ) @@ -268,7 +293,7 @@ static void generateOverloadsForMethod( PrintWriter out, Method m ) { - List overloads = listOverloadsForMethod( m.getParameterTypes() ); + List overloads = listOverloadsForMethod( m ); if( overloads.size() > 1 ) { for( Iterator i = overloads.iterator(); i.hasNext(); ) { @@ -295,9 +320,10 @@ Class template, String className ) { out.println( "// WARNING: DO NOT EDIT" ); - out.println( "// This file was automatically generated by the Boxer " - + "(floats like a butterfly, strings like a bee)" ); - out.println( "// Generated on " + (new Date()) ); + out.println( "// This file was automatically generated by the Boxer" ); + out.println( "// \"Float like a butterfly, string like a bee.\"" ); + out.println( "// Generated on " + (new Date()) + " by " + + System.getProperty("user.name") ); out.println(); if( classHasPackage(className) ) { |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects In directory sc8-pr-cvs1:/tmp/cvs-serv8319/src/core/test/mockobjects Modified Files: Tag: Nat_reworks_dynamics_from_0_09 TestAssertMo.java TestReturnValue.java TestExpectationCounter.java TestMapEntry.java TestExpectationCollection.java AllTests.java TestReturnObjectBag.java TestExpectationDoubleValue.java TestExpectationValue.java AutoTestSuite.java TestExpectationMap.java TestVerifier.java Log Message: Further changes from Nat Index: TestAssertMo.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestAssertMo.java,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- TestAssertMo.java 27 Oct 2002 22:24:13 -0000 1.3 +++ TestAssertMo.java 27 Jun 2003 16:03:20 -0000 1.3.6.1 @@ -1,12 +1,13 @@ package test.mockobjects; -import com.mockobjects.util.AssertMo; -import com.mockobjects.util.TestCaseMo; +import java.util.Vector; + import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestSuite; -import java.util.Vector; +import com.mockobjects.util.AssertMo; +import com.mockobjects.util.TestCaseMo; public class TestAssertMo extends TestCaseMo { private static final Class THIS = TestAssertMo.class; Index: TestReturnValue.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestReturnValue.java,v retrieving revision 1.4 retrieving revision 1.4.4.1 diff -u -r1.4 -r1.4.4.1 --- TestReturnValue.java 18 Mar 2003 14:28:18 -0000 1.4 +++ TestReturnValue.java 27 Jun 2003 16:03:20 -0000 1.4.4.1 @@ -1,8 +1,9 @@ package test.mockobjects; -import com.mockobjects.util.TestCaseMo; -import com.mockobjects.ReturnValue; import junit.framework.AssertionFailedError; + +import com.mockobjects.ReturnValue; +import com.mockobjects.util.TestCaseMo; public class TestReturnValue extends TestCaseMo { Index: TestExpectationCounter.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestExpectationCounter.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- TestExpectationCounter.java 21 Oct 2002 22:52:38 -0000 1.1 +++ TestExpectationCounter.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -1,8 +1,11 @@ package test.mockobjects; -import junit.framework.*; -import com.mockobjects.*; -import com.mockobjects.util.*; +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestSuite; + +import com.mockobjects.ExpectationCounter; +import com.mockobjects.util.TestCaseMo; /** * JUnit test case for TestExpectationCounter Index: TestMapEntry.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestMapEntry.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- TestMapEntry.java 21 Oct 2002 22:52:38 -0000 1.1 +++ TestMapEntry.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -1,9 +1,10 @@ package test.mockobjects; -import com.mockobjects.MapEntry; -import com.mockobjects.util.TestCaseMo; import junit.framework.Test; import junit.framework.TestSuite; + +import com.mockobjects.MapEntry; +import com.mockobjects.util.TestCaseMo; /** * JUnit test case for TestMapEntry Index: TestExpectationCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestExpectationCollection.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- TestExpectationCollection.java 21 Oct 2002 22:52:38 -0000 1.1 +++ TestExpectationCollection.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -1,9 +1,11 @@ package test.mockobjects; -import java.util.*; -import junit.framework.*; -import com.mockobjects.*; -import com.mockobjects.util.*; +import java.util.Vector; + +import junit.framework.AssertionFailedError; + +import com.mockobjects.ExpectationCollection; +import com.mockobjects.util.TestCaseMo; public abstract class TestExpectationCollection extends TestCaseMo { ExpectationCollection myExpectation; Index: AllTests.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/AllTests.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- AllTests.java 21 Oct 2002 22:52:38 -0000 1.1 +++ AllTests.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -1,9 +1,10 @@ package test.mockobjects; -import com.mockobjects.util.SuiteBuilder; -import com.mockobjects.util.TestCaseMo; import junit.framework.Test; import junit.framework.TestSuite; + +import com.mockobjects.util.SuiteBuilder; +import com.mockobjects.util.TestCaseMo; /** * JUnit test case for AllTests Index: TestReturnObjectBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestReturnObjectBag.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- TestReturnObjectBag.java 23 Apr 2003 11:52:47 -0000 1.4 +++ TestReturnObjectBag.java 27 Jun 2003 16:03:20 -0000 1.4.2.1 @@ -1,8 +1,9 @@ package test.mockobjects; -import com.mockobjects.util.TestCaseMo; -import com.mockobjects.ReturnObjectBag; import junit.framework.AssertionFailedError; + +import com.mockobjects.ReturnObjectBag; +import com.mockobjects.util.TestCaseMo; public class TestReturnObjectBag extends TestCaseMo { Index: TestExpectationDoubleValue.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestExpectationDoubleValue.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- TestExpectationDoubleValue.java 21 Oct 2002 22:52:38 -0000 1.1 +++ TestExpectationDoubleValue.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -1,8 +1,11 @@ package test.mockobjects; -import junit.framework.*; -import com.mockobjects.*; -import com.mockobjects.util.*; +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestSuite; + +import com.mockobjects.ExpectationDoubleValue; +import com.mockobjects.util.TestCaseMo; public class TestExpectationDoubleValue extends TestCaseMo { Index: TestExpectationValue.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestExpectationValue.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- TestExpectationValue.java 21 Oct 2002 22:52:38 -0000 1.1 +++ TestExpectationValue.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -1,8 +1,11 @@ package test.mockobjects; -import junit.framework.*; -import com.mockobjects.*; -import com.mockobjects.util.*; +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestSuite; + +import com.mockobjects.ExpectationValue; +import com.mockobjects.util.TestCaseMo; /** * JUnit test case for TestExpectationValue Index: AutoTestSuite.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/AutoTestSuite.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- AutoTestSuite.java 1 Nov 2002 15:37:28 -0000 1.1 +++ AutoTestSuite.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -2,7 +2,8 @@ import java.io.File; import java.lang.reflect.Modifier; import java.util.StringTokenizer; -import junit.framework.*; + +import junit.framework.TestSuite; /** A TestSuite containing all test classes found on the class path in a Index: TestExpectationMap.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestExpectationMap.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -u -r1.2 -r1.2.4.1 --- TestExpectationMap.java 24 Nov 2002 11:11:40 -0000 1.2 +++ TestExpectationMap.java 27 Jun 2003 16:03:20 -0000 1.2.4.1 @@ -1,9 +1,11 @@ package test.mockobjects; import junit.awtui.TestRunner; -import junit.framework.*; -import com.mockobjects.*; -import com.mockobjects.util.*; +import junit.framework.AssertionFailedError; + +import com.mockobjects.ExpectationMap; +import com.mockobjects.util.AssertMo; +import com.mockobjects.util.TestCaseMo; /** * JUnit test case for TestExpectationMap Index: TestVerifier.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestVerifier.java,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -u -r1.1 -r1.1.6.1 --- TestVerifier.java 21 Oct 2002 22:52:38 -0000 1.1 +++ TestVerifier.java 27 Jun 2003 16:03:20 -0000 1.1.6.1 @@ -1,11 +1,12 @@ package test.mockobjects; -import com.mockobjects.ExpectationValue; -import com.mockobjects.MockObject; -import com.mockobjects.util.TestCaseMo; import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestSuite; + +import com.mockobjects.ExpectationValue; +import com.mockobjects.MockObject; +import com.mockobjects.util.TestCaseMo; public class TestVerifier extends TestCaseMo { private static final Class THIS = TestVerifier.class; |