use of io.cucumber.core.backend.StaticHookDefinition 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.StaticHookDefinition in project cucumber-jvm by cucumber.
the class RunnerTest method all_static_hooks_execute_also_after_failure.
@Test
void all_static_hooks_execute_also_after_failure() {
StaticHookDefinition beforeAllHook = createStaticHook();
StaticHookDefinition failingBeforeAllHook = createStaticHook();
doThrow(new RuntimeException("boom")).when(failingBeforeAllHook).execute();
TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {
@Override
public void loadGlue(Glue glue, List<URI> gluePaths) {
glue.addBeforeAllHook(beforeAllHook);
glue.addBeforeAllHook(failingBeforeAllHook);
}
};
Runner runner = runnerSupplier.get();
assertThrows(RuntimeException.class, runner::runBeforeAllHooks);
InOrder inOrder = inOrder(beforeAllHook, failingBeforeAllHook);
inOrder.verify(beforeAllHook).execute();
inOrder.verify(failingBeforeAllHook).execute();
}
use of io.cucumber.core.backend.StaticHookDefinition in project cucumber-jvm by cucumber.
the class RunnerTest method createStaticHook.
private StaticHookDefinition createStaticHook() {
StaticHookDefinition hook = mock(StaticHookDefinition.class);
when(hook.getLocation()).thenReturn("");
return hook;
}
use of io.cucumber.core.backend.StaticHookDefinition in project cucumber-jvm by cucumber.
the class RunnerTest method hooks_not_executed_in_dry_run_mode.
@Test
void hooks_not_executed_in_dry_run_mode() {
RuntimeOptions runtimeOptions = new RuntimeOptionsBuilder().setDryRun().build();
StaticHookDefinition beforeAllHook = createStaticHook();
StaticHookDefinition afterAllHook = createStaticHook();
HookDefinition beforeHook = createHook();
HookDefinition afterHook = createHook();
HookDefinition beforeStepHook = createHook();
HookDefinition afterStepHook = createHook();
TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {
@Override
public void loadGlue(Glue glue, List<URI> gluePaths) {
glue.addBeforeAllHook(beforeAllHook);
glue.addAfterAllHook(afterAllHook);
glue.addBeforeHook(beforeHook);
glue.addAfterHook(afterHook);
glue.addBeforeStepHook(beforeStepHook);
glue.addAfterStepHook(afterStepHook);
}
};
runnerSupplier.get().runBeforeAllHooks();
runnerSupplier.get().runPickle(createPicklesWithSteps());
runnerSupplier.get().runAfterAllHooks();
verify(beforeAllHook, never()).execute();
verify(afterAllHook, never()).execute();
verify(beforeHook, never()).execute(any(TestCaseState.class));
verify(afterHook, never()).execute(any(TestCaseState.class));
verify(beforeStepHook, never()).execute(any(TestCaseState.class));
verify(afterStepHook, never()).execute(any(TestCaseState.class));
}
use of io.cucumber.core.backend.StaticHookDefinition in project cucumber-jvm by cucumber.
the class Runner method executeHooks.
private void executeHooks(List<StaticHookDefinition> afterAllHooks) {
ThrowableCollector throwableCollector = new ThrowableCollector();
for (StaticHookDefinition staticHookDefinition : afterAllHooks) {
throwableCollector.execute(() -> executeHook(staticHookDefinition));
}
Throwable throwable = throwableCollector.getThrowable();
if (throwable != null) {
throwAsUncheckedException(throwable);
}
}
Aggregations