use of io.cucumber.core.backend.Backend in project cucumber-jvm by cucumber.
the class HookTest method hook_throws_exception_with_name_when_tag_expression_is_invalid.
@Test
void hook_throws_exception_with_name_when_tag_expression_is_invalid() {
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());
RuntimeException e = assertThrows(RuntimeException.class, () -> new Runner(bus, Collections.singleton(backend), objectFactory, runtimeOptions));
assertThat(e.getMessage(), is("Invalid tag expression at 'hook-location'"));
}
use of io.cucumber.core.backend.Backend in project cucumber-jvm by cucumber.
the class RunnerTest method hooks_execute_inside_world_and_around_world.
@Test
void hooks_execute_inside_world_and_around_world() {
StaticHookDefinition beforeAllHook = createStaticHook();
StaticHookDefinition afterAllHook = createStaticHook();
HookDefinition beforeHook = createHook();
HookDefinition afterHook = createHook();
Backend backend = mock(Backend.class);
when(backend.getSnippet()).thenReturn(new TestSnippet());
ObjectFactory objectFactory = mock(ObjectFactory.class);
doAnswer(invocation -> {
Glue glue = invocation.getArgument(0);
glue.addBeforeAllHook(beforeAllHook);
glue.addAfterAllHook(afterAllHook);
glue.addBeforeHook(beforeHook);
glue.addAfterHook(afterHook);
return null;
}).when(backend).loadGlue(any(Glue.class), ArgumentMatchers.anyList());
Runner runner = new Runner(bus, singletonList(backend), objectFactory, runtimeOptions);
runner.runBeforeAllHooks();
runner.runPickle(createPicklesWithSteps());
runner.runAfterAllHooks();
InOrder inOrder = inOrder(beforeAllHook, afterAllHook, beforeHook, afterHook, backend);
inOrder.verify(beforeAllHook).execute();
inOrder.verify(backend).buildWorld();
inOrder.verify(beforeHook).execute(any(TestCaseState.class));
inOrder.verify(afterHook).execute(any(TestCaseState.class));
inOrder.verify(backend).disposeWorld();
inOrder.verify(afterAllHook).execute();
}
use of io.cucumber.core.backend.Backend in project cucumber-jvm by cucumber.
the class RunnerTest method backends_are_asked_for_snippets_for_undefined_steps.
@Test
void backends_are_asked_for_snippets_for_undefined_steps() {
Backend backend = mock(Backend.class);
when(backend.getSnippet()).thenReturn(new TestSnippet());
ObjectFactory objectFactory = mock(ObjectFactory.class);
Runner runner = new Runner(bus, singletonList(backend), objectFactory, runtimeOptions);
runner.runPickle(createPicklesWithSteps());
verify(backend).getSnippet();
}
use of io.cucumber.core.backend.Backend 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.Backend 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();
}
Aggregations