Package groovy.lang

Examples of groovy.lang.IntRange


        assertEquals("substring(1,3)", object.substring(1, 3), value);
    }

    public void testListGetWithRange() throws Throwable {
        List list = Arrays.asList(new Object[]{"a", "b", "c"});
        Object range = new IntRange(0, 2);
        Object value = invoke(list, "getAt", range);
        assertTrue("Returned List: " + value, value instanceof List);
        List retList = (List) value;
        assertEquals("List size", 3, retList.size());
    }
View Full Code Here


        // case, we need to reverse them and make sure the range's 'reverse'
        // property is correct.
        // TODO We should probably use DefaultGroovyMethodsSupport.subListBorders(),
        // but that's protected and unavailable to us.
        if (from > to) {
            r = r.isReverse() ? new IntRange(to, from) : new IntRange(from, to);
            from = r.getFromInt();
            to = r.getToInt();
        }

        // Copy the required nodes into a new list.
View Full Code Here

        assertEquals("substring(1,3)", object.substring(1, 3), value);
    }

    public void testListGetWithRange() throws Throwable {
        List list = Arrays.asList(new Object[]{"a", "b", "c"});
        Object range = new IntRange(0, 2);
        Object value = invoke(list, "getAt", range);
        assertTrue("Returned List: " + value, value instanceof List);
        List retList = (List) value;
        assertEquals("List size", 3, retList.size());
    }
View Full Code Here

        return RangeConstraint.class;
    }

    public void testValidation() {
        testConstraintMessageCodes(
                getConstraint("testInteger", new IntRange(1, 5)), 7L,
                new String[] {"testClass.testInteger.range.error","testClass.testInteger.range.toobig"},
                new Object[] {"testInteger",TestClass.class, 7L, 1, 5 });

        testConstraintMessageCodes(
                getConstraint("testInteger", new IntRange(1, 5)), 0,
                new String[] {"testClass.testInteger.range.error","testClass.testInteger.range.toosmall"},
                new Object[] {"testInteger",TestClass.class, 0, 1, 5 });

        testConstraintPassed(
                getConstraint("testString", new ObjectRange("abca","abcf")),
                "abcd");

        testConstraintPassed(getConstraint("testInteger", new IntRange(1, 7)), 5);

        // must always pass for null value
        testConstraintPassed(getConstraint("testInteger", new IntRange(1, 7)), null);

        testConstraintDefaultMessage(
                getConstraint("testInteger", new IntRange(1, 5)),
                7,
                "Property [{0}] of class [{1}] with value [{2}] does not fall within the valid range from [{3}] to [{4}]");
    }
