use of io.cucumber.core.exception.CucumberException 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")));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method throws_for_unknown_parameter_types.
@Test
void throws_for_unknown_parameter_types() {
StepDefinition stepDefinition = new StubStepDefinition("Given a {unknownParameterType}");
List<Envelope> events = new ArrayList<>();
bus.registerHandlerFor(Envelope.class, events::add);
CucumberException exception = assertThrows(CucumberException.class, () -> stepExpressionFactory.createExpression(stepDefinition));
assertThat(exception.getMessage(), is("" + "Could not create a cucumber expression for 'Given a {unknownParameterType}'.\n" + "It appears you did not register a parameter type."));
assertThat(events, iterableWithSize(1));
assertNotNull(events.get(0).getUndefinedParameterType());
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class PluginFactoryTest method fails_to_instantiate_plugin_that_wants_a_file_without_file_arg.
@Test
void fails_to_instantiate_plugin_that_wants_a_file_without_file_arg() {
PluginOption option = parse(WantsFile.class.getName());
Executable testMethod = () -> fc.create(option);
CucumberException exception = assertThrows(CucumberException.class, testMethod);
assertThat(exception.getMessage(), is(equalTo("You must supply an output argument to io.cucumber.core.plugin.PluginFactoryTest$WantsFile. Like so: io.cucumber.core.plugin.PluginFactoryTest$WantsFile:DIR|FILE|URL")));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class ResourceScannerTest method scanForResourcesNestedJarUri.
@Test
void scanForResourcesNestedJarUri() {
URI jarFileUri = new File("src/test/resources/io/cucumber/core/resource/test/spring-resource.jar").toURI();
URI resourceUri = URI.create("jar:file://" + jarFileUri.getSchemeSpecificPart() + "!/BOOT-INF/lib/jar-resource.jar!/com/example/package-jar-resource.txt");
CucumberException exception = assertThrows(CucumberException.class, () -> resourceScanner.scanForResourcesUri(resourceUri));
assertThat(exception.getMessage(), containsString("Cucumber currently doesn't support classpath scanning in nested jars."));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class PluginFactoryTest method fails_to_instantiate_plugin_that_declares_two_single_arg_constructors_when_argument_specified.
@Test
void fails_to_instantiate_plugin_that_declares_two_single_arg_constructors_when_argument_specified() {
PluginOption option = parse(WantsFileOrURL.class.getName() + ":some_arg");
Executable testMethod = () -> fc.create(option);
CucumberException exception = assertThrows(CucumberException.class, testMethod);
assertThat(exception.getMessage(), is(equalTo("class io.cucumber.core.plugin.PluginFactoryTest$WantsFileOrURL must have exactly one constructor that declares a single parameter of one of: [class java.lang.String, class java.io.File, class java.net.URI, class java.net.URL, class java.io.OutputStream, interface java.lang.Appendable]")));
}
Aggregations