use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_invoke_argument_conversion_when_argument_could_not_be_got.
@Test
void throws_could_not_invoke_argument_conversion_when_argument_could_not_be_got() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have a data table\n" + " | A | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have a data table", UndefinedDataTableType.class);
List<Argument> arguments = Collections.singletonList(() -> {
throw new CucumberBackendException("This exception is expected", new IllegalAccessException());
});
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 convert arguments for step [I have a data table] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with a hook or transformer definition.")));
}
use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_invoke_step_when_execution_failed_due_to_bad_methods.
@Test
void throws_could_not_invoke_step_when_execution_failed_due_to_bad_methods() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have a data table\n" + " | A | \n" + " | B | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have a data table", new CucumberBackendException("This exception is expected!", new IllegalAccessException()), String.class, String.class);
List<Argument> arguments = asList(() -> "mocked table cell", () -> "mocked table cell");
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 a data table] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with the step definition.\n" + "The converted arguments types were (java.lang.String, java.lang.String)")));
}
use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldFailIfClassWithSpringComponentAnnotationsIsFound.
@Test
void shouldFailIfClassWithSpringComponentAnnotationsIsFound() {
final ObjectFactory factory = new SpringFactory();
Executable testMethod = () -> factory.addClass(WithComponentAnnotation.class);
CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
assertThat(actualThrown.getMessage(), is(equalTo("Glue class io.cucumber.spring.componentannotation.WithComponentAnnotation was annotated with @Component; marking it as a candidate for auto-detection by Spring. Glue classes are detected and registered by Cucumber. Auto-detection of glue classes by spring may lead to duplicate bean definitions. Please remove the @Component annotation")));
}
use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldFailIfMultipleClassesWithSpringAnnotationsAreFound.
@Test
void shouldFailIfMultipleClassesWithSpringAnnotationsAreFound() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(WithSpringAnnotations.class);
Executable testMethod = () -> factory.addClass(BellyStepDefinitions.class);
CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
assertThat(actualThrown.getMessage(), startsWith("Glue class class io.cucumber.spring.contextconfig.BellyStepDefinitions and class io.cucumber.spring.SpringFactoryTest$WithSpringAnnotations are both annotated with @CucumberContextConfiguration.\n" + "Please ensure only one class configures the spring context"));
}
use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.
the class SpringFactory method start.
@Override
public void start() {
if (withCucumberContextConfiguration == null) {
throw new CucumberBackendException("" + "Please annotate a glue class with some context configuration.\n" + "\n" + "For example:\n" + "\n" + " @CucumberContextConfiguration\n" + " @SpringBootTest(classes = TestConfig.class)\n" + " public class CucumberSpringConfiguration { }" + "\n" + "Or: \n" + "\n" + " @CucumberContextConfiguration\n" + " @ContextConfiguration( ... )\n" + " public class CucumberSpringConfiguration { }");
}
// The application context created by the TestContextManager is
// a singleton and reused between scenarios and shared between
// threads.
TestContextManager testContextManager = new TestContextManager(withCucumberContextConfiguration);
testContextAdaptor = createTestContextManagerAdaptor(testContextManager, stepClasses);
testContextAdaptor.start();
}
Aggregations