From: Vincent M. <vm...@pi...> - 2003-05-17 18:54:50
|
Hi, I have a requirement for introducing a reset on dyna mocks so that they can be reused. Here's the use case: I am setting up a Mock InitialContext factory with: NamingManager.setInitialContextFactoryBuilder( new InitialContextFactoryBuilder() { public InitialContextFactory createInitialContextFactory( Hashtable environment) throws NamingException { return new InitialContextFactory() { public Context getInitialContext(Hashtable env) throws NamingException { // Return the mock context here return context; } }; } }); The setInitialContextFactoryBuilder() is a static method and can only be called *ONCE* in the lifetime of the JVM. Which means that it will be shared between testXXX() tests. Thus the InitialContext mock (in "return context") also has to be static. The second step is to define expectations on the context mock lookup() method so that we can return mocks. By doing this we are tying the static context mock with the other per-testXXX() mocks... ... which means that if we have 2 test methods setting expectations on lookup() with the same lookup name, the second test fails.... I believe this is a valid use case and that in order to support this use case, we need to introduce a reset() method in the dynamock Mock class to rest all expectations. I've just committed the patch to support this reset method. If you think we should not have a reset() method, I can always remove it. Thanks -Vincent |