Search in sources :

Example 16 with HookDefinition

use of io.cucumber.core.backend.HookDefinition 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));
}
Also used : Glue(io.cucumber.core.backend.Glue) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 17 with HookDefinition

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

the class CachingGlueTest method sorts_after_hooks_in_reverse_order.

@Test
void sorts_after_hooks_in_reverse_order() {
    HookDefinition hookDefinition1 = new MockedScenarioScopedHookDefinition(12);
    HookDefinition hookDefinition2 = new MockedScenarioScopedHookDefinition(12);
    HookDefinition hookDefinition3 = new MockedScenarioScopedHookDefinition(24);
    glue.addAfterHook(hookDefinition1);
    glue.addAfterHook(hookDefinition2);
    glue.addAfterHook(hookDefinition3);
    List<HookDefinition> hooks = glue.getAfterHooks().stream().map(CoreHookDefinition::getDelegate).collect(Collectors.toList());
    assertThat(hooks, contains(hookDefinition3, hookDefinition2, hookDefinition1));
}
Also used : HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 18 with HookDefinition

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

the class CachingGlueTest method scenario_scoped_hooks_have_higher_order.

@Test
void scenario_scoped_hooks_have_higher_order() {
    HookDefinition hookDefinition1 = new MockedScenarioScopedHookDefinition(12);
    HookDefinition hookDefinition2 = new MockedHookDefinition(12);
    HookDefinition hookDefinition3 = new MockedScenarioScopedHookDefinition(24);
    glue.addBeforeHook(hookDefinition1);
    glue.addBeforeHook(hookDefinition2);
    glue.addBeforeHook(hookDefinition3);
    List<HookDefinition> hooks = glue.getBeforeHooks().stream().map(CoreHookDefinition::getDelegate).collect(Collectors.toList());
    assertThat(hooks, contains(hookDefinition2, hookDefinition1, hookDefinition3));
}
Also used : HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 19 with HookDefinition

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

the class HookOrderTest method after_step_hooks_execute_in_reverse_order.

@Test
void after_step_hooks_execute_in_reverse_order() {
    final List<HookDefinition> hooks = mockHooks(Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0, 10000);
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addStepDefinition(stepDefinition);
            for (HookDefinition hook : hooks) {
                glue.addAfterStepHook(hook);
            }
        }
    };
    runnerSupplier.get().runPickle(pickle);
    InOrder inOrder = inOrder(hooks.toArray());
    inOrder.verify(hooks.get(2)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(6)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(3)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(1)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(5)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(4)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(0)).execute(ArgumentMatchers.any());
}
Also used : InOrder(org.mockito.InOrder) Glue(io.cucumber.core.backend.Glue) ArrayList(java.util.ArrayList) List(java.util.List) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 20 with HookDefinition

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

the class HookOrderTest method after_hooks_execute_in_reverse_order.

@Test
void after_hooks_execute_in_reverse_order() {
    final List<HookDefinition> hooks = mockHooks(Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0, 10000);
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addStepDefinition(stepDefinition);
            for (HookDefinition hook : hooks) {
                glue.addAfterHook(hook);
            }
        }
    };
    runnerSupplier.get().runPickle(pickle);
    InOrder inOrder = inOrder(hooks.toArray());
    inOrder.verify(hooks.get(2)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(6)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(3)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(1)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(5)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(4)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(0)).execute(ArgumentMatchers.any());
}
Also used : InOrder(org.mockito.InOrder) Glue(io.cucumber.core.backend.Glue) ArrayList(java.util.ArrayList) List(java.util.List) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

HookDefinition (io.cucumber.core.backend.HookDefinition)20 Test (org.junit.jupiter.api.Test)18 Glue (io.cucumber.core.backend.Glue)14 List (java.util.List)11 InOrder (org.mockito.InOrder)11 StaticHookDefinition (io.cucumber.core.backend.StaticHookDefinition)8 ArrayList (java.util.ArrayList)6 Collections.emptyList (java.util.Collections.emptyList)6 Collections.singletonList (java.util.Collections.singletonList)6 Backend (io.cucumber.core.backend.Backend)3 ObjectFactory (io.cucumber.core.backend.ObjectFactory)3 Pickle (io.cucumber.core.gherkin.Pickle)3 TestSnippet (io.cucumber.core.snippets.TestSnippet)3 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)2 TestCaseState (io.cucumber.core.backend.TestCaseState)1 Feature (io.cucumber.core.gherkin.Feature)1 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)1 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)1