Search in sources :

Example 6 with CucumberInvocationTargetException

use of io.cucumber.core.backend.CucumberInvocationTargetException 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)

Aggregations

CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)6 Test (org.junit.jupiter.api.Test)5 StepDefinition (io.cucumber.core.backend.StepDefinition)4 Argument (io.cucumber.core.stepexpression.Argument)4 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)3 Feature (io.cucumber.core.gherkin.Feature)3 Step (io.cucumber.core.gherkin.Step)3 StepExpression (io.cucumber.core.stepexpression.StepExpression)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Executable (org.junit.jupiter.api.function.Executable)3 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)2 DataTableType (io.cucumber.datatable.DataTableType)2 Located (io.cucumber.core.backend.Located)1 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 EventBus (io.cucumber.core.eventbus.EventBus)1 CucumberException (io.cucumber.core.exception.CucumberException)1 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)1 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)1 StepExpressionFactory (io.cucumber.core.stepexpression.StepExpressionFactory)1 StepTypeRegistry (io.cucumber.core.stepexpression.StepTypeRegistry)1