Search in sources :

Example 6 with IntRange

use of groovy.lang.IntRange in project grails-core by grails.

the class SizeConstraintTests method testValidation.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void testValidation() {
    testConstraintMessageCodes(getConstraint("testString", new IntRange(2, 5)), "123456", new String[] { "testClass.testString.size.error", "testClass.testString.size.toobig" }, new Object[] { "testString", TestClass.class, "123456", 2, 5 });
    testConstraintMessageCodes(getConstraint("testString", new IntRange(2, 5)), "1", new String[] { "testClass.testString.size.error", "testClass.testString.size.toosmall" }, new Object[] { "testString", TestClass.class, "1", 2, 5 });
    testConstraintPassed(getConstraint("testArray", new IntRange(2, 5)), new String[] { "one", "two", "three" });
    List list = new ArrayList();
    list.add("one");
    testConstraintFailed(getConstraint("testArray", new IntRange(2, 5)), list);
    list.add("two");
    testConstraintPassed(getConstraint("testArray", new IntRange(2, 5)), list);
    // must always pass on null value
    testConstraintPassed(getConstraint("testArray", new IntRange(2, 5)), null);
    testConstraintDefaultMessage(getConstraint("testString", new IntRange(1, 5)), "123456", "Property [{0}] of class [{1}] with value [{2}] does not fall within the valid size range from [{3}] to [{4}]");
}
Also used : IntRange(groovy.lang.IntRange) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

IntRange (groovy.lang.IntRange)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EmptyRange (groovy.lang.EmptyRange)1 Range (groovy.lang.Range)1 Collection (java.util.Collection)1