Search in sources :

Example 16 with ObjectFactory

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

the class BackendServiceLoader method loadBackends.

private Collection<? extends Backend> loadBackends(Iterable<BackendProviderService> serviceLoader) {
    List<Backend> backends = new ArrayList<>();
    for (BackendProviderService backendProviderService : serviceLoader) {
        ObjectFactory objectFactory = objectFactorySupplier.get();
        backends.add(backendProviderService.create(objectFactory, objectFactory, classLoaderSupplier));
    }
    return backends;
}
Also used : Backend(io.cucumber.core.backend.Backend) ObjectFactory(io.cucumber.core.backend.ObjectFactory) ArrayList(java.util.ArrayList) BackendProviderService(io.cucumber.core.backend.BackendProviderService)

Example 17 with ObjectFactory

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

the class HookTest method after_hooks_execute_before_objects_are_disposed.

/**
 * Test for
 * <a href="https://github.com/cucumber/cucumber-jvm/issues/23">#23</a>.
 */
@Test
void after_hooks_execute_before_objects_are_disposed() {
    Backend backend = mock(Backend.class);
    when(backend.getSnippet()).thenReturn(new TestSnippet());
    ObjectFactory objectFactory = mock(ObjectFactory.class);
    final HookDefinition hook = mock(HookDefinition.class);
    when(hook.getLocation()).thenReturn("hook-location");
    when(hook.getTagExpression()).thenReturn("");
    doAnswer(invocation -> {
        Glue glue = invocation.getArgument(0);
        glue.addBeforeHook(hook);
        return null;
    }).when(backend).loadGlue(any(Glue.class), ArgumentMatchers.anyList());
    Runner runner = new Runner(bus, Collections.singleton(backend), objectFactory, runtimeOptions);
    runner.runPickle(pickle);
    InOrder inOrder = inOrder(hook, backend);
    inOrder.verify(backend).buildWorld();
    inOrder.verify(hook).execute(ArgumentMatchers.any());
    inOrder.verify(backend).disposeWorld();
}
Also used : Backend(io.cucumber.core.backend.Backend) InOrder(org.mockito.InOrder) ObjectFactory(io.cucumber.core.backend.ObjectFactory) Glue(io.cucumber.core.backend.Glue) TestSnippet(io.cucumber.core.snippets.TestSnippet) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 18 with ObjectFactory

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

the class PicoFactoryTest method shouldDisposeOnStop.

@Test
void shouldDisposeOnStop() {
    // Given
    ObjectFactory factory = new PicoFactory();
    factory.addClass(StepDefinitions.class);
    // When
    factory.start();
    StepDefinitions steps = factory.getInstance(StepDefinitions.class);
    // Then
    assertFalse(steps.getBelly().isDisposed());
    // When
    factory.stop();
    // Then
    assertTrue(steps.getBelly().isDisposed());
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Example 19 with ObjectFactory

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

the class PicoFactoryTest method shouldGiveUsNewInstancesForEachScenario.

@Test
void shouldGiveUsNewInstancesForEachScenario() {
    ObjectFactory factory = new PicoFactory();
    factory.addClass(StepDefinitions.class);
    // Scenario 1
    factory.start();
    StepDefinitions o1 = factory.getInstance(StepDefinitions.class);
    factory.stop();
    // Scenario 2
    factory.start();
    StepDefinitions o2 = factory.getInstance(StepDefinitions.class);
    factory.stop();
    assertAll(() -> 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 20 with ObjectFactory

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

the class PicoFactoryTest method public_non_static_inner_classes_are_not_instantiable.

@Test
void public_non_static_inner_classes_are_not_instantiable() {
    ObjectFactory factory = new PicoFactory();
    factory.addClass(NonStaticInnerClass.class);
    factory.start();
    assertThat(factory.getInstance(NonStaticInnerClass.class), nullValue());
}
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