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;
}
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();
}
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());
}
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)))));
}
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());
}
Aggregations