Search in sources :

Example 6 with CucumberBackendException

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

the class MethodFormat method format.

String format(Method method) {
    String signature = method.toGenericString();
    Matcher matcher = METHOD_PATTERN.matcher(signature);
    if (matcher.find()) {
        String qc = matcher.group(3);
        String m = matcher.group(4);
        String qa = matcher.group(5);
        return format.format(new Object[] { qc, m, qa });
    } else {
        throw new CucumberBackendException("Cucumber bug: Couldn't format " + signature);
    }
}
Also used : Matcher(java.util.regex.Matcher) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException)

Example 7 with CucumberBackendException

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

the class StepDefinitionMatchTest method throws_could_not_invoke_step_when_execution_failed_with_null_arguments.

@Test
void throws_could_not_invoke_step_when_execution_failed_with_null_arguments() {
    Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have an null value\n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have an {word} value", new CucumberBackendException("This exception is expected!", new IllegalAccessException()), String.class);
    List<Argument> arguments = asList(() -> null);
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, URI.create("file:path/to.feature"), step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not invoke step [I have an {word} value] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with the step definition.\n" + "The converted arguments types were (null)")));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Step(io.cucumber.core.gherkin.Step) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 8 with CucumberBackendException

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

the class Java8LambdaStepDefinitionTest method should_fail_for_param_with_generic_list.

@Test
void should_fail_for_param_with_generic_list() {
    StepDefinitionBody.A1<List<String>> body = p1 -> {
    };
    Java8StepDefinition stepDefinition = Java8StepDefinition.create("some step", StepDefinitionBody.A1.class, body);
    Executable testMethod = () -> stepDefinition.parameterInfos().get(0).getTypeResolver().resolve();
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Can't use java.util.List in lambda step definition \"some step\". " + "Declare a DataTable or DocString argument instead and convert " + "manually with 'asList/asLists/asMap/asMaps' and 'convert' respectively")));
}
Also used : CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Test(org.junit.jupiter.api.Test) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Is.isA(org.hamcrest.core.Is.isA) List(java.util.List) Executable(org.junit.jupiter.api.function.Executable) Is.is(org.hamcrest.core.Is.is) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) List(java.util.List) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 9 with CucumberBackendException

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

the class Java8LambdaStepDefinitionTest method should_fail_for_param_with_non_generic_list.

@Test
void should_fail_for_param_with_non_generic_list() {
    StepDefinitionBody.A1<List> body = p1 -> {
    };
    Java8StepDefinition stepDefinition = Java8StepDefinition.create("some step", StepDefinitionBody.A1.class, body);
    Executable testMethod = () -> stepDefinition.parameterInfos().get(0).getTypeResolver().resolve();
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Can't use java.util.List in lambda step definition \"some step\". " + "Declare a DataTable or DocString argument instead and convert " + "manually with 'asList/asLists/asMap/asMaps' and 'convert' respectively")));
}
Also used : CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Test(org.junit.jupiter.api.Test) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Is.isA(org.hamcrest.core.Is.isA) List(java.util.List) Executable(org.junit.jupiter.api.function.Executable) Is.is(org.hamcrest.core.Is.is) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) List(java.util.List) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 10 with CucumberBackendException

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

the class OpenEJBObjectFactory method getInstance.

@Override
public <T> T getInstance(Class<T> type) {
    if (instances.containsKey(type)) {
        return type.cast(instances.get(type));
    }
    T object;
    try {
        object = type.newInstance();
        container.getContext().bind("inject", object);
    } catch (Exception e) {
        throw new CucumberBackendException("can't create " + type.getName(), e);
    }
    instances.put(type, object);
    return object;
}
Also used : CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) 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