private boolean checkMatcher(Context context) { Node expectedNode = context.getExpectedNode(); Node actualNode = context.getActualNode(); if (expectedNode.getNodeType() == NodeType.STRING) { Matcher patternMatcher = MATCHER_PLACEHOLDER_PATTERN.matcher(expectedNode.asText()); if (patternMatcher.matches()) { String matcherName = patternMatcher.group(1); org.hamcrest.Matcher<?> matcher = configuration.getMatcher(matcherName); if (matcher != null) { if (matcher instanceof ParametrizedMatcher) { ((ParametrizedMatcher) matcher).setParameter(patternMatcher.group(2)); } Object value = actualNode.getValue(); if (!matcher.matches(value)) { Description description = new StringDescription(); matcher.describeMismatch(value, description); reportValueDifference(context, "Matcher \"%s\" does not match value %s in node \"%s\". %s", matcherName, quoteTextValue(actualNode), context.getActualPath(), description); } } else { structureDifferenceFound(context, "Matcher \"%s\" not found.", matcherName); } return true; } } return false; }
private boolean checkMatcher(Context context) { Node expectedNode = context.getExpectedNode(); Node actualNode = context.getActualNode(); if (expectedNode.getNodeType() == NodeType.STRING) { Matcher patternMatcher = MATCHER_PLACEHOLDER_PATTERN.matcher(expectedNode.asText()); if (patternMatcher.matches()) { String matcherName = patternMatcher.group(1); org.hamcrest.Matcher<?> matcher = configuration.getMatcher(matcherName); if (matcher != null) { if (matcher instanceof ParametrizedMatcher) { ((ParametrizedMatcher) matcher).setParameter(patternMatcher.group(2)); } Object value = actualNode.getValue(); if (!matcher.matches(value)) { Description description = new StringDescription(); matcher.describeMismatch(value, description); reportValueDifference(context, "Matcher \"%s\" does not match value %s in node \"%s\". %s", matcherName, quoteTextValue(actualNode), context.getActualPath(), description); } } else { structureDifferenceFound(context, "Matcher \"%s\" not found.", matcherName); } return true; } } return false; }