我正在尝试为我正在开发的 Spring WebApp 编写集成测试。在此过程中的某个时刻,我正在BindingResult
使用以下代码从错误列表中提取错误列表:
BindingResult checkMe = (BindingResult)mv.getModelMap().get("org.springframework.validation.BindingResult.module");
assertEquals(1, check.getErrorCount());
//Check to make sure it is the right field that errored, and had the right error.
if(check.hasErrors()){
List<ObjectError> errors = checkMe.getAllErrors();
assertEquals(1, errors.size());
ObjectError tester = errors.get(0);
assertEquals("Range", tester.getCode());
assertEquals("must be between 0 and 365", tester.getDefaultMessage());
}
我想添加一行来断言引发错误的字段实际上是“daysToComplete”。我知道信息在某处,因为checkMe.getAllErrors().toString()
返回:
[Field error in object 'module' on field 'daysToComplete': rejected value [1000]; codes [Range.module.daysToComplete,Range.daysToComplete,Range.int,Range]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [module.daysToComplete,daysToComplete]; arguments []; default message [daysToComplete],365,0]; default message [must be between 0 and 365]]
我如何才能获得该领域本身?我查看了文档并询问了谷歌,但似乎没有任何结果......