From: Tim M. <tim...@po...> - 2003-02-18 00:24:57
|
I was going to suggest that Vincent could wrap the NamingManager object in some better behaved implementation - as exposing the reset stuff does set a dangerous precedent (we observe mocks getting used for all kinds of wierd stuff)... However I have a second observation that supports his reset's as well. Often you initialize a default state in the setup method used by all test methods in a fixture - and then once in a while there are one or two tests out of the 10-15 that just want a slightly different set of expectations - and you know, its a pain in the ass to redefine all of that share stuff for those two tests - and so I've often just wanted to reset that one expectation and leave the rest of the infrastructure in place... its maybe not totally pure - but readability is actually better and in general its what people expect (you often waste a few minutes trying to refactor that duplication back into setup only to discover that one difference that made you duplicate it in the first place). So I second vincents request (maybe with some caveat that reset has a description where you document why you are doing this?) Tim -----Original Message----- From: moc...@li... [mailto:moc...@li...]On Behalf Of Vincent Massol Sent: 17 February 2003 17:43 To: 'Steve Freeman' Cc: 'MockObjects' Subject: RE: [MO-java-dev] Reusing dynamic mocks? Hi Steve, > -----Original Message----- > From: Steve Freeman [mailto:st...@m3...] > Sent: 17 February 2003 16:27 > To: Vincent Massol > Subject: Re: [MO-java-dev] Reusing dynamic mocks? > > Vincent Massol wrote: > > Hi, > > > > I have a scenario where I have to reuse the same Dynamic Mock for > > several tests. However, it appears that there is no "reset()" methods on > > the Mock class. Am I missing something? If not, can I add the following > > to Mock.java: > > > > public void reset() > > { > > this.methods = new MethodMap(); > > } > > Does it really have to be the same instance each time? Actually yes. The scenario is as follows: I am setting up my own JNDI implementation which, upon call to "new InitialContext()" returns a Mock Context object. However, setting up one's own JNDI implementation (by calling NamingManager.setInitialContextFactoryBuilder) can only be done once during the VM's lifetime. Thus, I am wrapping this in a TestSetup. This means that I have only one chance to define what will be the mock returned upon calls to "new InitialContext()". I believe there are use cases for the reset() stuff. Let me know what you think. Thanks -Vincent > > I'd suggest wrapping up mock object creation in a helper method and > generate a new copy for each test. > > S. > ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.455 / Virus Database: 255 - Release Date: 13/02/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.455 / Virus Database: 255 - Release Date: 13/02/2003 |