Search in sources :

Example 26 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldNeverCreateNewApplicationBeanInstancesUsingMetaConfiguration.

@Test
void shouldNeverCreateNewApplicationBeanInstancesUsingMetaConfiguration() {
    // Feature 1
    final ObjectFactory factory1 = new SpringFactory();
    factory1.addClass(BellyMetaStepDefinitions.class);
    factory1.start();
    final BellyBean o1 = factory1.getInstance(BellyMetaStepDefinitions.class).getBellyBean();
    factory1.stop();
    // Feature 2
    final ObjectFactory factory2 = new SpringFactory();
    factory2.addClass(BellyMetaStepDefinitions.class);
    factory2.start();
    final BellyBean o2 = factory2.getInstance(BellyMetaStepDefinitions.class).getBellyBean();
    factory2.stop();
    assertAll(() -> assertThat(o1, is(notNullValue())), () -> assertThat(o2, is(notNullValue())), () -> assertThat(o1, is(equalTo(o1))), () -> assertThat(o2, is(equalTo(o2))));
}
Also used : BellyMetaStepDefinitions(io.cucumber.spring.metaconfig.general.BellyMetaStepDefinitions) DirtiesContextBellyMetaStepDefinitions(io.cucumber.spring.metaconfig.dirties.DirtiesContextBellyMetaStepDefinitions) ObjectFactory(io.cucumber.core.backend.ObjectFactory) BellyBean(io.cucumber.spring.beans.BellyBean) Test(org.junit.jupiter.api.Test)

Example 27 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldFailIfClassWithAnnotationAnnotatedWithSpringComponentAnnotationsIsFound.

@Test
void shouldFailIfClassWithAnnotationAnnotatedWithSpringComponentAnnotationsIsFound() {
    final ObjectFactory factory = new SpringFactory();
    Executable testMethod = () -> factory.addClass(WithControllerAnnotation.class);
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat(actualThrown.getMessage(), is(equalTo("Glue class io.cucumber.spring.componentannotation.WithControllerAnnotation was annotated with @Controller; 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 @Controller annotation")));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 28 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldReuseStepDefsCreatedImplicitlyForAutowiring.

@Test
void shouldReuseStepDefsCreatedImplicitlyForAutowiring() {
    final ObjectFactory factory1 = new SpringFactory();
    factory1.addClass(WithSpringAnnotations.class);
    factory1.addClass(OneStepDef.class);
    factory1.addClass(ThirdStepDef.class);
    factory1.addClass(AutowiresThirdStepDef.class);
    factory1.start();
    final OneStepDef o1 = factory1.getInstance(OneStepDef.class);
    final AutowiresThirdStepDef o3 = factory1.getInstance(AutowiresThirdStepDef.class);
    factory1.stop();
    assertAll(() -> assertThat(o1.getThirdStepDef(), is(notNullValue())), () -> assertThat(o3.getThirdStepDef(), is(notNullValue())), () -> assertThat(o1.getThirdStepDef(), is(equalTo(o3.getThirdStepDef()))), () -> assertThat(o3.getThirdStepDef(), is(equalTo(o1.getThirdStepDef()))));
}
Also used : OneStepDef(io.cucumber.spring.commonglue.OneStepDef) ObjectFactory(io.cucumber.core.backend.ObjectFactory) AutowiresThirdStepDef(io.cucumber.spring.commonglue.AutowiresThirdStepDef) Test(org.junit.jupiter.api.Test)

Example 29 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class GuiceFactoryTest method factoryCanBeInstantiatedWithDefaultConstructor.

@Test
void factoryCanBeInstantiatedWithDefaultConstructor() {
    ObjectFactory factory = new GuiceFactory();
    assertThat(factory, notNullValue());
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectFactory (io.cucumber.core.backend.ObjectFactory)29 Test (org.junit.jupiter.api.Test)27 Backend (io.cucumber.core.backend.Backend)5 TestSnippet (io.cucumber.core.snippets.TestSnippet)4 BellyBean (io.cucumber.spring.beans.BellyBean)4 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)3 Glue (io.cucumber.core.backend.Glue)3 HookDefinition (io.cucumber.core.backend.HookDefinition)3 DirtiesContextBellyStepDefinitions (io.cucumber.spring.dirtiescontextconfig.DirtiesContextBellyStepDefinitions)3 Executable (org.junit.jupiter.api.function.Executable)3 Belly (io.cucumber.spring.beans.Belly)2 GlueScopedComponent (io.cucumber.spring.beans.GlueScopedComponent)2 AutowiresThirdStepDef (io.cucumber.spring.commonglue.AutowiresThirdStepDef)2 OneStepDef (io.cucumber.spring.commonglue.OneStepDef)2 BellyStepDefinitions (io.cucumber.spring.contextconfig.BellyStepDefinitions)2 DirtiesContextBellyMetaStepDefinitions (io.cucumber.spring.metaconfig.dirties.DirtiesContextBellyMetaStepDefinitions)2 InOrder (org.mockito.InOrder)2 BackendProviderService (io.cucumber.core.backend.BackendProviderService)1 DefaultObjectFactory (io.cucumber.core.backend.DefaultObjectFactory)1 StaticHookDefinition (io.cucumber.core.backend.StaticHookDefinition)1