private boolean satisfiesCondition(IMethodInvocation invocation, Throwable failure) { if (condition == null) { return true; } condition.setDelegate(new RetryConditionContext(invocation, failure)); condition.setResolveStrategy(Closure.DELEGATE_ONLY); try { return GroovyRuntimeUtil.isTruthy(condition.call()); } catch (Exception e) { throw new ExtensionException("Failed to evaluate @Retry condition", e); } }
private void doVisit(Requires annotation, ISkippable skippable) { Closure condition = createCondition(annotation.value()); Object result = evaluateCondition(condition); if (!GroovyRuntimeUtil.isTruthy(result)) { skippable.setSkipped(true); } }
private void doVisit(IgnoreIf annotation, ISkippable skippable) { Closure condition = createCondition(annotation.value()); Object result = evaluateCondition(condition); if (GroovyRuntimeUtil.isTruthy(result)) { skippable.setSkipped(true); } }
public static void verifyCondition(@Nullable ErrorCollector errorCollector, @Nullable ValueRecorder recorder, @Nullable String text, int line, int column, @Nullable Object message, @Nullable Object condition) { if (!GroovyRuntimeUtil.isTruthy(condition)) { final ConditionNotSatisfiedError conditionNotSatisfiedError = new ConditionNotSatisfiedError( new Condition(getValues(recorder), text, TextPosition.create(line, column), messageToString(message), null, null)); errorCollector.collectOrThrow(conditionNotSatisfiedError); } }
public static void verifyMethodCondition(@Nullable ErrorCollector errorCollector, @Nullable ValueRecorder recorder, @Nullable String text, int line, int column, @Nullable Object message, Object target, String method, Object[] args, boolean safe, boolean explicit, int lastVariableNum) { MatcherCondition matcherCondition = MatcherCondition.parse(target, method, args, safe); if (matcherCondition != null) { matcherCondition.verify(errorCollector, getValues(recorder), text, line, column, messageToString(message)); return; } if (recorder != null) { recorder.startRecordingValue(lastVariableNum); } Object result = safe ? GroovyRuntimeUtil.invokeMethodNullSafe(target, method, args) : GroovyRuntimeUtil.invokeMethod(target, method, args); if (!explicit && result == null && isVoidMethod(target, method, args)) return; if (!GroovyRuntimeUtil.isTruthy(result)) { List<Object> values = getValues(recorder); if (values != null) CollectionUtil.setLastElement(values, result); final ConditionNotSatisfiedError conditionNotSatisfiedError = new ConditionNotSatisfiedError( new Condition(values, text, TextPosition.create(line, column), messageToString(message), null, null)); errorCollector.collectOrThrow(conditionNotSatisfiedError); } }