void replaceMatcherValues(List<Object> values) { boolean firstOccurrence = true; ListIterator<Object> iter = values.listIterator(values.size()); while (iter.hasPrevious()) { Object value = iter.previous(); if (!HamcrestFacade.isMatcher(value)) continue; if (firstOccurrence) { // indicate mismatch in condition output iter.set(shortSyntax ? false : ExpressionInfo.VALUE_NOT_AVAILABLE); firstOccurrence = false; } else { // don't show in condition output iter.set(ExpressionInfo.VALUE_NOT_AVAILABLE); } } }
@Nullable static MatcherCondition parse(Object target, String method, Object[] args, boolean safe) { if (safe) return null; if ("call".equals(method)) { if (args.length != 1 || !HamcrestFacade.isMatcher(args[0])) return null; return new MatcherCondition(target, args[0], true); } if ("that".equals(method) || "expect".equals(method)) { if (target != spock.util.matcher.HamcrestSupport.class) return null; if (args.length != 2 || !HamcrestFacade.isMatcher(args[1])) return null; return new MatcherCondition(args[0], args[1], false); } return null; } }
@Override public boolean isSatisfiedBy(Object arg) { if (HamcrestFacade.isMatcher(expected)) { return HamcrestFacade.matches(expected, arg); } return GroovyRuntimeUtil.equals(arg, expected); }
@Override public String describeMismatch(Object arg) { if (HamcrestFacade.isMatcher(expected)) { return HamcrestFacade.getFailureDescription(expected, arg, null); } Condition condition = new Condition(CollectionUtil.listOf(arg, expected, false), "argument == expected", null, null, null, null); return condition.getRendering(); } }