use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class ObjectFactoryServiceLoaderTest method shouldThrowIfSelectedObjectFactoryServiceCouldNotBeLoaded.
@Test
void shouldThrowIfSelectedObjectFactoryServiceCouldNotBeLoaded() {
Options options = () -> NoSuchObjectFactory.class;
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 object factory io.cucumber.core.runtime.ObjectFactoryServiceLoaderTest$NoSuchObjectFactory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "Has the class been registered with SPI and is it available on\n" + "the classpath?"));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class JUnitReporterWithStepNotificationsTest method test_step_undefined_fires_test_failure_and_test_finished_for_undefined_step.
@Test
void test_step_undefined_fires_test_failure_and_test_finished_for_undefined_step() {
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
Suggestion suggestion = new Suggestion("step name", singletonList("some snippet"));
bus.send(new SnippetsSuggestedEvent(now(), featureUri, scenarioLine, scenarioLine, suggestion));
bus.send(new TestCaseStarted(now(), testCase));
bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
Throwable exception = new CucumberException("No step definitions found");
Result result = new Result(Status.UNDEFINED, ZERO, exception);
bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
Failure stepFailure = failureArgumentCaptor.getValue();
assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
assertThat(stepFailure.getException(), is(equalTo(exception)));
bus.send(new TestCaseFinished(now(), testCase, result));
verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
Failure pickleFailure = failureArgumentCaptor.getValue();
assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
assertThat(pickleFailure.getException().getMessage(), is("" + "The step 'step name' is undefined.\n" + "You can implement this step using the snippet(s) below:\n" + "\n" + "some snippet\n"));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class CucumberPropertiesParser method parseAll.
private <T> void parseAll(CucumberPropertiesProvider properties, String propertyName, Function<String, Collection<T>> parser, Consumer<T> setter) {
String property = properties.get(propertyName);
if (property == null || property.isEmpty()) {
return;
}
try {
Collection<T> parsed = parser.apply(property);
parsed.forEach(setter);
} catch (Exception e) {
throw new CucumberException("Failed to parse '" + propertyName + "' with value '" + property + "'", e);
}
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class PrettyFormatter method printStep.
private void printStep(TestStepFinished event) {
if (event.getTestStep() instanceof PickleStepTestStep) {
PickleStepTestStep testStep = (PickleStepTestStep) event.getTestStep();
String keyword = testStep.getStep().getKeyword();
String stepText = testStep.getStep().getText();
String status = event.getResult().getStatus().name().toLowerCase(ROOT);
String formattedStepText = formatStepText(keyword, stepText, formats.get(status), formats.get(status + "_arg"), testStep.getDefinitionArgument());
String locationComment = formatLocationComment(event, testStep, keyword, stepText);
out.println(STEP_INDENT + formattedStepText + locationComment);
StepArgument stepArgument = testStep.getStep().getArgument();
if (DataTableArgument.class.isInstance(stepArgument)) {
DataTableFormatter tableFormatter = DataTableFormatter.builder().prefixRow(STEP_SCENARIO_INDENT).escapeDelimiters(false).build();
DataTableArgument dataTableArgument = (DataTableArgument) stepArgument;
try {
tableFormatter.formatTo(DataTable.create(dataTableArgument.cells()), out);
} catch (IOException e) {
throw new CucumberException(e);
}
}
}
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class DefaultObjectFactoryTest method shouldThrowForNonZeroArgPublicConstructors.
@Test
void shouldThrowForNonZeroArgPublicConstructors() {
CucumberException exception = assertThrows(CucumberException.class, () -> factory.getInstance(NoAccessibleConstructor.class));
assertThat(exception.getMessage(), is("" + "class io.cucumber.core.backend.DefaultObjectFactoryTest$NoAccessibleConstructor does not have a public zero-argument constructor.\n" + "\n" + "To use dependency injection add an other ObjectFactory implementation such as:\n" + " * cucumber-picocontainer\n" + " * cucumber-spring\n" + " * cucumber-jakarta-cdi\n" + " * ...etc\n"));
}
Aggregations