use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table.
@Test
void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table() {
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");
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 0 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")));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch.
@Test
void throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch() {
stepTypeRegistry.defineParameterType(new ParameterType<>("itemQuantity", "(few|some|lots of) (cukes|gherkins)", ItemQuantity.class, // Wrong number of capture groups
(String s) -> null));
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);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have {itemQuantity} in my belly] defined at '{stubbed location with details}'.")));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class CamelCaseConverterTest method should_throw_on_duplicate_headers.
@Test
void should_throw_on_duplicate_headers() {
Map<String, String> table = new HashMap<>();
table.put("Title Case Header", "value1");
table.put("TitleCaseHeader", "value2");
CucumberException exception = assertThrows(CucumberException.class, () -> camelCaseConverter.toCamelCase(table));
assertThat(exception.getMessage(), is("" + "Failed to convert header 'Title Case Header' to property name. " + "'TitleCaseHeader' also converted to 'titleCaseHeader'"));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class BackendServiceLoaderTest method should_throw_an_exception_when_no_backend_could_be_found.
@Test
void should_throw_an_exception_when_no_backend_could_be_found() {
BackendServiceLoader backendSupplier = new BackendServiceLoader(classLoaderSupplier, objectFactory);
Executable testMethod = () -> backendSupplier.get(emptyList()).iterator().next();
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("No backends were found. Please make sure you have a backend module on your CLASSPATH.")));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class ObjectFactoryServiceLoaderTest method shouldThrowIfDefaultObjectFactoryServiceCouldNotBeLoaded.
@Test
void shouldThrowIfDefaultObjectFactoryServiceCouldNotBeLoaded() {
Options options = () -> null;
Supplier<ClassLoader> classLoader = () -> new FilteredClassLoader("META-INF/services/io.cucumber.core.backend.ObjectFactory");
ObjectFactoryServiceLoader loader = new ObjectFactoryServiceLoader(classLoader, options);
CucumberException exception = assertThrows(CucumberException.class, loader::loadObjectFactory);
assertThat(exception.getMessage(), is("" + "Could not find any object factory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "This typically happens when using shaded jars. Make sure\n" + "to merge all SPI definitions in META-INF/services correctly"));
}
Aggregations