Search in sources :

Example 11 with CucumberBackendException

use of io.cucumber.core.backend.CucumberBackendException 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 12 with CucumberBackendException

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

the class SpringFactoryTest method shouldFailIfClassWithAnnotationAnnotatedWithSpringComponentAnnotationsIsFound.

@Test
void shouldFailIfClassWithAnnotationAnnotatedWithSpringComponentAnnotationsIsFound() {
    final ObjectFactory factory = new SpringFactory();
    Executable testMethod = () -> factory.addClass(WithControllerAnnotation.class);
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat(actualThrown.getMessage(), is(equalTo("Glue class io.cucumber.spring.componentannotation.WithControllerAnnotation was annotated with @Controller; marking it as a candidate for auto-detection by Spring. Glue classes are detected and registered by Cucumber. Auto-detection of glue classes by spring may lead to duplicate bean definitions. Please remove the @Controller annotation")));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 13 with CucumberBackendException

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

the class TestContextAdaptor method stop.

public final void stop() {
    notifyTestContextManagerAboutAfterTestMethod();
    CucumberTestContext.getInstance().stop();
    try {
        delegate.afterTestClass();
    } catch (Exception e) {
        throw new CucumberBackendException(e.getMessage(), e);
    }
}
Also used : CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException)

Example 14 with CucumberBackendException

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

the class TestContextAdaptor method notifyTestContextManagerAboutBeforeTestMethod.

private void notifyTestContextManagerAboutBeforeTestMethod() {
    try {
        CucumberTestContext.getInstance().start();
        Class<?> testClass = delegate.getTestContext().getTestClass();
        Object testContextInstance = applicationContext.getBean(testClass);
        Method dummyMethod = TestContextAdaptor.class.getMethod("cucumberDoesNotHaveASingleTestMethod");
        delegate.beforeTestMethod(testContextInstance, dummyMethod);
    } catch (Exception e) {
        throw new CucumberBackendException(e.getMessage(), e);
    }
}
Also used : CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Method(java.lang.reflect.Method) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException)

Example 15 with CucumberBackendException

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

the class TestContextAdaptor method notifyTestContextManagerAboutAfterTestMethod.

private void notifyTestContextManagerAboutAfterTestMethod() {
    try {
        CucumberTestContext.getInstance().start();
        Class<?> testClass = delegate.getTestContext().getTestClass();
        Object testContextInstance = applicationContext.getBean(testClass);
        Method dummyMethod = TestContextAdaptor.class.getMethod("cucumberDoesNotHaveASingleTestMethod");
        delegate.afterTestMethod(testContextInstance, dummyMethod, null);
    } catch (Exception e) {
        throw new CucumberBackendException(e.getMessage(), e);
    }
}
Also used : CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Method(java.lang.reflect.Method) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException)

Aggregations

CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)17 Test (org.junit.jupiter.api.Test)9 Executable (org.junit.jupiter.api.function.Executable)9 Argument (io.cucumber.core.stepexpression.Argument)4 ObjectFactory (io.cucumber.core.backend.ObjectFactory)3 StepDefinition (io.cucumber.core.backend.StepDefinition)3 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)3 CucumberException (io.cucumber.core.exception.CucumberException)3 Feature (io.cucumber.core.gherkin.Feature)3 Step (io.cucumber.core.gherkin.Step)3 Method (java.lang.reflect.Method)2 List (java.util.List)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Is.is (org.hamcrest.core.Is.is)2 Is.isA (org.hamcrest.core.Is.isA)2 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)1 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 CucumberExpressionException (io.cucumber.cucumberexpressions.CucumberExpressionException)1