private void executeOutputMatchAssertion()

in junit/src/org/apache/tapestry/junit/mock/MockTester.java [654:720]


    private void executeOutputMatchAssertion(Element element, String outputString)
        throws DocumentParseException
    {
        String name = element.getAttributeValue("name");
        String value = element.getAttributeValue("subgroup");
        int subgroup = (value == null) ? 0 : Integer.parseInt(value);

        String pattern = element.getTextTrim();

        if (Tapestry.isBlank(pattern))
            throw new DocumentParseException("Pattern is null in " + element);

        PatternMatcherInput input = new PatternMatcherInput(outputString);

        PatternMatcher matcher = getMatcher();
        Pattern compiled = compile(pattern);

        List l = element.getChildren("match");
        int count = l.size();
        int i = 0;

        while (matcher.contains(input, compiled))
        {
            MatchResult match = matcher.getMatch();

            if (i >= count)
            {
                System.err.println(outputString);
                throw new AssertionFailedError(
                    buildTestName(name) + ": Too many matches for '" + pattern + "'.");
            }

            Element e = (Element) l.get(i);
            String expected = e.getTextTrim();
            String actual = match.group(subgroup);

            if (!actual.equals(expected))
            {
                System.err.println(outputString);
                throw new AssertionFailedError(
                    buildTestName(name)
                        + "["
                        + i
                        + "]: Expected '"
                        + expected
                        + "' but got '"
                        + actual
                        + "'.");
            }

            i++;
        }

        if (i < count)
        {
            System.err.println(outputString);
            throw new AssertionFailedError(
                buildTestName(name)
                    + ": Too few matches for '"
                    + pattern
                    + "' (expected "
                    + count
                    + " but got "
                    + i
                    + ").");
        }
    }