【发布时间】:2014-12-19 14:37:33
【问题描述】:
我在 sources/groovy 中定义了一个 Groovy 助手类,我正在尝试使用 Spock 进行测试。我尝试测试的类引用了 org.springframework.validation.Errors,称为错误 ..
我定义了一个测试,它调用下面显示的一些代码..
def validateSuppliedDocument() {
// If we create one it's always valid ..
if (txn.transactionType.autoCreateDocument) {
return true
} else {
txn.documentHeader =
DocumentHeader.findByDocumentReferenceCodeAndDocumentType(txn.documentReferenceCode, txn.transactionType.associatedDocumentType)
if (!txn.documentHeader) {
errors.rejectValue('documentReferenceCode', "document.not.found",
[txn.documentReferenceCode].toArray(), 'Document not found')
return false
}
我的问题是由 'errors.rejectValue' 语句引起的,因为错误实例为 null ..
我怎样才能让 grails 注入它只是为了测试目的,应该给什么类,因为 Errors 是一个接口?
仅供参考,此方法作为字段验证器的一部分被调用(如果有帮助的话..)并在生产中正常工作..
谢谢
【问题讨论】: