I'm using the ExpandoMetaClass to make a service always return success in an integration test but I would like to have one test that actually fails.
Example use of ExpandoMetaClass:
static {
ExpandoMetaClass someService = new ExpandoMetaClass(Object, false)
someService.accessAnotherSystem = { return 'success' }
someService.initialize()
SomeService.metaClass = someService
}
Note: currently the service isn't defined for the controller but since it's a spring bean referencing the class named SomeService
like someService.accessAnotherSystem()
works just fine i.e. there is no def someService
in the controller.
Therefore I can't do controller.someService.metaClass.accessAnotherSystem = { return 'failure'}
from the integration test.
Also note: this is an integration test for a webflow.
Is it possible to reset the metaClass for one test, or in someway test what I want?
The below works fine if the test is ran by itself, however the ExpandoMetaClass is overridden if another test that uses SomeService is ran before it. I'll be opening another question for that problem.