From: Vincent M. <vm...@oc...> - 2003-02-17 17:43:20
|
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. > |