You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(151) |
Sep
(21) |
Oct
(6) |
Nov
(70) |
Dec
(8) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(47) |
Feb
(66) |
Mar
(23) |
Apr
(115) |
May
(24) |
Jun
(53) |
Jul
(10) |
Aug
(279) |
Sep
(84) |
Oct
(149) |
Nov
(138) |
Dec
(52) |
2003 |
Jan
(22) |
Feb
(20) |
Mar
(29) |
Apr
(106) |
May
(170) |
Jun
(122) |
Jul
(70) |
Aug
(64) |
Sep
(27) |
Oct
(71) |
Nov
(49) |
Dec
(9) |
2004 |
Jan
(7) |
Feb
(38) |
Mar
(3) |
Apr
(9) |
May
(22) |
Jun
(4) |
Jul
(1) |
Aug
(2) |
Sep
(2) |
Oct
|
Nov
(15) |
Dec
(2) |
2005 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(28) |
Jun
(3) |
Jul
(11) |
Aug
(5) |
Sep
(1) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2006 |
Jan
(8) |
Feb
(3) |
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Tim M. <tim...@po...> - 2003-05-13 23:45:37
|
> Ok thanks. Then I don't understand the difference between match*() and > expectAndReturn(). > This appears to be a stumbling block - its exactly what steve said.. but to repeat: expect means: "To consider obligatory; require: e.g. The school expects its pupils to be on time." match means: "One that is like another in one or more specified qualities: He is John's match for bravery." Thus - expectAndReturn means that it is obligatory for a certain call to happen. We specify that call (becuase java does method overloading). And we also specify the result of that call. matchAndReturn means that we just specify a value that is like what would happen if the real call had taken place. Note that we DONT set any expectation. If the call doesn't happen then no failure would happen. In other words, its a return without any expectation, however in Java you cannot create a method called "return(String name, Object return value)" as return is a reserved word. I can't think of any clearer way of saying this - does it help? Tim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003 |
From: Jeff M. <cus...@us...> - 2003-05-13 08:59:16
|
Update of /cvsroot/mockobjects/mockobjects-java In directory sc8-pr-cvs1:/tmp/cvs-serv15079 Modified Files: build.xml Log Message: Change jar names Index: build.xml =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/build.xml,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- build.xml 18 Mar 2003 14:28:43 -0000 1.32 +++ build.xml 13 May 2003 08:59:12 -0000 1.33 @@ -263,9 +263,9 @@ description="Generate jdk mockobjects jar"> <antcall target="_inner-jar"> <param name="jarfile.name" - value="${out.dir}/${jar.base.name}-jdk${jdk.version}.jar" /> + value="${out.dir}/${ant.project.name}-jdk${jdk.version}-${project.version}.jar" /> <param name="alt.jarfile.name" - value="${out.dir}/${alt.jar.base.name}-jdk${jdk.version}.jar" /> + value="${out.dir}/${ant.project.name}-alt-jdk${jdk.version}-${project.version}.jar" /> <param name="classes.dir" value="${jdk.classes}" /> </antcall> </target> @@ -276,9 +276,9 @@ description="Generate j2ee mockobjects jar"> <antcall target="_inner-jar"> <param name="jarfile.name" - value="${out.dir}/${jar.base.name}-j${jdk.version}-j2ee${j2ee.version}.jar" /> + value="${out.dir}/${ant.project.name}-jdk${jdk.version}-j2ee${j2ee.version}-${project.version}.jar" /> <param name="alt.jarfile.name" - value="${out.dir}/${alt.jar.base.name}-j${jdk.version}-j2ee${j2ee.version}.jar" /> + value="${out.dir}/${ant.project.name}-alt-jdk${jdk.version}-j2ee${j2ee.version}-${project.version}.jar" /> <param name="classes.dir" value="${j2ee.classes}" /> </antcall> </target> |
From: Vincent M. <vm...@pi...> - 2003-05-13 07:48:05
|
> -----Original Message----- > From: Tim Mackinnon [mailto:tim...@po...] > Sent: 13 May 2003 01:51 > To: Vincent Massol; Mockobjects-Java-Dev > Subject: RE: [MO-java-dev] First batch of questions on new Dynamic Mock > API > > Vincent - I think you seem to be panicing a bit. If you slow down a second > and look at the example you will find its not as bad as you think - there > are some useful comments in the actual test, and many of the parameters of > the methods you are calling have pretty explicit names. If you recall I > did > send you a long message documenting a lot of this stuff for you already, > however as I know you have a tight deadline I will repeat and clarify some > of this stuff so you can go faster. Thank you Tim and sorry. I did remember you sent me some long emails and I had stored it for when I would need it. I've tried to find it again and I found several emails where you describe the new mocks but either I've lost your email (shame on me!) or you did not go into the details I'm asking below as I could not find answers for that. > > > - what is now replacing the setupDefaultResult() method? > > Ex: mockRequest.setupDefaultResult(String.class, null); Any answer for that? > > > > - what's the difference between expect*() and match*()? It seems to me > > that the verify() will trigger a check to verify that the expect*() > > calls did actually happen whereas this would not be checked for the > > match*() ones? Is that correct? > > As Steve correctly pointed out - matchAndReturn does this. Does what? My questions is "simply what's the difference between expect*() and match*()"... > There is a > comment above these lines saying "// Set no expectations but answer a > value > for the specified method ". Yes, I have read this comment, hence my comment: " It seems to me that the verify() will trigger a check to verify that the expect*() calls did actually happen whereas this would not be checked for the match*() ones". My English may seem good but I don't think in the same way as you do guys so it may take me longer to understand something... please bear with me ;-) I'll complement my question: Is expect*() considered deprecated now? But then, why is it in the example... > Using ANY_ARGS as parameter constraint will > give > you the same behavior as you used to have, however using constraints can > give you hashtable like behavior for example. > > We did consider calling this method "stubAndReturn" however Steve felt it > didn't indicate the matching of the constraints very well. Yes, but expect*() also support matching constraints! I'm completely lost now :-) > > > - I've started looking at the > > src\examples\com\mockobjects\examples\dynamic\ SimpleServletTest.java > > example. It doesn't seem to be finished though and is missing some > > comments. But that would be the best help for those starting with the > > new dyna Mock API. Some questions: > > The example is an example of test first programming - e.g. the code > doesn't > actually have to work to have all the tests passing. Some of the real > implementations are left to the reader to implement them. > > > - I don't understand what's the purpose of the Timer class. Also, it > > wasn't in the testDoGetOldStyle() method. I think the Timer is muddying > > the example and should be removed altogether (unless there's something I > > don't understand!). > > The timer demonstrates an interface of an object that we expect to return > multiple results from a single method (the idea being, if we were going to > indicate the elapsed time of an operation this is ofent something). I > would > say the code in the Servlet gives this impression: > > writer.print("timer before:" + timer.getTime()); > mailSender.sendMail(subject, recipients, body); > writer.print("timer after:" + timer.getTime()); > ok, I think I get it now. A comment would be nice to explain this... Am I allowed to comment it? > > - What's the point of using the second parameter (i.e. "response") in: > > new OrderedMock(HttpServletResponse.class, "response"); > > As the name of the Parameter, "name" implies, it gives the mock a non > default name. A simple examination of the code makes this pretty obvious. I had looked at the code. Here it is: public class OrderedMock extends Mock { public OrderedMock(Class mockedClass) { this(mockedClass, mockNameFromClass(mockedClass)); } public OrderedMock(Class mockedClass, String name) { super(new DefaultCallFactory(), new CallSequence(),mockedClass, name); } } It doesn't tell anything to me.... and then if you have the time to follow the code, it calls the following constructor from the Mock class: public Mock(CallFactory callFactory, CallableAddable callableAddable, Class mockedClass, String name) { this.name = name; [...] Still without any comment! I would need to browse and scan the full code to understand what it does... > As the name of the Parameter, "name" implies, it gives the mock a non > default name. I mean I can see that. My question wasn't that. It was: > > - What's the point of using the second parameter (i.e. "response") in: > > new OrderedMock(HttpServletResponse.class, "response"); I can't figure out why we need to use "response" in this test sample! It doesn't seem to be used anywhere. I mean if we want to show how to use the second parameter we should demonstrate an example where we need this second parameter and explain why... > If > you have two objects of the same time (e.g. a Customer) - it is useful if > the error message is the same for both of them if one is causing the > failure. > ok, I get it now. Sorry but that wasn't obvious at all and would definitely require some javadoc or a good test... Problem is that the test would not show much unless you put comments in it as it is a runtime stuff... > As I am sure you are going to ask - MailSender is an example of an object > that takes an Object[] as a parameter. In Java its important to get this > one > right so that the error messages are clear. > > > - At some point, it says: " // Proposed enhancement to allow > > individual ordering". Is it done? As the http response is an ordered > > mock, isn't the implemented solution already doing the same as what is > > in the comments? > > No - the comment is right, its not implemented yet. MockHttpResponse > shouldn't actually be totally ordered as not all messages have to be in a > specific order, it really should just be a Mock with this type of code. Thus, if I understand correctly, there will be 2 solution for sequence calls: - use a OrderedMock but then all calls are supposed to be in the same order as the order in which we define the match*() (or expect*()) calls. - use expectBefore() when you simply need to order 2 calls Is that correct? > > > - Is the ConstraintMatcher[] supposed to be used internally or used by > > the user? It is not used in the sample servlet test. In other words, how > > would you translate the following (old style): > > > > mockRequest.expectVoid("setAttribute", new Constraint[] { > > C.eq("result"), C.IS_ANYTHING }); > > You can instantiate a FullConstraintMatcher if you want e.g.: > mockRequest.expect("setAttribute", new > FullConstraintMatcher(C.eq("result"), C.IS_ANYTHING)); > > but simpler still is: > mockRequest.expect("setAttribute", C.args(C.eq("result"), > C.IS_ANYTHING); ok Thanks -Vincent > > > Thanks > > No problem. > > Tim > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003 |
From: Vincent M. <vm...@pi...> - 2003-05-13 07:26:19
|
> -----Original Message----- > From: Steve Freeman [mailto:st...@m3...] > Sent: 12 May 2003 23:25 > To: Vincent Massol > Cc: 'Mockobjects-Java-Dev' > Subject: Re: [MO-java-dev] First batch of questions on new Dynamic Mock > API > > Vincent Massol wrote: > > I've started migrating my existing project to the new Dynamic Mock API > > and I have the following questions (maybe this could be the start of a > > migration guide or user guide?): > > > > - what is now replacing the setupDefaultResult() method? > > Ex: mockRequest.setupDefaultResult(String.class, null); > > > > - what's the difference between expect*() and match*()? It seems to me > > that the verify() will trigger a check to verify that the expect*() > > calls did actually happen whereas this would not be checked for the > > match*() ones? Is that correct? > > match tells the mock to return a result when it, um, matches a given > call. It's a bit more flexible than the old return code. Presumably > matching ANY would count as a default result although I don't think > we've tried that. Ok thanks. Then I don't understand the difference between match*() and expectAndReturn(). -Vincent > > > Tim, can you answer the rest? > > S. |
From: Tim M. <tim...@po...> - 2003-05-12 23:47:13
|
Vincent - I think you seem to be panicing a bit. If you slow down a second and look at the example you will find its not as bad as you think - there are some useful comments in the actual test, and many of the parameters of the methods you are calling have pretty explicit names. If you recall I did send you a long message documenting a lot of this stuff for you already, however as I know you have a tight deadline I will repeat and clarify some of this stuff so you can go faster. > - what is now replacing the setupDefaultResult() method? > Ex: mockRequest.setupDefaultResult(String.class, null); > > - what's the difference between expect*() and match*()? It seems to me > that the verify() will trigger a check to verify that the expect*() > calls did actually happen whereas this would not be checked for the > match*() ones? Is that correct? As Steve correctly pointed out - matchAndReturn does this. There is a comment above these lines saying "// Set no expectations but answer a value for the specified method ". Using ANY_ARGS as parameter constraint will give you the same behavior as you used to have, however using constraints can give you hashtable like behavior for example. We did consider calling this method "stubAndReturn" however Steve felt it didn't indicate the matching of the constraints very well. > - I've started looking at the > src\examples\com\mockobjects\examples\dynamic\ SimpleServletTest.java > example. It doesn't seem to be finished though and is missing some > comments. But that would be the best help for those starting with the > new dyna Mock API. Some questions: The example is an example of test first programming - e.g. the code doesn't actually have to work to have all the tests passing. Some of the real implementations are left to the reader to implement them. > - I don't understand what's the purpose of the Timer class. Also, it > wasn't in the testDoGetOldStyle() method. I think the Timer is muddying > the example and should be removed altogether (unless there's something I > don't understand!). The timer demonstrates an interface of an object that we expect to return multiple results from a single method (the idea being, if we were going to indicate the elapsed time of an operation this is ofent something). I would say the code in the Servlet gives this impression: writer.print("timer before:" + timer.getTime()); mailSender.sendMail(subject, recipients, body); writer.print("timer after:" + timer.getTime()); > - What's the point of using the second parameter (i.e. "response") in: > new OrderedMock(HttpServletResponse.class, "response"); As the name of the Parameter, "name" implies, it gives the mock a non default name. A simple examination of the code makes this pretty obvious. If you have two objects of the same time (e.g. a Customer) - it is useful if the error message is the same for both of them if one is causing the failure. As I am sure you are going to ask - MailSender is an example of an object that takes an Object[] as a parameter. In Java its important to get this one right so that the error messages are clear. > - At some point, it says: " // Proposed enhancement to allow > individual ordering". Is it done? As the http response is an ordered > mock, isn't the implemented solution already doing the same as what is > in the comments? No - the comment is right, its not implemented yet. MockHttpResponse shouldn't actually be totally ordered as not all messages have to be in a specific order, it really should just be a Mock with this type of code. > - Is the ConstraintMatcher[] supposed to be used internally or used by > the user? It is not used in the sample servlet test. In other words, how > would you translate the following (old style): > > mockRequest.expectVoid("setAttribute", new Constraint[] { > C.eq("result"), C.IS_ANYTHING }); You can instantiate a FullConstraintMatcher if you want e.g.: mockRequest.expect("setAttribute", new FullConstraintMatcher(C.eq("result"), C.IS_ANYTHING)); but simpler still is: mockRequest.expect("setAttribute", C.args(C.eq("result"), C.IS_ANYTHING); > Thanks No problem. Tim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003 |
From: Steve F. <st...@m3...> - 2003-05-12 21:25:05
|
Vincent Massol wrote: > I've started migrating my existing project to the new Dynamic Mock API > and I have the following questions (maybe this could be the start of a > migration guide or user guide?): > > - what is now replacing the setupDefaultResult() method? > Ex: mockRequest.setupDefaultResult(String.class, null); > > - what's the difference between expect*() and match*()? It seems to me > that the verify() will trigger a check to verify that the expect*() > calls did actually happen whereas this would not be checked for the > match*() ones? Is that correct? match tells the mock to return a result when it, um, matches a given call. It's a bit more flexible than the old return code. Presumably matching ANY would count as a default result although I don't think we've tried that. Tim, can you answer the rest? S. |
From: Vincent M. <vm...@pi...> - 2003-05-12 17:37:38
|
Hi, I've started migrating my existing project to the new Dynamic Mock API and I have the following questions (maybe this could be the start of a migration guide or user guide?): - what is now replacing the setupDefaultResult() method? Ex: mockRequest.setupDefaultResult(String.class, null); - what's the difference between expect*() and match*()? It seems to me that the verify() will trigger a check to verify that the expect*() calls did actually happen whereas this would not be checked for the match*() ones? Is that correct? - I've started looking at the src\examples\com\mockobjects\examples\dynamic\ SimpleServletTest.java example. It doesn't seem to be finished though and is missing some comments. But that would be the best help for those starting with the new dyna Mock API. Some questions: - I don't understand what's the purpose of the Timer class. Also, it wasn't in the testDoGetOldStyle() method. I think the Timer is muddying the example and should be removed altogether (unless there's something I don't understand!). - What's the point of using the second parameter (i.e. "response") in: new OrderedMock(HttpServletResponse.class, "response"); - At some point, it says: " // Proposed enhancement to allow individual ordering". Is it done? As the http response is an ordered mock, isn't the implemented solution already doing the same as what is in the comments? - Is the ConstraintMatcher[] supposed to be used internally or used by the user? It is not used in the sample servlet test. In other words, how would you translate the following (old style): mockRequest.expectVoid("setAttribute", new Constraint[] { C.eq("result"), C.IS_ANYTHING }); Thanks -Vincent |
From: Joe W. <jo...@tr...> - 2003-05-12 09:35:16
|
I like the name DynaMock too. Or MegaMock. Or GreatSmashingSuperMock. Jeff Martin wrote: >Personally I think DynaMock is really cheesy. I'd prefer the more mature >Dynamic Mock. Does that make me boring? > >Actually what about Mynamic ;) > >On Mon, 2003-05-12 at 08:25, Vincent Massol wrote: > > >>I personally like DynaMock as it really has a nice ring and it still >>reminds us that we're talking about Mocks. I wouldn't care about the >>fact that "Dyna" looks like "Dynamic Proxy". For me "Dyna" simply means >>dynamic, which is more positive than static and suggests that we're >>doing stuff at runtime versus compile time. >> >> >> |
From: Jeff M. <je...@mk...> - 2003-05-12 08:46:31
|
Personally I think DynaMock is really cheesy. I'd prefer the more mature Dynamic Mock. Does that make me boring? Actually what about Mynamic ;)=20 On Mon, 2003-05-12 at 08:25, Vincent Massol wrote: > I personally like DynaMock as it really has a nice ring and it still > reminds us that we're talking about Mocks. I wouldn't care about the > fact that "Dyna" looks like "Dynamic Proxy". For me "Dyna" simply means > dynamic, which is more positive than static and suggests that we're > doing stuff at runtime versus compile time. >=20 > My 0.2=E2=82=AC > -Vincent >=20 > > -----Original Message----- > > From: Ayerst, Tom [mailto:Tom...@DR...] > > Sent: 12 May 2003 09:01 > > To: 'Joe Walnes'; Steve Freeman > > Cc: Tim Mackinnon; Vincent Massol; 'Mockobjects-Java-Dev' > > Subject: RE: [MO-java-dev] New dyna mocks to head? > >=20 > > Proxy > > | > > +---+---+ > > | | > > Moxy Boxy > >=20 > > ? :-) > >=20 > > -----Original Message----- > > From: Joe Walnes [mailto:jo...@tr...] > > Sent: 12 May 2003 06:51 > > To: Steve Freeman > > Cc: Tim Mackinnon; Vincent Massol; 'Mockobjects-Java-Dev' > > Subject: Re: [MO-java-dev] New dyna mocks to head? > >=20 > >=20 > > Steve Freeman wrote: > >=20 > > > another thing, after all that naming stuff last week. The getter in > > > the .Net version is called MockInstance(), which seems to describe > the > > > situation quite adequately. > >=20 > > I prefer MockInstance because it doesnt tie the api into the fact tha= t > > the mock object is generated using a dynamic proxy. For example, the > > enhancements I made to allow classes (as well as interfaces) to be > > mocked used byte code generation instead of a proxy. That's also > another > > reason not to call it Moxy. > >=20 > > -j > >=20 > >=20 > >=20 > >=20 > > ------------------------------------------------------- > > Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara > > The only event dedicated to issues related to Linux enterprise > solutions > > www.enterpriselinuxforum.com > >=20 > > _______________________________________________ > > Mockobjects-java-dev mailing list > > Moc...@li... > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > >=20 > >=20 > > ---------------------------------------------------------------------= - > > If you have received this e-mail in error or wish to read our e-mail > > disclaimer statement and monitoring policy, please refer to > > http://www.drkw.com/disc/email/ or contact the sender. > > ---------------------------------------------------------------------= - >=20 >=20 >=20 >=20 > ------------------------------------------------------- > Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara > The only event dedicated to issues related to Linux enterprise solution= s > www.enterpriselinuxforum.com >=20 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev --=20 ------------------------------ jeff martin information technologist mkodo limited mobile: 44 (0) 78 55 478 331 phone: 44 (0) 20 77 29 45 45 email: jef...@mk... www.mkodo.com 73 Leonard St, London, EC2A 4QS. U.K |
From: Vincent M. <vm...@pi...> - 2003-05-12 07:27:07
|
I personally like DynaMock as it really has a nice ring and it still reminds us that we're talking about Mocks. I wouldn't care about the fact that "Dyna" looks like "Dynamic Proxy". For me "Dyna" simply means dynamic, which is more positive than static and suggests that we're doing stuff at runtime versus compile time. My 0.2=88 -Vincent > -----Original Message----- > From: Ayerst, Tom [mailto:Tom...@DR...] > Sent: 12 May 2003 09:01 > To: 'Joe Walnes'; Steve Freeman > Cc: Tim Mackinnon; Vincent Massol; 'Mockobjects-Java-Dev' > Subject: RE: [MO-java-dev] New dyna mocks to head? >=20 > Proxy > | > +---+---+ > | | > Moxy Boxy >=20 > ? :-) >=20 > -----Original Message----- > From: Joe Walnes [mailto:jo...@tr...] > Sent: 12 May 2003 06:51 > To: Steve Freeman > Cc: Tim Mackinnon; Vincent Massol; 'Mockobjects-Java-Dev' > Subject: Re: [MO-java-dev] New dyna mocks to head? >=20 >=20 > Steve Freeman wrote: >=20 > > another thing, after all that naming stuff last week. The getter in > > the .Net version is called MockInstance(), which seems to describe the > > situation quite adequately. >=20 > I prefer MockInstance because it doesnt tie the api into the fact that > the mock object is generated using a dynamic proxy. For example, the > enhancements I made to allow classes (as well as interfaces) to be > mocked used byte code generation instead of a proxy. That's also another > reason not to call it Moxy. >=20 > -j >=20 >=20 >=20 >=20 > ------------------------------------------------------- > Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara > The only event dedicated to issues related to Linux enterprise solutions > www.enterpriselinuxforum.com >=20 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev >=20 >=20 > ---------------------------------------------------------------------- > If you have received this e-mail in error or wish to read our e-mail > disclaimer statement and monitoring policy, please refer to > http://www.drkw.com/disc/email/ or contact the sender. > ---------------------------------------------------------------------- |
From: Ayerst, T. <Tom...@DR...> - 2003-05-12 07:03:16
|
Proxy | +---+---+ | | Moxy Boxy ? :-) -----Original Message----- From: Joe Walnes [mailto:jo...@tr...] Sent: 12 May 2003 06:51 To: Steve Freeman Cc: Tim Mackinnon; Vincent Massol; 'Mockobjects-Java-Dev' Subject: Re: [MO-java-dev] New dyna mocks to head? Steve Freeman wrote: > another thing, after all that naming stuff last week. The getter in > the .Net version is called MockInstance(), which seems to describe the > situation quite adequately. I prefer MockInstance because it doesnt tie the api into the fact that the mock object is generated using a dynamic proxy. For example, the enhancements I made to allow classes (as well as interfaces) to be mocked used byte code generation instead of a proxy. That's also another reason not to call it Moxy. -j ------------------------------------------------------- Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara The only event dedicated to issues related to Linux enterprise solutions www.enterpriselinuxforum.com _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev ---------------------------------------------------------------------- If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please refer to http://www.drkw.com/disc/email/ or contact the sender. ---------------------------------------------------------------------- |
From: Joe W. <jo...@tr...> - 2003-05-12 05:51:20
|
Steve Freeman wrote: > another thing, after all that naming stuff last week. The getter in > the .Net version is called MockInstance(), which seems to describe the > situation quite adequately. I prefer MockInstance because it doesnt tie the api into the fact that the mock object is generated using a dynamic proxy. For example, the enhancements I made to allow classes (as well as interfaces) to be mocked used byte code generation instead of a proxy. That's also another reason not to call it Moxy. -j |
From: Steve F. <st...@m3...> - 2003-05-11 23:13:42
|
another thing, after all that naming stuff last week. The getter in the .Net version is called MockInstance(), which seems to describe the situation quite adequately. Tim, I expect you'll getting more intimate with .Net in your new role. Good luck. S. Tim Mackinnon wrote: > Oh yes - forgot to add, we did a bit of an excerise with the name, and I > think your name "DynaMock" appears to be the best (there was some talk about > Moxy - but a google search shows lots of other things by that name, one > specific one is a type of proxy library as well). > > So I would like to sort out what we can, and then re-launch the thing with > the name. |
From: Tim M. <tim...@po...> - 2003-05-11 22:39:47
|
Oh yes - forgot to add, we did a bit of an excerise with the name, and I think your name "DynaMock" appears to be the best (there was some talk about Moxy - but a google search shows lots of other things by that name, one specific one is a type of proxy library as well). So I would like to sort out what we can, and then re-launch the thing with the name. Tim -----Original Message----- From: moc...@li... [mailto:moc...@li...]On Behalf Of Vincent Massol Sent: 11 May 2003 20:56 To: 'Mockobjects-Java-Dev' Subject: [MO-java-dev] New dyna mocks to head? Hi, I would just like to get some status WRT the move of the new dyna mocks to head. What's currently happening? Is someone doing the move? Are there any blocking items and if so is there someone working on them? I'm really keen to move to the new Dyna Mock in my applications but I would rather not do that unless they are on CVS HEAD and even better in a release... :-) Thanks! -Vincent ------------------------------------------------------- Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara The only event dedicated to issues related to Linux enterprise solutions www.enterpriselinuxforum.com _______________________________________________ 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.476 / Virus Database: 273 - Release Date: 24/04/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003 |
From: Tim M. <tim...@po...> - 2003-05-11 22:36:36
|
Vincent - I'm with you!!! The current block as I understand is how to get the existing stuff to compile/ant build again so that we can do a release and then retire the old verision to then integrate the new version? I would be all for just zipping up the old version and then putting the new version right over top - and then trying out your examples with the new version. However does this may cause issues for anyone with the old version (however, as it was never officially released, is this really a problem?) You can probably advise on this. Steve wanted to get hold of me this weekend, but unfortunately I've been very busy. Maybe we could do a release fest at XtC - hold off on the beer and just do what it takes to make it integrate? Tim -----Original Message----- From: moc...@li... [mailto:moc...@li...]On Behalf Of Vincent Massol Sent: 11 May 2003 20:56 To: 'Mockobjects-Java-Dev' Subject: [MO-java-dev] New dyna mocks to head? Hi, I would just like to get some status WRT the move of the new dyna mocks to head. What's currently happening? Is someone doing the move? Are there any blocking items and if so is there someone working on them? I'm really keen to move to the new Dyna Mock in my applications but I would rather not do that unless they are on CVS HEAD and even better in a release... :-) Thanks! -Vincent ------------------------------------------------------- Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara The only event dedicated to issues related to Linux enterprise solutions www.enterpriselinuxforum.com _______________________________________________ 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.476 / Virus Database: 273 - Release Date: 24/04/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003 |
From: Vincent M. <vm...@pi...> - 2003-05-11 19:57:41
|
Hi, I would just like to get some status WRT the move of the new dyna mocks to head. What's currently happening? Is someone doing the move? Are there any blocking items and if so is there someone working on them? I'm really keen to move to the new Dyna Mock in my applications but I would rather not do that unless they are on CVS HEAD and even better in a release... :-) Thanks! -Vincent |
From: Tim M. <ma...@us...> - 2003-05-06 00:13:31
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv9011/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment DynamicUtil.java Log Message: Renamed internal getProxyName to proxyToString - which is what it is Index: DynamicUtil.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DynamicUtil.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- DynamicUtil.java 6 May 2003 00:08:50 -0000 1.1.2.3 +++ DynamicUtil.java 6 May 2003 00:13:28 -0000 1.1.2.4 @@ -74,8 +74,7 @@ return result.toArray(); } - //TODO rename to proxyToString - public static String getProxyName(Object element) { + public static String proxyToString(Object element) { if (Proxy.isProxyClass(element.getClass())) { try { Method mockNameMethod = Mock.class.getDeclaredMethod("getMockName", new Class[0]); @@ -122,7 +121,7 @@ buf.append("]"); } else { buf.append("<"); - buf.append(getProxyName(element)); + buf.append(proxyToString(element)); buf.append(">"); } } |
From: Tim M. <ma...@us...> - 2003-05-06 00:13:30
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv9011/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment MockTest.java Log Message: Renamed internal getProxyName to proxyToString - which is what it is Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.10 retrieving revision 1.8.2.11 diff -u -r1.8.2.10 -r1.8.2.11 --- MockTest.java 5 May 2003 22:47:09 -0000 1.8.2.10 +++ MockTest.java 6 May 2003 00:13:28 -0000 1.8.2.11 @@ -405,8 +405,8 @@ 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 + public void testProxyToString() throws Exception { + assertEquals("Should get a mock name without touching the underlying mock", MOCK_NAME, DynamicUtil.proxyToString(proxy)); + mock.verify(); // should not fail on a proxyToString call } } |
From: Tim M. <ma...@us...> - 2003-05-06 00:13:30
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv9011/core/com/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment IsEqual.java Log Message: Renamed internal getProxyName to proxyToString - which is what it is Index: IsEqual.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsEqual.java,v retrieving revision 1.2.2.5 retrieving revision 1.2.2.6 diff -u -r1.2.2.5 -r1.2.2.6 --- IsEqual.java 5 May 2003 22:44:33 -0000 1.2.2.5 +++ IsEqual.java 6 May 2003 00:13:28 -0000 1.2.2.6 @@ -33,7 +33,7 @@ } public String toString() { - return " = " + DynamicUtil.getProxyName(_object); + return " = " + DynamicUtil.proxyToString(_object); } public boolean equals(Object anObject) { |
From: Tim M. <ma...@us...> - 2003-05-06 00:08:53
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6309/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment DynamicUtil.java Log Message: Support or primitive array type error reporting in a readable format (e.g. not int[]@3456) Index: DynamicUtil.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DynamicUtil.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- DynamicUtil.java 5 May 2003 22:44:33 -0000 1.1.2.2 +++ DynamicUtil.java 6 May 2003 00:08:50 -0000 1.1.2.3 @@ -6,56 +6,125 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.util.*; +import java.util.List; + public class DynamicUtil { - + public static Object[] asObjectArray(Object primitiveArray) { + + if (primitiveArray instanceof Object[]) { + return (Object[])primitiveArray; + } + + List result = new ArrayList(); + + if (primitiveArray instanceof boolean[]) { + boolean[] booleanArray = (boolean[]) primitiveArray; + + for (int i = 0; i < booleanArray.length; i++) { + result.add(new Boolean(booleanArray[i])); + } + } else if (primitiveArray instanceof char[]) { + char[] charArray = (char[]) primitiveArray; + + for (int i = 0; i < charArray.length; i++) { + result.add(new Character(charArray[i])); + } + } else if (primitiveArray instanceof byte[]) { + byte[] byteArray = (byte[]) primitiveArray; + + for (int i = 0; i < byteArray.length; i++) { + result.add(new Byte(byteArray[i])); + } + + } else if (primitiveArray instanceof short[]) { + short[] shortArray = (short[]) primitiveArray; + + for (int i = 0; i < shortArray.length; i++) { + result.add(new Short(shortArray[i])); + } + } else if (primitiveArray instanceof int[]) { + int[] intArray = (int[]) primitiveArray; + + for (int i = 0; i < intArray.length; i++) { + result.add(new Integer(intArray[i])); + } + } else if (primitiveArray instanceof long[]) { + long[] longArray = (long[]) primitiveArray; + + for (int i = 0; i < longArray.length; i++) { + result.add(new Long(longArray[i])); + } + } else if (primitiveArray instanceof float[]) { + float[] floatArray = (float[]) primitiveArray; + + for (int i = 0; i < floatArray.length; i++) { + result.add(new Float(floatArray[i])); + } + } else if (primitiveArray instanceof double[]) { + double[] doulbeArray = (double[]) primitiveArray; + + for (int i = 0; i < doulbeArray.length; i++) { + result.add(new Float(doulbeArray[i])); + } + } else { + throw new RuntimeException("Unknown primitive data type for Object[] conversion " + primitiveArray.toString()); + } + + return result.toArray(); + } + //TODO rename to proxyToString public static String getProxyName(Object element) { - if(Proxy.isProxyClass(element.getClass())) { + 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(); + Object debugableResult = Proxy.getInvocationHandler(element).invoke(element, mockNameMethod, new Object[0]); + return debugableResult.toString(); } catch (Throwable e) { - return element.getClass().getName(); - } + return element.getClass().getName(); + } + } + + if (element.getClass().isArray()) { + StringBuffer buf = new StringBuffer(); + buf.append("["); + join(asObjectArray(element),buf); + buf.append("]"); + return buf.toString(); + } else { + return element.toString(); } - - //TODO put in primitive array print handling - return element.toString(); - } - public static String methodToString( String name, Object[] args ) { + public static String methodToString(String name, Object[] args) { StringBuffer buf = new StringBuffer(); - + buf.append(name); buf.append("("); - buf.append(DynamicUtil.join(args)); + join(args,buf); buf.append(")"); - - return buf.toString(); + + return buf.toString(); } - public static String join( Object[] elements ) { - StringBuffer buf = new StringBuffer(); - + public static void join(Object[] elements, StringBuffer buf) { for (int i = 0; i < elements.length; i++) { - if( i > 0 ) buf.append(", "); - + if (i > 0) { + buf.append(", "); + } + Object element = elements[i]; - //TODO put in primitive array print handling - if(element instanceof Object[]) { - buf.append( "[" ); - buf.append(join((Object[])element)); - buf.append( "]" ); + + if (element.getClass().isArray()) { + buf.append("["); + join(asObjectArray(element), buf); + buf.append("]"); } else { - buf.append( "<" ); - buf.append(DynamicUtil.getProxyName(element)); - buf.append( ">" ); + buf.append("<"); + buf.append(getProxyName(element)); + buf.append(">"); } } - return buf.toString(); } - - } |
From: Tim M. <ma...@us...> - 2003-05-06 00:08:53
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6309/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment DynamicUtilTest.java Log Message: Support or primitive array type error reporting in a readable format (e.g. not int[]@3456) Index: DynamicUtilTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/DynamicUtilTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DynamicUtilTest.java 16 Apr 2003 16:31:46 -0000 1.1.2.1 +++ DynamicUtilTest.java 6 May 2003 00:08:50 -0000 1.1.2.2 @@ -28,6 +28,24 @@ AssertMo.assertIncludes("Should contain second Arg", "arg2", result); } + public void testMethodToStringWithStringArray() throws Exception { + Object[] args = new Object[] { new String[] {"arg1","arg2"}}; + + String result = DynamicUtil.methodToString("methodName", args); + + AssertMo.assertIncludes("Should contain method name", "methodName", result); + AssertMo.assertIncludes("Should contain args as an array", "[<arg1>, <arg2>]", result); + } + + public void testMethodToStringWithPrimitiveArray() throws Exception { + Object[] args = new Object[] { new long[] {1,2}}; + + String result = DynamicUtil.methodToString("methodName", args); + + AssertMo.assertIncludes("Should contain method name", "methodName", result); + AssertMo.assertIncludes("Should contain args as an array", "[<1>, <2>]", result); + } + public void testMethodToStringWithProxyArg() throws Exception { Mock mockDummyInterface = new Mock(DummyInterface.class, "DummyMock"); Object[] args = new Object[] {"arg1", mockDummyInterface.proxy()}; |
From: Tim M. <ma...@us...> - 2003-05-06 00:08:53
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv6309/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServletTest.java SimpleServlet.java Log Message: Support or primitive array type error reporting in a readable format (e.g. not int[]@3456) Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- SimpleServletTest.java 5 May 2003 22:48:07 -0000 1.1.2.10 +++ SimpleServletTest.java 6 May 2003 00:08:50 -0000 1.1.2.11 @@ -69,7 +69,7 @@ mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), BODY ); mockTimer.expectAndReturn("getTime", 10000); mockTimer.expectAndReturn("getTime", 20000); - mockMailSender.expectAndReturn("sendMail", C.eq(SUBJECT, new int[] {1,2}, BODY),true); + mockMailSender.expectAndReturn("sendMail", C.eq(SUBJECT, RECIPIENTS, BODY),true); final PrintWriter contentWriter = new PrintWriter(new StringWriter()); Index: SimpleServlet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServlet.java,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- SimpleServlet.java 5 May 2003 22:48:07 -0000 1.1.2.7 +++ SimpleServlet.java 6 May 2003 00:08:50 -0000 1.1.2.8 @@ -34,6 +34,7 @@ String subject = request.getParameter("subject"); String[] recipients = request.getParameterValues("recipients"); String browser = request.getParameter("browser-identifier"); + // Cause a failure by calling something unexpected //String pet = request.getParameter("favourite-pet"); |
From: Tim M. <ma...@us...> - 2003-05-05 22:48:10
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv18466/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServletTest.java SimpleServlet.java Added Files: Tag: DynamicMockExperiment MailSender.java Log Message: Updated dynamic example with an additional interface that shows the usage of an object that has an Object[] parameter --- NEW FILE: MailSender.java --- /* * Created on 02-May-03 */ package com.mockobjects.examples.dynamic; // An example interface that has an Object[] as a parameter public interface MailSender { boolean sendMail(String subject, String[] recipients, String body); } Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -r1.1.2.9 -r1.1.2.10 --- SimpleServletTest.java 17 Apr 2003 01:54:16 -0000 1.1.2.9 +++ SimpleServletTest.java 5 May 2003 22:48:07 -0000 1.1.2.10 @@ -21,13 +21,16 @@ import com.mockobjects.dynamic.OrderedMock; /** - * @author dev - * - * To change this generated comment go to - * Window>Preferences>Java>Code Generation>Code and Comments + * A sample test case showing usage of the dynamic mock library. + * It has also been used as an acceptance test for the implementation + * of the library, and so uses different variations of some of the calls */ -public class SimpleServletTest extends TestCase { +public class SimpleServletTest extends TestCase { + final String SUBJECT = "Mail Subject"; + final String[] RECIPIENTS = new String[]{ "ti...@ho...", "st...@ya..."}; + final String BODY = "Mail Body"; + public SimpleServletTest(String name) { super(name); } @@ -50,31 +53,41 @@ mockHttpServletResponse.verify(); } */ - public void testDoGetNew() throws ServletException, IOException { - Mock mockTimer = new Mock(Timer.class); - Mock mockHttpServletResponse = new OrderedMock(HttpServletResponse.class, "response"); + public void testDoGet() throws ServletException, IOException { + Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); + Mock mockHttpServletResponse = new OrderedMock(HttpServletResponse.class, "response"); + Mock mockTimer = new Mock(Timer.class); + Mock mockMailSender = new Mock(MailSender.class); - mockHttpServletRequest.matchAndReturn( "getParameter", C.args(C.eq("browser-identifier")), "MSIE-5.0" ); - mockHttpServletRequest.expectAndReturn( "getParameter", "subject", "Mail Subject" ); - mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), "Mail Body" ); + // Set no expectations but answer a value for the specified method + mockHttpServletRequest.matchAndReturn( "getParameter", C.eq("browser-identifier"), "MSIE-5.0" ); + mockHttpServletRequest.matchAndReturn("getIntHeader", C.ANY_ARGS, 20); + + mockHttpServletRequest.expectAndReturn( "getParameter", "subject", SUBJECT ); + mockHttpServletRequest.expectAndReturn("getParameterValues", "recipients", RECIPIENTS); + mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), BODY ); mockTimer.expectAndReturn("getTime", 10000); mockTimer.expectAndReturn("getTime", 20000); + mockMailSender.expectAndReturn("sendMail", C.eq(SUBJECT, new int[] {1,2}, BODY),true); final PrintWriter contentWriter = new PrintWriter(new StringWriter()); mockHttpServletResponse.expect( "setContentType", "text/html"); mockHttpServletResponse.expectAndReturn( "getWriter", contentWriter ); - + +// Proposed enhancement to allow individual ordering +// // CallMatch m1 = mockHttpServletResponse.expect( "setContentType", "text/html"); // CallMatch m2 = mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); // m1.expectBefore(m2); - SimpleServlet aServlet = new SimpleServlet((Timer)mockTimer.proxy()); + SimpleServlet aServlet = new SimpleServlet((Timer)mockTimer.proxy(), (MailSender)mockMailSender.proxy()); aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); mockHttpServletRequest.verify(); mockHttpServletResponse.verify(); mockTimer.verify(); + mockMailSender.verify(); } } Index: SimpleServlet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServlet.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- SimpleServlet.java 16 Apr 2003 22:17:35 -0000 1.1.2.6 +++ SimpleServlet.java 5 May 2003 22:48:07 -0000 1.1.2.7 @@ -16,28 +16,33 @@ public class SimpleServlet extends HttpServlet { private Timer timer; + private MailSender mailSender; - public SimpleServlet(Timer aTimer) { + public SimpleServlet(Timer aTimer, MailSender aMailSender) { super(); timer = aTimer; + mailSender = aMailSender; } public SimpleServlet() { - this(null); // really this would be a proper timer... + this(null,null); // really this would be a proper timer and mail sender... } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String body = request.getParameter("body"); String subject = request.getParameter("subject"); + String[] recipients = request.getParameterValues("recipients"); String browser = request.getParameter("browser-identifier"); + // Cause a failure by calling something unexpected //String pet = request.getParameter("favourite-pet"); - + + int age = request.getIntHeader("age"); response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print("timer before:" + timer.getTime()); - // some long operation + mailSender.sendMail(subject, recipients, body); writer.print("timer after:" + timer.getTime()); } |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv17720/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallMatchTest.java CallSequenceTest.java CallBagTest.java MockTest.java MockConstraint.java DummyThrowable.java ExpectedCallTest.java MockCallFactory.java Added Files: Tag: DynamicMockExperiment MockConstraintMatcher.java ErrorMessageExamples.java ConstraintMatcherTest.java CTest.java Log Message: Tests for change from Constraint[] to ConstraintMatcher as well as Object[] parameters Before making this change refactored the tests after realisation that if a CallMatch matches returns true, then CallMatch.call does not need to do additional constraint checking - it just performs the call. --- NEW FILE: MockConstraintMatcher.java --- package test.mockobjects.dynamic; import com.mockobjects.*; import com.mockobjects.dynamic.ConstraintMatcher; public class MockConstraintMatcher implements ConstraintMatcher{ private ExpectationCounter myMatchesCalls = new ExpectationCounter("MockConstraintMatcher.matches(Object[])"); private ReturnValues myActualMatchesReturnValues = new ReturnValues("MockConstraintMatcher.matches(Object[])", true); private ExpectationList myMatchesParameter0Values = new ExpectationList("MockConstraintMatcher.matches(Object[]) java.lang.Object"); private ExpectationCounter myGetConstraintsCalls = new ExpectationCounter("MockConstraintMatcher.getConstraints()"); private ReturnValues myActualGetConstraintsReturnValues = new ReturnValues("MockConstraintMatcher.getConstraints()", true); public void setExpectedMatchesCalls(int calls){ myMatchesCalls.setExpected(calls); } public void addExpectedMatches(Object[] arg0){ myMatchesParameter0Values.addExpected(arg0); } public boolean matches(Object[] arg0){ myMatchesCalls.inc(); myMatchesParameter0Values.addActual(arg0); Object nextReturnValue = myActualMatchesReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); return ((Boolean) nextReturnValue).booleanValue(); } public void setupExceptionMatches(Throwable arg){ myActualMatchesReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupMatches(boolean arg){ myActualMatchesReturnValues.add(new Boolean(arg)); } public void setExpectedGetConstraintsCalls(int calls){ myGetConstraintsCalls.setExpected(calls); } public Object[] getConstraints(){ myGetConstraintsCalls.inc(); Object nextReturnValue = myActualGetConstraintsReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); return (Object[]) nextReturnValue; } public void setupExceptionGetConstraints(Throwable arg){ myActualGetConstraintsReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupGetConstraints(Object[] arg){ myActualGetConstraintsReturnValues.add(arg); } public void verify(){ myMatchesCalls.verify(); myMatchesParameter0Values.verify(); myGetConstraintsCalls.verify(); } } --- NEW FILE: ErrorMessageExamples.java --- /* * Created on 30-Apr-03 */ package test.mockobjects.dynamic; import junit.framework.Assert; import junit.textui.TestRunner; public class ErrorMessageExamples { public static void main(String[] args) { TestRunner.main(new String[] { ErrorMessageExamples.class.getName() }); //TODO work out how to build up test methods to be run just by this app } public void testUncalledMethodError() { Assert.assertEquals("should not be equa1", "a", "b"); } } --- NEW FILE: ConstraintMatcherTest.java --- /* * Created on 20-Apr-03 */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.*; import com.mockobjects.dynamic.ConstraintMatcher; import junit.framework.TestCase; public class ConstraintMatcherTest extends TestCase { private final String METHOD_NAME = "methodA"; public ConstraintMatcherTest(String name) { super(name); } public void testNoMatchWhenTooManyArguments() throws Throwable { String[] args = { "arg1", "arg2" }; MockConstraint[] constraints = { new MockConstraint("constraint1", args[0], true) }; ConstraintMatcher constraintMatcher = new FullConstraintMatcher(constraints); assertFalse("Should not match if too many arguments", constraintMatcher.matches(args)); } public void testNoMatchWhenTooFewArguments() throws Throwable { String[] args = { "arg1" }; MockConstraint[] constraints = { new MockConstraint("constraint1", args[0], true), new MockConstraint("constraint2", args[0], true) }; ConstraintMatcher constraintMatcher = new FullConstraintMatcher(constraints); assertFalse("Should not match if too few arguments", constraintMatcher.matches(args)); } public void testNoMatchWhenConstraintIsViolated() throws Throwable { String[] args = { "argA", "argB", "argC" }; MockConstraint[] constraints = { new MockConstraint("constraintA", args[0], true), new MockConstraint("constraintB", args[1], false), new MockConstraint("constraintC", args[2], true) }; ConstraintMatcher constraintMatcher = new FullConstraintMatcher(constraints); assertFalse("Should not match", constraintMatcher.matches(args)); } public void testNoMatchWithNoArgumentsAndCalleeHasArguments() throws Throwable { String[] args = new String[] { "arg1", "arg2" }; MockConstraint[] constraints = new MockConstraint[0]; ConstraintMatcher constraintMatcher = new FullConstraintMatcher(constraints); assertFalse("Should not match", constraintMatcher.matches(args)); } public void testMatchWithNoArguments() throws Throwable { String[] args = new String[0]; MockConstraint[] constraints = new MockConstraint[0]; ConstraintMatcher constraintMatcher = new FullConstraintMatcher(constraints); assertTrue("Should match", constraintMatcher.matches(args)); } public void testMatchAndArgumentsCheckedAgainstConstraints() throws Throwable { String[] args = { "argA", "argB", "argC" }; MockConstraint constraintA = new MockConstraint("constraintA", args[0], true); MockConstraint constraintB = new MockConstraint("constraintB", args[1], true); MockConstraint constraintC = new MockConstraint("constraintC", args[2], true); MockConstraint[] constraints = { constraintA, constraintB, constraintC }; ConstraintMatcher constraintMatcher = new FullConstraintMatcher(constraints); assertTrue("Should match", constraintMatcher.matches(args)); constraintA.verify(); constraintB.verify(); constraintC.verify(); } public void testMatchWithArgument() throws Throwable { String[] args = { "argA" }; MockConstraint constraintA = new MockConstraint("constraintA", args[0], true); ConstraintMatcher constraintMatcher = new FullConstraintMatcher(new MockConstraint[] { constraintA }); assertTrue("Should match", constraintMatcher.matches(args)); } } --- NEW FILE: CTest.java --- /* * Created on 30-Apr-03 */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.C; import junit.framework.TestCase; public class CTest extends TestCase { public CTest(String name) { super(name); } public void testEqObjectArray() { assertTrue("Should be equals for object arrays", C.eq(new String[]{"a", "b"}).eval(new String[]{"a","b"})); } } Index: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallMatchTest.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- CallMatchTest.java 16 Apr 2003 22:16:08 -0000 1.1.2.5 +++ CallMatchTest.java 5 May 2003 22:47:09 -0000 1.1.2.6 @@ -3,255 +3,102 @@ */ package test.mockobjects.dynamic; -import com.mockobjects.constraint.*; +import junit.framework.TestCase; + import com.mockobjects.dynamic.*; -import com.mockobjects.util.*; -import junit.framework.*; public class CallMatchTest extends TestCase { + private static final Object[] IGNORED_ARGS = new Object[0]; + final String METHOD_NAME = "methodName"; + Mock mock = new Mock(DummyInterface.class, "mock"); + MockCallable mockCallable = new MockCallable(); + MockConstraintMatcher mockConstraintMatcher = new MockConstraintMatcher(); + CallMatch callMatch = new CallMatch(METHOD_NAME, mockConstraintMatcher, mockCallable); + + public CallMatchTest(String name) { + super(name); + } + + public void testCallArgumentsArePropagatedToDecorated() + throws Throwable { + final Object[] arguments = IGNORED_ARGS; + final String result = "result"; + + mockCallable.setExpectedCall(mock, METHOD_NAME, arguments); + mockCallable.setupCallReturn(result); + + callMatch.call(mock, METHOD_NAME, arguments); + + mockCallable.verifyExpectations(); + } + + public void testUncalledCallVerifies() { + mockCallable.setExpectedVerifyCalls(1); + + callMatch.verify(); + + mockCallable.verifyExpectations(); + } + + public void testCallSuccessVerifies() throws Throwable { + mockCallable.setExpectedVerifyCalls(1); + mockCallable.setupCallReturn("result"); + + callMatch.call(mock, "methodName", IGNORED_ARGS); + callMatch.verify(); + + mockCallable.verifyExpectations(); + } + + public void testMultipleCallsSucceed() throws Throwable { + mockCallable.setupCallReturn("result"); + + callMatch.call(mock, METHOD_NAME, IGNORED_ARGS); + callMatch.call(mock, METHOD_NAME, IGNORED_ARGS); + + mockCallable.verifyExpectations(); + } + + public void testCallFailure() throws Throwable { + // na + } + + public void testCallDoesNotMatchWhenWrongName() throws Throwable { + CallMatch call = new CallMatch(METHOD_NAME, C.ANY_ARGS, mockCallable); + + assertFalse("call does not match", callMatch.matches("anotherName", IGNORED_ARGS)); + mockCallable.verifyExpectations(); + } + + public void testMatchesAfterCalls() throws Throwable { + mockCallable.setupCallReturn("result"); + mockCallable.setupMatchesReturn(true); + + mockConstraintMatcher.setupMatches(true); + + callMatch.call(mock, METHOD_NAME, IGNORED_ARGS); + assertTrue("matches after first call", callMatch.matches(METHOD_NAME, IGNORED_ARGS)); + callMatch.call(mock, METHOD_NAME, IGNORED_ARGS); + assertTrue("matches after further calls", callMatch.matches(METHOD_NAME, IGNORED_ARGS)); + + mockCallable.verifyExpectations(); + } + + public void testMatchesDelegatesToContraintMatcher() + throws Throwable { + final String[] args = new String[] { "a1", "a2" }; + + mockConstraintMatcher.addExpectedMatches(args); + mockConstraintMatcher.setupMatches(true); + + assertTrue("matches delegated to constraint matcher", callMatch.matches(METHOD_NAME, args)); + mockConstraintMatcher.verify(); + } + + public void testMatchesFailure() throws Throwable { + mockConstraintMatcher.setupMatches(false); - final String METHOD_NAME = "methodName"; - Mock mock = new Mock(DummyInterface.class,"mock"); - MockCallable mockCallable = new MockCallable(); - CallMatch call = new CallMatch( METHOD_NAME, new Constraint[0], mockCallable ); - - public CallMatchTest(String name) { - super(name); - } - - public void testCallArgumentsArePropagatedToDecorated() throws Throwable { - final Object[] arguments = new Object[0]; - final String result = "result"; - - mockCallable.setExpectedCall( mock, METHOD_NAME, arguments ); - mockCallable.setupCallReturn( result ); - - call.call(mock, METHOD_NAME, arguments); - - mockCallable.verifyExpectations(); - } - - public void testUncalledCallVerifies() { - mockCallable.setExpectedVerifyCalls(1); - call.verify(); - - mockCallable.verifyExpectations(); - } - - public void testSuccessfulCallVerifies() throws Throwable { - mockCallable.setExpectedVerifyCalls(1); - mockCallable.setupCallReturn("result"); - - call.call( mock, "methodName", new Object[0] ); - call.verify(); - - mockCallable.verifyExpectations(); - } - - public void testMultipleCallsSucceed() throws Throwable { - mockCallable.setupCallReturn("result"); - - call.call( mock, METHOD_NAME, new Object[0] ); - call.call( mock, METHOD_NAME, new Object[0] ); - - mockCallable.verifyExpectations(); - } - - public void testArgumentsCheckedAgainstConstraints() throws Throwable { - String[] args = { "arg1", "arg2", "arg3" }; - MockConstraint[] constraints = { - new MockConstraint( "constraint1", args[0], true ), - new MockConstraint( "constraint2", args[1], true ), - new MockConstraint( "constraint3", args[2], true ) - }; - mockCallable.setupCallReturn("result"); - - CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - - call.call( mock, METHOD_NAME, args ); - - for( int i = 0; i < constraints.length; i++ ) { - constraints[i].verify(); - } - - mockCallable.verifyExpectations(); - } - - public void testWrongNumberOfArguments() throws Throwable { - String[] args = { "arg1", "arg2" }; - MockConstraint[] constraints = { - new MockConstraint( "constraint1", args[0], true ), - new MockConstraint( "constraint2", args[1], true ), - new MockConstraint( "constraint3", args[1], true ) - }; - - CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - - boolean passed = true; - try { - call.call( mock, METHOD_NAME, args ); - passed = false; - } catch (AssertionFailedError ex) { - AssertMo.assertIncludes("Should show expected number of arguments", - Integer.toString(constraints.length), ex.getMessage()); - AssertMo.assertIncludes("Should show actual number of arguments", - Integer.toString(args.length), ex.getMessage()); - AssertMo.assertIncludes("Should include the method name", - METHOD_NAME, ex.getMessage()); - } - - assertTrue("Should fail is call doesn't give an exception", passed); - mockCallable.verifyExpectations(); - } - - public void testConstraintFailure() throws Throwable { - String[] args = { "argA", "argB", "argC" }; - MockConstraint[] constraints = { - new MockConstraint( "constraintA", args[0], true ), - new MockConstraint( "constraintB", args[1], false ), - new MockConstraint( "constraintC", args[2], true ) - }; - - CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - - boolean passed = true; - try { - call.call( mock, METHOD_NAME, args ); - passed = false; - } catch (AssertionFailedError ex) { - AssertMo.assertIncludes("Should include the method name", - METHOD_NAME, ex.getMessage()); - AssertMo.assertIncludes("Should show index of failed argument", - "1", ex.getMessage() ); - AssertMo.assertIncludes("Should show expected arguments", - DynamicUtil.join(constraints), ex.getMessage()); - AssertMo.assertIncludes("Should show actual arguments", - DynamicUtil.join(args), ex.getMessage()); - } - - assertTrue("Should fail is call doesn't give an exception", passed); - mockCallable.verifyExpectations(); - } - - - public void testCallMatchesArguments() throws Throwable { - String[] args = { "arg1", "arg2", "arg3" }; - MockConstraint[] constraints = { - new MockConstraint( "constraint1", args[0], true ), - new MockConstraint( "constraint2", args[1], true ), - new MockConstraint( "constraint3", args[2], true ) - }; - - mockCallable.setExpectedMatches( METHOD_NAME, args ); - mockCallable.setupMatchesReturn(true); - - CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - - assertTrue( "call matches", call.matches( METHOD_NAME, args) ); - mockCallable.verifyExpectations(); - } - - 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 match", call.matches( METHOD_NAME, args) ); - mockCallable.verifyExpectations(); - } - - public void testCallMatchesWithAnyArguments() throws Throwable { - String[] args = new String[] {"anyArg" }; - - 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(); - } - - 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 ), - new MockConstraint( "constraint2", args[1], true ), - new MockConstraint( "constraint3", args[2], true ) - }; - - mockCallable.setExpectedMatches( METHOD_NAME, args ); - mockCallable.setupMatchesReturn(false); - - CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - - 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( METHOD_NAME, new Constraint[0], mockCallable ); - - assertFalse( "call does not match", call.matches( "anotherName", new Object[0]) ); - mockCallable.verifyExpectations(); - } - - public void testCallDoesNotMatchWhenWrongNumberOfArguments() throws Throwable { - String[] args = { "arg1", "arg2" }; - MockConstraint[] constraints = { - new MockConstraint( "constraint1", args[0], true ), - new MockConstraint( "constraint2", args[1], true ), - new MockConstraint( "constraint3", args[1], true ) - }; - - CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - - assertFalse( "call does not match", call.matches( METHOD_NAME, args) ); - mockCallable.verifyExpectations(); - } - - public void testCallDoesNotMatchWhenConstraintIsViolated() throws Throwable { - String[] args = { "argA", "argB", "argC" }; - MockConstraint[] constraints = { - new MockConstraint( "constraintA", args[0], true ), - new MockConstraint( "constraintB", args[1], false ), - new MockConstraint( "constraintC", args[2], true ) - }; - - CallMatch call = new CallMatch( METHOD_NAME, (Constraint[])constraints, mockCallable ); - - assertFalse( "call does not match", call.matches( METHOD_NAME, args) ); - mockCallable.verifyExpectations(); - } - - public void testMatchesAfterCalls() throws Throwable { - mockCallable.setupCallReturn("result"); - mockCallable.setupMatchesReturn(true); - - CallMatch call = new CallMatch(METHOD_NAME, C.args(), mockCallable ); - - 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]) ); - - mockCallable.verifyExpectations(); - } + assertFalse("Should not match if constraint matcher doesn't", callMatch.matches(METHOD_NAME, IGNORED_ARGS)); + } } Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSequenceTest.java,v retrieving revision 1.5.2.4 retrieving revision 1.5.2.5 diff -u -r1.5.2.4 -r1.5.2.5 --- CallSequenceTest.java 17 Apr 2003 16:17:27 -0000 1.5.2.4 +++ CallSequenceTest.java 5 May 2003 22:47:09 -0000 1.5.2.5 @@ -3,8 +3,7 @@ */ package test.mockobjects.dynamic; -import com.mockobjects.constraint.Constraint; - +import com.mockobjects.dynamic.*; import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.CallMatch; import com.mockobjects.dynamic.CallSequence; @@ -26,7 +25,7 @@ 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 ConstraintMatcher 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; @@ -113,7 +112,7 @@ 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 expected error message", "Unexpected call: 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); Index: CallBagTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallBagTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallBagTest.java 17 Apr 2003 16:17:27 -0000 1.1.2.2 +++ CallBagTest.java 5 May 2003 22:47:09 -0000 1.1.2.3 @@ -3,7 +3,6 @@ */ package test.mockobjects.dynamic; -import com.mockobjects.constraint.*; import com.mockobjects.dynamic.*; import com.mockobjects.util.*; @@ -21,7 +20,7 @@ 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 ConstraintMatcher METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2")); final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; private CallBag callSet = new CallBag(); private Mock unusedMock = null; Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.9 retrieving revision 1.8.2.10 diff -u -r1.8.2.9 -r1.8.2.10 --- MockTest.java 17 Apr 2003 16:17:25 -0000 1.8.2.9 +++ MockTest.java 5 May 2003 22:47:09 -0000 1.8.2.10 @@ -3,7 +3,8 @@ */ package test.mockobjects.dynamic; -import com.mockobjects.constraint.Constraint; +import com.mockobjects.constraint.*; +import com.mockobjects.constraint.IsEqual; import com.mockobjects.dynamic.*; import com.mockobjects.util.*; @@ -22,9 +23,9 @@ final Throwable METHOD_EXCEPTION = new DummyThrowable("Configured test throwable"); final Object[] METHOD_NOARG_ARGS = new Object[0]; final String[] METHOD_ONEARG_ARGS = new String[] { "oneP1" }; - final Constraint[] METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1")); + final ConstraintMatcher METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1")); final String[] METHOD_TWOARG_ARGS = new String[] { "twoP1", "twoP2" }; - final Constraint[] METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2")); + final ConstraintMatcher METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2")); private DummyInterface proxy; private Mock mock; private MockCallFactory mockCallFactory = new MockCallFactory(); @@ -144,6 +145,35 @@ Verifier.verifyObject(this); mockCallableAddable.verifyExpectations(); } + + public void testExpectWithConstraint() throws Throwable { + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); + + mock.expect(METHOD_ONEARG_NAME, new IsEqual(METHOD_ONEARG_ARGS[0])); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + + public void testExpectWithConstraintArray() throws Throwable { + mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub); + mockCallFactory.setupCreateCallMatch(mockCallMatch); + mockCallFactory.setupCreateExpectedCall(mockExpectedCall); + + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); + + mock.expect(METHOD_ONEARG_NAME, new Constraint[] { new IsEqual(METHOD_ONEARG_ARGS[0])}); + + Verifier.verifyObject(this); + mockCallableAddable.verifyExpectations(); + } + public void testExpectManyAndReturn() throws Throwable { mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT); Index: MockConstraint.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockConstraint.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- MockConstraint.java 7 Apr 2003 14:27:00 -0000 1.1.2.1 +++ MockConstraint.java 5 May 2003 22:47:10 -0000 1.1.2.2 @@ -27,8 +27,8 @@ return description; } - public boolean eval( Object o ) { - assertSame( "should be expected argument", expectedArg, o ); + public boolean eval( Object arg ) { + assertSame( "Should be expected argument", expectedArg, arg ); wasChecked = true; return result; } Index: DummyThrowable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/DummyThrowable.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DummyThrowable.java 7 Apr 2003 14:26:59 -0000 1.1.2.1 +++ DummyThrowable.java 5 May 2003 22:47:10 -0000 1.1.2.2 @@ -16,12 +16,4 @@ super(message); } - public DummyThrowable(String message, Throwable cause) { - super(message, cause); - } - - public DummyThrowable(Throwable cause) { - super(cause); - } - } Index: ExpectedCallTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/ExpectedCallTest.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- ExpectedCallTest.java 16 Apr 2003 22:17:04 -0000 1.1.2.6 +++ ExpectedCallTest.java 5 May 2003 22:47:10 -0000 1.1.2.7 @@ -33,8 +33,8 @@ public void testDescription() { AssertMo.assertIncludes( "should contain decorated's description", DECORATED_DESCRIPTION, call.getDescription() ); - AssertMo.assertIncludes( "should say that decorated call is mandatory", - "mandatory", call.getDescription() ); + AssertMo.assertIncludes( "should say that decorated call has called status", + "called", call.getDescription() ); } public void testDoesNotVerifyIfNotCalled() { Index: MockCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockCallFactory.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- MockCallFactory.java 11 Apr 2003 15:38:20 -0000 1.1.2.3 +++ MockCallFactory.java 5 May 2003 22:47:10 -0000 1.1.2.4 @@ -3,9 +3,9 @@ import com.mockobjects.*; import com.mockobjects.dynamic.CallFactory; import com.mockobjects.dynamic.Callable; -import com.mockobjects.constraint.Constraint; +import com.mockobjects.dynamic.ConstraintMatcher; -public class MockCallFactory implements CallFactory, Verifiable { +public class MockCallFactory implements CallFactory{ private ExpectationCounter myCreateReturnStubCalls = new ExpectationCounter("MockCallFactory.createReturnStub(Object)"); private ReturnValues myActualCreateReturnStubReturnValues = new ReturnValues("MockCallFactory.createReturnStub(Object)", true); private ExpectationList myCreateReturnStubParameter0Values = new ExpectationList("MockCallFactory.createReturnStub(Object) java.lang.Object"); @@ -17,11 +17,11 @@ private ExpectationCounter myCreateExpectedCallCalls = new ExpectationCounter("MockCallFactory.createExpectedCall(Callable)"); private ReturnValues myActualCreateExpectedCallReturnValues = new ReturnValues("MockCallFactory.createExpectedCall(Callable)", true); private ExpectationList myCreateExpectedCallParameter0Values = new ExpectationList("MockCallFactory.createExpectedCall(Callable) com.mockobjects.dynamic.Callable"); - private ExpectationCounter myCreateCallMatchCalls = new ExpectationCounter("MockCallFactory.createCallMatch(String, Constraint[], Callable)"); - private ReturnValues myActualCreateCallMatchReturnValues = new ReturnValues("MockCallFactory.createCallMatch(String, Constraint[], Callable)", true); - private ExpectationList myCreateCallMatchParameter0Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], Callable) java.lang.String"); - private ExpectationList myCreateCallMatchParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], Callable) com.mockobjects.constraint.Constraint"); - private ExpectationList myCreateCallMatchParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, Constraint[], Callable) com.mockobjects.dynamic.Callable"); + private ExpectationCounter myCreateCallMatchCalls = new ExpectationCounter("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable)"); + private ReturnValues myActualCreateCallMatchReturnValues = new ReturnValues("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable)", true); + private ExpectationList myCreateCallMatchParameter0Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) java.lang.String"); + private ExpectationList myCreateCallMatchParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.ConstraintMatcher"); + private ExpectationList myCreateCallMatchParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.Callable"); public void setExpectedCreateReturnStubCalls(int calls){ myCreateReturnStubCalls.setExpected(calls); @@ -122,16 +122,16 @@ myCreateCallMatchCalls.setExpected(calls); } - public void addExpectedCreateCallMatch(String arg0, Constraint[] arg1, Callable arg2){ + public void addExpectedCreateCallMatch(String arg0, ConstraintMatcher arg1, Callable arg2){ myCreateCallMatchParameter0Values.addExpected(arg0); - myCreateCallMatchParameter1Values.addExpectedMany(arg1); + myCreateCallMatchParameter1Values.addExpectedMany(arg1.getConstraints()); myCreateCallMatchParameter2Values.addExpected(arg2); } - public Callable createCallMatch(String arg0, Constraint[] arg1, Callable arg2){ + public Callable createCallMatch(String arg0, ConstraintMatcher arg1, Callable arg2){ myCreateCallMatchCalls.inc(); myCreateCallMatchParameter0Values.addActual(arg0); - myCreateCallMatchParameter1Values.addActualMany(arg1); + myCreateCallMatchParameter1Values.addActualMany(arg1.getConstraints()); myCreateCallMatchParameter2Values.addActual(arg2); Object nextReturnValue = myActualCreateCallMatchReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) |
From: Tim M. <ma...@us...> - 2003-05-05 22:47:13
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv17720/core/test/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment ConstraintsTest.java Log Message: Tests for change from Constraint[] to ConstraintMatcher as well as Object[] parameters Before making this change refactored the tests after realisation that if a CallMatch matches returns true, then CallMatch.call does not need to do additional constraint checking - it just performs the call. Index: ConstraintsTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint/ConstraintsTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- ConstraintsTest.java 16 Apr 2003 16:31:48 -0000 1.1.2.3 +++ ConstraintsTest.java 5 May 2003 22:47:09 -0000 1.1.2.4 @@ -6,6 +6,7 @@ import com.mockobjects.constraint.*; import com.mockobjects.dynamic.Mock; +import com.mockobjects.util.AssertMo; import test.mockobjects.dynamic.DummyInterface; @@ -55,17 +56,35 @@ assertTrue( !p.eval(i2) ); } + public void testIsEqualObjectArray() { + String[] s1 = new String[] { "a", "b" }; + String[] s2 = new String[] { "a", "b" }; + String[] s3 = new String[] { "c", "d" }; + String[] s4 = new String[] { "a", "b", "c", "d" }; + + Constraint p = new IsEqual(s1); + + assertTrue( "Should equal itself", p.eval(s1) ); + assertTrue( "Should equal a similar array", p.eval( s2 ) ); + assertTrue( "Should not equal a different array", !p.eval(s3) ); + assertTrue( "Should not equal a different sized array", !p.eval(s4) ); + } + + public void testIsEqualToStringForNestedConstraint() { + assertEquals("Should get an obvious toString to reflect nesting if viewed in a debugger", + " = = NestedConstraint", new IsEqual(new IsEqual("NestedConstraint")).toString()); + } 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()); + AssertMo.assertIncludes("Should get resolved toString() with no expectation error", "MockName", p.toString()); } public void testIsEqualEquals() throws Exception { assertEquals("Should be equal", new IsEqual("a"), new IsEqual("a")); - assertFalse("Should not be equal - same type", new IsEqual("a").equals(new IsEqual("b"))); + assertFalse("Should not be equal - same type different values", new IsEqual("a").equals(new IsEqual("b"))); assertFalse("Should not be equal - different type", new IsEqual("a").equals("b")); } |