Search in sources :

Example 91 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method rethrows_target_invocation_exceptions_from_parameter_type.

@Test
void rethrows_target_invocation_exceptions_from_parameter_type() {
    RuntimeException userException = new RuntimeException();
    stepTypeRegistry.defineParameterType(new ParameterType<>("itemQuantity", "(few|some|lots of) (cukes|gherkins)", ItemQuantity.class, (String[] s) -> {
        throw new CucumberInvocationTargetException(stubbedLocation, new InvocationTargetException(userException));
    }));
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some cukes in my belly\n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have {itemQuantity} 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 : 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) 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)

Example 92 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method transforms_to_map_of_double_to_double.

@Test
void transforms_to_map_of_double_to_double() throws Throwable {
    Method m = Steps.class.getMethod("mapOfDoubleToDouble", Map.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | 100.5 | 99.5 | \n" + "      | 0.5   | -0.5 | \n" + "      | 1000  | 999  | \n");
    Map<Double, Double> stepDefs = runStepDef(m, false, feature);
    assertAll(() -> assertThat(stepDefs, hasEntry(1000.0, 999.0)), () -> assertThat(stepDefs, hasEntry(0.5, -0.5)), () -> assertThat(stepDefs, hasEntry(100.5, 99.5)));
}
Also used : Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 93 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method transforms_to_list_of_single_values_transposed.

@Test
void transforms_to_list_of_single_values_transposed() throws Throwable {
    Method m = Steps.class.getMethod("listOfListOfDoubles", List.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | 100.5 | 0.5   | 1000| \n" + "      | 99.5   | -0.5 | 999 | \n");
    List<List<Double>> stepDefs = runStepDef(m, true, feature);
    assertThat(stepDefs.toString(), is(equalTo("[[100.5, 99.5], [0.5, -0.5], [1000.0, 999.0]]")));
}
Also used : ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 94 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method passes_transposed_data_table.

@Test
void passes_transposed_data_table() throws Throwable {
    Method m = Steps.class.getMethod("plainDataTable", DataTable.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | Birth Date | \n" + "      | 1957-05-10 | \n");
    DataTable stepDefs = runStepDef(m, true, feature);
    assertAll(() -> assertThat(stepDefs.cell(0, 0), is(equalTo("Birth Date"))), () -> assertThat(stepDefs.cell(0, 1), is(equalTo("1957-05-10"))));
}
Also used : DataTable(io.cucumber.datatable.DataTable) Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 95 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method transforms_transposed_to_map_of_double_to_double.

@Test
void transforms_transposed_to_map_of_double_to_double() throws Throwable {
    Method m = Steps.class.getMethod("transposedMapOfDoubleToListOfDouble", Map.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | 100.5 | 99.5 | \n" + "      | 0.5   | -0.5 | \n" + "      | 1000  | 999  | \n");
    Map<Double, List<Double>> stepDefs = runStepDef(m, true, feature);
    assertThat(stepDefs, hasEntry(100.5, asList(0.5, 1000.0)));
}
Also used : ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

Feature (io.cucumber.core.gherkin.Feature)152 Test (org.junit.jupiter.api.Test)144 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)92 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)78 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)77 UUID (java.util.UUID)67 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)59 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)26 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)23 Step (io.cucumber.core.gherkin.Step)22 StepDefinition (io.cucumber.core.backend.StepDefinition)21 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)21 Argument (io.cucumber.core.stepexpression.Argument)18 StepExpression (io.cucumber.core.stepexpression.StepExpression)18 DocString (io.cucumber.docstring.DocString)17 Executable (org.junit.jupiter.api.function.Executable)16 URI (java.net.URI)15 Arrays.asList (java.util.Arrays.asList)14 Collections.singletonList (java.util.Collections.singletonList)13