Search in sources :

Example 11 with ObjectFactory

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

the class SpringFactoryTest method shouldRespectCustomPropertyPlaceholderConfigurer.

@Test
void shouldRespectCustomPropertyPlaceholderConfigurer() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithSpringAnnotations.class);
    factory.start();
    WithSpringAnnotations stepdef = factory.getInstance(WithSpringAnnotations.class);
    factory.stop();
    assertThat(stepdef.getProperty(), is(equalTo("property value")));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Example 12 with ObjectFactory

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

the class SpringFactoryTest method shouldBeStoppableWhenFacedWithInvalidConfiguration.

@Test
void shouldBeStoppableWhenFacedWithInvalidConfiguration() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithEmptySpringAnnotations.class);
    IllegalStateException exception = assertThrows(IllegalStateException.class, factory::start);
    assertThat(exception.getMessage(), containsString("DelegatingSmartContextLoader was unable to detect defaults"));
    assertDoesNotThrow(factory::stop);
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Example 13 with ObjectFactory

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

the class SpringFactoryTest method shouldRespectDirtiesContextAnnotationsInStepDefsUsingMetaConfiguration.

@Test
void shouldRespectDirtiesContextAnnotationsInStepDefsUsingMetaConfiguration() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(DirtiesContextBellyMetaStepDefinitions.class);
    // Scenario 1
    factory.start();
    final BellyBean o1 = factory.getInstance(DirtiesContextBellyMetaStepDefinitions.class).getBellyBean();
    factory.stop();
    // Scenario 2
    factory.start();
    final BellyBean o2 = factory.getInstance(DirtiesContextBellyMetaStepDefinitions.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) DirtiesContextBellyMetaStepDefinitions(io.cucumber.spring.metaconfig.dirties.DirtiesContextBellyMetaStepDefinitions) Test(org.junit.jupiter.api.Test)

Example 14 with ObjectFactory

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

the class OpenEJBObjectFactoryTest method shouldGiveUsNewInstancesForEachScenario.

@Test
void shouldGiveUsNewInstancesForEachScenario() {
    ObjectFactory factory = new OpenEJBObjectFactory();
    factory.addClass(BellyStepDefinitions.class);
    // Scenario 1
    factory.start();
    BellyStepDefinitions o1 = factory.getInstance(BellyStepDefinitions.class);
    factory.stop();
    // Scenario 2
    factory.start();
    BellyStepDefinitions o2 = factory.getInstance(BellyStepDefinitions.class);
    factory.stop();
    assertThat(o1, is(notNullValue()));
    assertThat(o1, is(not(equalTo(o2))));
    assertThat(o2, is(not(equalTo(o1))));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Example 15 with ObjectFactory

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

the class ObjectFactoryServiceLoader method loadSingleObjectFactoryOrDefault.

private static ObjectFactory loadSingleObjectFactoryOrDefault(ServiceLoader<ObjectFactory> loader) {
    Iterator<ObjectFactory> objectFactories = loader.iterator();
    // Find the first non-default object factory,
    // or the default as a side effect.
    ObjectFactory objectFactory = null;
    while (objectFactories.hasNext()) {
        objectFactory = objectFactories.next();
        if (!(objectFactory instanceof DefaultObjectFactory)) {
            break;
        }
    }
    if (objectFactory == null) {
        throw new CucumberException("" + "Could not find any object factory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "This typically happens when using shaded jars. Make sure\n" + "to merge all SPI definitions in META-INF/services correctly");
    }
    // Check if there are no other non-default object factories
    while (objectFactories.hasNext()) {
        ObjectFactory extraObjectFactory = objectFactories.next();
        if (extraObjectFactory instanceof DefaultObjectFactory) {
            continue;
        }
        throw new CucumberException(getMultipleObjectFactoryLogMessage(objectFactory, extraObjectFactory));
    }
    return objectFactory;
}
Also used : DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) ObjectFactory(io.cucumber.core.backend.ObjectFactory) DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) CucumberException(io.cucumber.core.exception.CucumberException)

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