Search in sources :

Example 6 with Argument

use of io.cucumber.core.stepexpression.Argument in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments.

@Test
void throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n" + "       | A | B | \n" + "       | C | D | \n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have {int} cukes in my belly", Integer.TYPE, Short.TYPE, List.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(step);
    PickleStepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Step [I have {int} cukes in my belly] is defined with 3 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 2 arguments:\n" + " * 4\n" + " * Table:\n" + "      | A | B |\n" + "      | C | D |\n" + "\n" + "Step text: I have 4 cukes in my belly")));
}
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) 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) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 7 with Argument

use of io.cucumber.core.stepexpression.Argument in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method should_apply_identity_transform_to_data_table_when_target_type_is_object.

@Test
void should_apply_identity_transform_to_data_table_when_target_type_is_object() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some step\n" + "      | content |\n");
    StepDefinition stepDefinition = new StubStepDefinition("I have some step", Object.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(feature.getPickles().get(0).getSteps().get(0));
    assertThat(arguments.get(0).getValue(), is(equalTo(DataTable.create(singletonList(singletonList("content"))))));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StepDefinition(io.cucumber.core.backend.StepDefinition) Feature(io.cucumber.core.gherkin.Feature) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 8 with Argument

use of io.cucumber.core.stepexpression.Argument in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method should_convert_empty_pickle_table_cells_to_null_values.

@Test
void should_convert_empty_pickle_table_cells_to_null_values() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some step\n" + "       |  |\n");
    StepDefinition stepDefinition = new StubStepDefinition("I have some step", Object.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(feature.getPickles().get(0).getSteps().get(0));
    assertEquals(DataTable.create(singletonList(singletonList(null))), arguments.get(0).getValue());
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StepDefinition(io.cucumber.core.backend.StepDefinition) Feature(io.cucumber.core.gherkin.Feature) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 9 with Argument

use of io.cucumber.core.stepexpression.Argument 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 10 with Argument

use of io.cucumber.core.stepexpression.Argument in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method rethrows_target_invocation_exception_for_docstring.

@Test
void rethrows_target_invocation_exception_for_docstring() {
    RuntimeException userException = new RuntimeException();
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some cukes in my belly\n" + "       \"\"\"doc\n" + "        converting this should throw an exception\n" + "       \"\"\"\n");
    stepTypeRegistry.defineDocStringType(new DocStringType(ItemQuantity.class, "doc", content -> {
        throw new CucumberInvocationTargetException(stubbedLocation, new InvocationTargetException(userException));
    }));
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have some cukes in my belly", ItemQuantity.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(step);
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    RuntimeException actualThrown = assertThrows(RuntimeException.class, testMethod);
    assertThat(actualThrown, sameInstance(userException));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Step(io.cucumber.core.gherkin.Step) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) DataTableType(io.cucumber.datatable.DataTableType) Located(io.cucumber.core.backend.Located) StepDefinition(io.cucumber.core.backend.StepDefinition) StepExpression(io.cucumber.core.stepexpression.StepExpression) Arrays.asList(java.util.Arrays.asList) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENGLISH(java.util.Locale.ENGLISH) EventBus(io.cucumber.core.eventbus.EventBus) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) InvocationTargetException(java.lang.reflect.InvocationTargetException) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Test(org.junit.jupiter.api.Test) List(java.util.List) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Argument(io.cucumber.core.stepexpression.Argument) DocStringType(io.cucumber.docstring.DocStringType) Clock(java.time.Clock) Collections(java.util.Collections) CucumberException(io.cucumber.core.exception.CucumberException) ParameterType(io.cucumber.cucumberexpressions.ParameterType) Argument(io.cucumber.core.stepexpression.Argument) Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DocStringType(io.cucumber.docstring.DocStringType) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Executable(org.junit.jupiter.api.function.Executable) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Aggregations

Argument (io.cucumber.core.stepexpression.Argument)20 StepDefinition (io.cucumber.core.backend.StepDefinition)18 Feature (io.cucumber.core.gherkin.Feature)18 Test (org.junit.jupiter.api.Test)18 Step (io.cucumber.core.gherkin.Step)17 StepExpression (io.cucumber.core.stepexpression.StepExpression)16 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)15 Executable (org.junit.jupiter.api.function.Executable)14 CucumberException (io.cucumber.core.exception.CucumberException)12 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)6 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)5 DataTableType (io.cucumber.datatable.DataTableType)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Located (io.cucumber.core.backend.Located)2 EventBus (io.cucumber.core.eventbus.EventBus)2 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)2 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)2 StepExpressionFactory (io.cucumber.core.stepexpression.StepExpressionFactory)2 StepTypeRegistry (io.cucumber.core.stepexpression.StepTypeRegistry)2 ParameterType (io.cucumber.cucumberexpressions.ParameterType)2