forked from grails/grails-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAILS-12010 - throw ConstraintException instead of IllegalStateExcep…
…tion
- Loading branch information
Jeff Scott Brown
committed
Mar 10, 2015
1 parent
06b6b90
commit 49bcba2
Showing
3 changed files
with
58 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
grails-validation/src/test/groovy/grails/validation/ConstraintTypeMismatchSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package grails.validation | ||
|
||
import grails.validation.exceptions.ConstraintException | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class ConstraintTypeMismatchSpec extends Specification { | ||
|
||
@Unroll | ||
void 'test calling #methodName on a ConstrainedProperty for a non-String property'() { | ||
given: | ||
def cp = new ConstrainedProperty(ConstraintTypeMismatchSpec, 'testProperty', Integer); | ||
|
||
expect: | ||
cp."$methodName"() == expectedResult | ||
|
||
where: | ||
methodName | expectedResult | ||
'isEmail' | false | ||
'isCreditCard' | false | ||
'isUrl' | false | ||
'getMatches' | null | ||
'isUrl' | false | ||
} | ||
|
||
@Unroll | ||
void 'test calling set#constraintName(#argValue) on a ConstrainedProperty for a non-String property'() { | ||
given: | ||
def cp = new ConstrainedProperty(ConstraintTypeMismatchSpec, 'testProperty', Integer); | ||
|
||
when: | ||
cp."set${constraintName}"(argValue) | ||
|
||
then: | ||
ConstraintException ex = thrown() | ||
"$constraintName constraint can only be applied to String properties" == ex.message | ||
|
||
where: | ||
constraintName | argValue | ||
'Email' | true | ||
'CreditCard' | true | ||
'Url' | true | ||
'Matches' | '.*' | ||
'Blank' | true | ||
} | ||
} |