我在Grails的這種約束對於這一領域:Grails getErrorCount()返回多個錯誤,如何獲取錯誤列表?
businessNumber(matches: '([0-9A-Z]*9)RA([0-9A-Z]*4)', maxSize: 15)
我把最大範圍的約束,這樣的Grails嵌入在HTML視圖的maxlength屬性。我做一個單元測試,看起來像這樣的約束:
void testBusinessNumberExceedMaxSize(){
mockChildrenSpecialAllowancesForm.setBusinessNumber("F%G&Hy934F4G6H%55")
assertFalse (mockChildrenSpecialAllowancesForm.validate())
assertEquals ("maxSize",mockChildrenSpecialAllowancesForm.errors.businessNumber)
assertEquals (2, mockChildrenSpecialAllowancesForm.errors.getErrorCount())
}
然後,它會產生此故障:
testBusinessNumberExceedMaxSize(com.ass.socialservicescm.ChildrenSpecialAllowancesTests)
| org.junit.ComparisonFailure: expected:<ma[xSize]> but was:<ma[tches]>
at org.junit.Assert.assertEquals(Assert.java:125)
at org.junit.Assert.assertEquals(Assert.java:147)
at com.ass.socialservicescm.ChildrenSpecialAllowancesTests.testBusinessNumberExceedMaxSize(ChildrenSpecialAllowancesTests.groovy:177)
我認爲它違反了2個約束(因爲我的錯誤計數2)一個是maxSize,另一個是匹配。但是,我如何做maxSize約束的assertEquals?
注:我使用的Grails 2.0.0