Exemplo n.º 1
0
  // method calls with spread-dot operator are not rewritten, hence this method doesn't have to care
  // about spread-dot
  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 && GroovyRuntimeUtil.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);
    }
  }
Exemplo n.º 2
0
    void verify(
        @Nullable ErrorCollector errorCollector,
        @Nullable List<Object> values,
        @Nullable String text,
        int line,
        int column,
        @Nullable String message) {
      if (HamcrestFacade.matches(matcher, actual)) return;

      if (values != null) {
        CollectionUtil.setLastElement(values, shortSyntax ? actual : false);
        replaceMatcherValues(values);
      }

      String description = HamcrestFacade.getFailureDescription(matcher, actual, message);
      Condition condition =
          new Condition(values, text, TextPosition.create(line, column), description, null, null);
      errorCollector.collectOrThrow(new ConditionNotSatisfiedError(condition));
    }