1 package org
.codehaus
.groovy
.grails
.validation
;
4 * Test cases for 'email' constraint.
6 * @author Sergey Nebolsin (<a href="mailto:nebolsin@gmail.com"/>)
8 public class EmailConstraintTests
extends AbstractConstraintTests
{
10 protected Class
getConstraintClass() {
11 return EmailConstraint
.class;
14 public void testValidation() {
15 testConstraintMessageCodes(
16 getConstraint( "testString", Boolean
.TRUE
),
18 new String
[] {"testClass.testString.email.error","testClass.testString.email.invalid"},
19 new Object
[] {"testString",TestClass
.class,"wrong_email"}
23 getConstraint( "testString", Boolean
.TRUE
),
28 testConstraintDefaultMessage(
29 getConstraint( "testString", Boolean
.TRUE
),
31 "Property [{0}] of class [{1}] with value [{2}] is not a valid e-mail address"
36 public void testNullValue() {
37 // must always pass for null value
39 getConstraint( "testString", Boolean
.TRUE
),
44 public void testBlankString() {
45 // must always pass for blank value
47 getConstraint( "testString", Boolean
.TRUE
),
53 public void testCreation() {
54 EmailConstraint constraint
= new EmailConstraint();
55 assertEquals( ConstrainedProperty
.EMAIL_CONSTRAINT
, constraint
.getName() );
56 assertTrue( constraint
.supports( String
.class ));
57 assertFalse( constraint
.supports( null ));
58 assertFalse( constraint
.supports( Long
.class ));
61 getConstraint( "testString", "wrong");
62 fail("EmailConstraint must throw an exception for non-boolean parameters.");
63 } catch( IllegalArgumentException iae
) {