View Full Code Here

                7,
                "Property [{0}] of class [{1}] with value [{2}] does not fall within the valid range from [{3}] to [{4}]");
    }

    public void testCreation() {
        RangeConstraint constraint = (RangeConstraint) getConstraint("testInteger", new IntRange(1,5));
        assertEquals(ConstrainedProperty.RANGE_CONSTRAINT, constraint.getName());
        assertTrue(constraint.supports(Integer.class));
        assertTrue(constraint.supports(Long.class));
        assertTrue(constraint.supports(Double.class));
        assertFalse(constraint.supports(Object.class));
        assertFalse(constraint.supports(null));
        assertEquals(new IntRange(1,5), constraint.getRange());

        try {
            getConstraint("testInteger", "wrong");
            fail("RangeConstraint must throw an exception for non-range parameters.");
        } catch (IllegalArgumentException iae) {
View Full Code Here

        cp.applyConstraint(ConstrainedProperty.MIN_SIZE_CONSTRAINT, 5);
        assertEquals(5, cp.getMinSize().intValue());

        // validate that getMinSize returns the correct value when the size constraint is defined for the property (but no minSize constraint is defined)
        cp = new ConstrainedProperty(getClass(), "testURL", String.class);
        cp.applyConstraint(ConstrainedProperty.SIZE_CONSTRAINT, new IntRange(10, 20));
        assertEquals(10, cp.getMinSize().intValue());

        // validate that getMinSize returns the maximum of the minSize constraint and the lower bound of the size constraint
        //   1) validate where the lower bound of the size constraint is greater than the minSize constraint
        cp = new ConstrainedProperty(getClass(), "testURL", String.class);
        cp.applyConstraint(ConstrainedProperty.MIN_SIZE_CONSTRAINT, 6);
        cp.applyConstraint(ConstrainedProperty.SIZE_CONSTRAINT, new IntRange(11, 21));
        assertEquals(11, cp.getMinSize().intValue());

        //   2) validate where the minSize constraint is greater than the lower bound of the size constraint
        cp = new ConstrainedProperty(getClass(), "testURL", String.class);
        cp.applyConstraint(ConstrainedProperty.MIN_SIZE_CONSTRAINT, 12);
        cp.applyConstraint(ConstrainedProperty.SIZE_CONSTRAINT, new IntRange(9, 22));
        assertEquals(12, cp.getMinSize().intValue());
    }
View Full Code Here

        cp.applyConstraint(ConstrainedProperty.MAX_SIZE_CONSTRAINT, 5);
        assertEquals(5, cp.getMaxSize().intValue());

        // validate that getMaxSize returns the correct value when the size constraint is defined for the property (but no maxSize constraint is defined)
        cp = new ConstrainedProperty(getClass(), "testURL", String.class);
        cp.applyConstraint(ConstrainedProperty.SIZE_CONSTRAINT, new IntRange(10, 20));
        assertEquals(20, cp.getMaxSize().intValue());

        // validate that getMaxSize returns the minimum of the maxSize constraint and the upper bound of the size constraint
        //   1) validate where the upper bound of the size constraint is less than the maxSize constraint
        cp = new ConstrainedProperty(getClass(), "testURL", String.class);
        cp.applyConstraint(ConstrainedProperty.MAX_SIZE_CONSTRAINT, 29);
        cp.applyConstraint(ConstrainedProperty.SIZE_CONSTRAINT, new IntRange(11, 21));
        assertEquals(21, cp.getMaxSize().intValue());

        //   2) validate where the maxSize constraint is less than the upper bound of the size constraint
        cp = new ConstrainedProperty(getClass(), "testURL", String.class);
        cp.applyConstraint(ConstrainedProperty.MAX_SIZE_CONSTRAINT, 12);
        cp.applyConstraint(ConstrainedProperty.SIZE_CONSTRAINT, new IntRange(9, 22));
        assertEquals(12, cp.getMaxSize().intValue());
    }
View Full Code Here

    }

    @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}]");
    }
View Full Code Here

                "123456",
                "Property [{0}] of class [{1}] with value [{2}] does not fall within the valid size range from [{3}] to [{4}]");
    }

    public void testCreation() {
        SizeConstraint constraint = (SizeConstraint) getConstraint("testInteger", new IntRange(1,5));
        assertEquals(ConstrainedProperty.SIZE_CONSTRAINT, constraint.getName());
        assertTrue(constraint.supports(List.class));
        assertTrue(constraint.supports(Collection.class));
        assertTrue(constraint.supports(Double[].class));
        assertFalse(constraint.supports(Object.class));
        assertFalse(constraint.supports(null));
        assertFalse(constraint.supports(Integer.class));
        assertFalse(constraint.supports(Number.class));
        assertEquals(new IntRange(1,5), constraint.getRange());

        try {
            getConstraint("testInteger", "wrong");
            fail("SizeConstraint must throw an exception for non-range parameters.");
        } catch(IllegalArgumentException iae) {
View Full Code Here

        List<String> lines = StringGroovyMethods.readLines(body);

        // split the form-data lines around the boundaries
        // remove a first surrounding empty lines and closing boundary
        // trim the last \n characters
        List<String> parts = DefaultGroovyMethods.getAt(body.split(lines.get(0).trim()), new IntRange(true, 1,-2));
        for (int i = 0; i < parts.size(); i++) {
            parts.set(i, parts.get(i).trim());
        }       

        // reads the part keys and values into a Map
View Full Code Here

TOP

Related Classes of groovy.lang.IntRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.