use of io.cucumber.core.backend.ObjectFactory 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.ObjectFactory in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldBeStoppableWhenFacedWithMissingContextConfiguration.
@Test
void shouldBeStoppableWhenFacedWithMissingContextConfiguration() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(WithoutContextConfiguration.class);
IllegalStateException exception = assertThrows(IllegalStateException.class, factory::start);
assertThat(exception.getMessage(), containsString("Failed to load ApplicationContext"));
assertDoesNotThrow(factory::stop);
}
use of io.cucumber.core.backend.ObjectFactory 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.ObjectFactory in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldRespectCommonAnnotationsInStepDefs.
@Test
void shouldRespectCommonAnnotationsInStepDefs() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(WithSpringAnnotations.class);
factory.start();
WithSpringAnnotations stepdef = factory.getInstance(WithSpringAnnotations.class);
factory.stop();
assertThat(stepdef, is(notNullValue()));
assertTrue(stepdef.isAutowired());
}
use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldGlueScopedSpringBeanBehaveLikeGlueLifecycle.
@Test
void shouldGlueScopedSpringBeanBehaveLikeGlueLifecycle() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(WithSpringAnnotations.class);
// Scenario 1
factory.start();
long bellyInstance1 = factory.getInstance(Belly.class).getInstanceId();
long glueInstance1 = factory.getInstance(GlueScopedComponent.class).getInstanceId();
factory.stop();
// Scenario 2
factory.start();
long bellyInstance2 = factory.getInstance(Belly.class).getInstanceId();
long glueInstance2 = factory.getInstance(GlueScopedComponent.class).getInstanceId();
factory.stop();
assertAll(() -> assertThat(glueInstance1, is(not(glueInstance2))), () -> assertThat(glueInstance2, is(not(glueInstance1))), () -> assertThat(bellyInstance1, is(bellyInstance2)), () -> assertThat(bellyInstance2, is(bellyInstance1)));
}
Aggregations