Search in sources :

Example 1 with ParameterInfo

use of io.cucumber.core.backend.ParameterInfo in project cucumber-jvm by cucumber.

the class JavaParameterInfo method fromMethod.

static List<ParameterInfo> fromMethod(Method method) {
    List<ParameterInfo> result = new ArrayList<>();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] annotations = method.getParameterAnnotations();
    for (int i = 0; i < genericParameterTypes.length; i++) {
        boolean transposed = false;
        for (Annotation annotation : annotations[i]) {
            if (annotation instanceof Transpose) {
                transposed = ((Transpose) annotation).value();
            }
        }
        result.add(new JavaParameterInfo(genericParameterTypes[i], transposed));
    }
    return result;
}
Also used : Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) ParameterInfo(io.cucumber.core.backend.ParameterInfo) Annotation(java.lang.annotation.Annotation)

Example 2 with ParameterInfo

use of io.cucumber.core.backend.ParameterInfo in project cucumber-jvm by cucumber.

the class PickleStepDefinitionMatch method runStep.

@Override
public void runStep(TestCaseState state) throws Throwable {
    List<Argument> arguments = getArguments();
    List<ParameterInfo> parameterInfos = stepDefinition.parameterInfos();
    if (parameterInfos != null && arguments.size() != parameterInfos.size()) {
        throw arityMismatch(parameterInfos.size());
    }
    List<Object> result = new ArrayList<>();
    try {
        for (Argument argument : arguments) {
            result.add(argument.getValue());
        }
    } catch (UndefinedDataTableTypeException e) {
        throw registerDataTableTypeInConfiguration(e);
    } catch (CucumberExpressionException | CucumberDataTableException | CucumberDocStringException e) {
        CucumberInvocationTargetException targetException;
        if ((targetException = causedByCucumberInvocationTargetException(e)) != null) {
            throw removeFrameworkFrames(targetException);
        }
        throw couldNotConvertArguments(e);
    } catch (CucumberBackendException e) {
        throw couldNotInvokeArgumentConversion(e);
    } catch (CucumberInvocationTargetException e) {
        throw removeFrameworkFrames(e);
    }
    try {
        stepDefinition.execute(result.toArray(new Object[0]));
    } catch (CucumberBackendException e) {
        throw couldNotInvokeStep(e, result);
    } catch (CucumberInvocationTargetException e) {
        throw removeFrameworkFramesAndAppendStepLocation(e, getStepLocation());
    }
}
Also used : CucumberDocStringException(io.cucumber.docstring.CucumberDocStringException) Argument(io.cucumber.core.stepexpression.Argument) ArrayList(java.util.ArrayList) ParameterInfo(io.cucumber.core.backend.ParameterInfo) CucumberExpressionException(io.cucumber.cucumberexpressions.CucumberExpressionException) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) UndefinedDataTableTypeException(io.cucumber.datatable.UndefinedDataTableTypeException) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) CucumberDataTableException(io.cucumber.datatable.CucumberDataTableException)

Example 3 with ParameterInfo

use of io.cucumber.core.backend.ParameterInfo in project cucumber-jvm by cucumber.

the class StepExpressionFactory method createExpression.

public StepExpression createExpression(StepDefinition stepDefinition) {
    List<ParameterInfo> parameterInfos = stepDefinition.parameterInfos();
    if (parameterInfos.isEmpty()) {
        return createExpression(stepDefinition.getPattern(), stepDefinitionDoesNotTakeAnyParameter(stepDefinition), false);
    }
    ParameterInfo parameterInfo = parameterInfos.get(parameterInfos.size() - 1);
    return createExpression(stepDefinition.getPattern(), parameterInfo.getTypeResolver()::resolve, parameterInfo.isTransposed());
}
Also used : ParameterInfo(io.cucumber.core.backend.ParameterInfo)

Aggregations

ParameterInfo (io.cucumber.core.backend.ParameterInfo)3 ArrayList (java.util.ArrayList)2 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)1 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)1 Argument (io.cucumber.core.stepexpression.Argument)1 CucumberExpressionException (io.cucumber.cucumberexpressions.CucumberExpressionException)1 CucumberDataTableException (io.cucumber.datatable.CucumberDataTableException)1 UndefinedDataTableTypeException (io.cucumber.datatable.UndefinedDataTableTypeException)1 CucumberDocStringException (io.cucumber.docstring.CucumberDocStringException)1 Annotation (java.lang.annotation.Annotation)1 Type (java.lang.reflect.Type)1