我有一个组件
@Component
class SomeComponent {
@Autowired
GrailsApplication grailsApplication
String buildString(String someInfo) {
return "${grailsApplication.config.my.string}${someInfo}"
}
}
和一个单元测试
@TestMixin(ControllerUnitTestMixin)
class SomeComponent Tests {
@Test
void test() {
SomeComponent component = new SomeComponent()
component.grailsApplication = new Expando()
component.grailsApplication.config = [config: [my: [string: 'FOO']]]
assert component.buildString('BAR') == 'FOOBAR'
}
}
当我执行我的测试时,我得到了这个错误:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{}' with class 'groovy.util.Expando' to class 'org.codehaus.groovy.grails.commons.GrailsApplication'
那么最好的方法是什么?