Search in sources :

Example 21 with ObjectFactory

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

the class Issue1970 method issue1970.

@Test
public void issue1970() {
    ObjectFactory factory = new SpringFactory();
    // Add glue with Spring configuration
    factory.addClass(GlueClass.class);
    factory.start();
    GlueClass instance = factory.getInstance(GlueClass.class);
    String response = instance.service.get();
    factory.stop();
    factory.start();
    GlueClass instance2 = factory.getInstance(GlueClass.class);
    String response2 = instance2.service.get();
    factory.stop();
    assertNotEquals(response, response2);
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Example 22 with ObjectFactory

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

the class SpringFactoryTest method shouldRespectContextHierarchyInStepDefs.

@Test
void shouldRespectContextHierarchyInStepDefs() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithContextHierarchyAnnotation.class);
    factory.start();
    WithContextHierarchyAnnotation stepdef = factory.getInstance(WithContextHierarchyAnnotation.class);
    factory.stop();
    assertThat(stepdef, is(notNullValue()));
    assertTrue(stepdef.isAutowired());
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) WithContextHierarchyAnnotation(io.cucumber.spring.contexthierarchyconfig.WithContextHierarchyAnnotation) Test(org.junit.jupiter.api.Test)

Example 23 with ObjectFactory

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

the class SpringFactoryTest method shouldNeverCreateNewApplicationBeanInstances.

@Test
void shouldNeverCreateNewApplicationBeanInstances() {
    // Feature 1
    final ObjectFactory factory1 = new SpringFactory();
    factory1.addClass(BellyStepDefinitions.class);
    factory1.start();
    final BellyBean o1 = factory1.getInstance(BellyStepDefinitions.class).getBellyBean();
    factory1.stop();
    // Feature 2
    final ObjectFactory factory2 = new SpringFactory();
    factory2.addClass(BellyStepDefinitions.class);
    factory2.start();
    final BellyBean o2 = factory2.getInstance(BellyStepDefinitions.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 : DirtiesContextBellyStepDefinitions(io.cucumber.spring.dirtiescontextconfig.DirtiesContextBellyStepDefinitions) BellyStepDefinitions(io.cucumber.spring.contextconfig.BellyStepDefinitions) ObjectFactory(io.cucumber.core.backend.ObjectFactory) BellyBean(io.cucumber.spring.beans.BellyBean) Test(org.junit.jupiter.api.Test)

Example 24 with ObjectFactory

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

the class SpringFactoryTest method shouldFindStepDefsCreatedImplicitlyForAutowiring.

@Test
void shouldFindStepDefsCreatedImplicitlyForAutowiring() {
    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 ThirdStepDef o2 = factory1.getInstance(ThirdStepDef.class);
    factory1.stop();
    assertAll(() -> assertThat(o1.getThirdStepDef(), is(notNullValue())), () -> assertThat(o2, is(notNullValue())), () -> assertThat(o1.getThirdStepDef(), is(equalTo(o2))), () -> assertThat(o2, is(equalTo(o1.getThirdStepDef()))));
}
Also used : OneStepDef(io.cucumber.spring.commonglue.OneStepDef) ObjectFactory(io.cucumber.core.backend.ObjectFactory) ThirdStepDef(io.cucumber.spring.commonglue.ThirdStepDef) AutowiresThirdStepDef(io.cucumber.spring.commonglue.AutowiresThirdStepDef) Test(org.junit.jupiter.api.Test)

Example 25 with ObjectFactory

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

the class SpringFactoryTest method shouldRespectDirtiesContextAnnotationsInStepDefs.

@Test
void shouldRespectDirtiesContextAnnotationsInStepDefs() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(DirtiesContextBellyStepDefinitions.class);
    // Scenario 1
    factory.start();
    final BellyBean o1 = factory.getInstance(DirtiesContextBellyStepDefinitions.class).getBellyBean();
    factory.stop();
    // Scenario 2
    factory.start();
    final BellyBean o2 = factory.getInstance(DirtiesContextBellyStepDefinitions.class).getBellyBean();
    factory.stop();
    assertAll(() -> assertThat(o1, is(notNullValue())), () -> assertThat(o2, is(notNullValue())), () -> assertThat(o1, is(not(equalTo(o2)))), () -> assertThat(o2, is(not(equalTo(o1)))));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) BellyBean(io.cucumber.spring.beans.BellyBean) DirtiesContextBellyStepDefinitions(io.cucumber.spring.dirtiescontextconfig.DirtiesContextBellyStepDefinitions) 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