Is there a less bloated way to test constraints? It seems to me that this is too much code to test constraints.
class BlogPostTests extends GrailsUnitTestCase {
protected void setUp() {
super.setUp()
mockDomain BlogPost
}
void testConstraints() {
BlogPost blogPost = new BlogPost(title: "", text: "")
assertFalse blogPost.validate()
assertEquals 2, blogPost.errors.getErrorCount()
assertEquals "blank", blogPost.errors.getFieldError("title").getCode()
assertEquals "blank", blogPost.errors.getFieldError("text").getCode()
blogPost = new BlogPost(title: "title", text: ObjectMother.bigText(2001))
assertFalse blogPost.validate()
assertEquals 1, blogPost.errors.getErrorCount()
assertEquals "maxSize.exceeded", blogPost.errors.getFieldError("text").getCode()
}
}