1 package org
.codehaus
.groovy
.grails
.validation
;
4 * Tests for 'blank' constraint.
6 * @author Sergey Nebolsin (<a href="mailto:nebolsin@gmail.com"/>)
8 public class BlankConstraintTests
extends AbstractConstraintTests
{
9 protected Class
getConstraintClass() {
10 return BlankConstraint
.class;
13 public void testValidate() {
14 testConstraintMessageCodes(
15 getConstraint( "testString", Boolean
.FALSE
),
17 new String
[] {"testClass.testString.blank.error","testClass.testString.blank"},
18 new Object
[] {"testString", TestClass
.class }
22 getConstraint( "testString", Boolean
.FALSE
),
27 getConstraint( "testString", Boolean
.TRUE
),
31 testConstraintFailedAndVetoed(
32 getConstraint( "testString", Boolean
.FALSE
),
37 getConstraint( "testString", Boolean
.FALSE
),
41 testConstraintDefaultMessage(
42 getConstraint( "testString", Boolean
.FALSE
),
44 "Property [{0}] of class [{1}] cannot be blank"
48 public void testConstraintCreation() {
49 BlankConstraint constraint
= new BlankConstraint();
50 assertEquals( ConstrainedProperty
.BLANK_CONSTRAINT
, constraint
.getName());
51 assertTrue( constraint
.supports( String
.class ));
52 assertFalse( constraint
.supports( null ));
53 assertFalse( constraint
.supports( Long
.class ));
54 constraint
= (BlankConstraint
) getConstraint( "testString", Boolean
.TRUE
);
55 assertEquals( Boolean
.TRUE
, constraint
.getParameter() );
58 getConstraint( "testString", "wrong");
59 fail("BlankConstraint must throw an exception for non-boolean parameters.");
60 } catch( IllegalArgumentException iae
) {