GrailsUnitTest.defineBeans(new PluginClass()) does not set grailsApplication /applicationContext? #43
Description
I have a custom TagLib that makes use of the asset-pipeline-grails (version 3.0.6) AssetsTagLib to display images. It calls asset.image() to output an image tag when it renders.
In order to test this, I have a CustomTagLibSpec that implements TagLibUnitTest, and in the setup method I was expecting to be able to do the following to bootstrap and mock the the relevant asset dependencies:
setup() {`
defineBeans(new AssetPipelineGrailsPlugin())
mockTagLib(AssetsTagLib)
mockTagLib(AssetMethodTagLib)
}
On running the unit test though, I get a failure because grailsApplication is used in the AssetPipelineGrailsPlugin.doWithSpring Closure, and that is not set.
If I change my unit test code to
setup() {`
def assetPlugin = new AssetPipelineGrailsPlugin()
assetPlugin.applicationContext = applicationContext
assetPlugin.grailsApplicatin = grailsApplication
defineBeans(assetPlugin)
mockTagLib(AssetsTagLib)
mockTagLib(AssetMethodTagLib)
}
Then my unit test works.
Given that all plugins implement Plugin, and therefore ApplicationContextAware, and GrailsApplicationAware, can the defineBeans(Object plugin) method in GrailsUnitTest be changed to set the grailsApplication and applicationContext from the unit test to avoid having to do it manually please ?