Working with Stub and Mock objects in Groovy has been a very interesting (and fun) task to me. Today I needed to modify a method’s behavior for an integration test avoiding unnecessary remote calls however the next test should be performed using the remote behavior (strange, but…).
So, for this solution I simply changed the method’s execution in run time using meta programming, easy. The problem was: how to do the rollback to the original state? After some researches I found two ways that I would like to share: