Search in sources :

Example 1 with HookDefinition

use of cucumber.runtime.HookDefinition in project cucumber-jvm by cucumber.

the class JavaHookTest method fails_if_hook_argument_is_not_scenario_result.

@Test
public void fails_if_hook_argument_is_not_scenario_result() throws Throwable {
    objectFactory.setInstance(new BadHook());
    backend.buildWorld();
    backend.addHook(BAD_AFTER.getAnnotation(After.class), BAD_AFTER);
    HookDefinition bad = glue.getAfterHooks().get(0);
    try {
        bad.execute(mock(Scenario.class));
        fail();
    } catch (CucumberException expected) {
        assertEquals("When a hook declares an argument it must be of type cucumber.api.Scenario. public void cucumber.runtime.java.JavaHookTest$BadHook.after(java.lang.String)", expected.getMessage());
    }
}
Also used : After(cucumber.api.java.After) CucumberException(cucumber.runtime.CucumberException) HookDefinition(cucumber.runtime.HookDefinition) Scenario(cucumber.api.Scenario) Test(org.junit.Test)

Example 2 with HookDefinition

use of cucumber.runtime.HookDefinition in project cucumber-jvm by cucumber.

the class JavaHookTest method matches_matching_tags.

@Test
public void matches_matching_tags() {
    objectFactory.setInstance(new HasHooks());
    backend.buildWorld();
    backend.addHook(BEFORE.getAnnotation(Before.class), BEFORE);
    HookDefinition before = glue.getBeforeHooks().get(0);
    assertTrue(before.matches(asList(new Tag("@bar", 0), new Tag("@zap", 0))));
}
Also used : Before(cucumber.api.java.Before) Tag(gherkin.formatter.model.Tag) HookDefinition(cucumber.runtime.HookDefinition) Test(org.junit.Test)

Example 3 with HookDefinition

use of cucumber.runtime.HookDefinition in project cucumber-jvm by cucumber.

the class JavaHookTest method hook_with_no_order_is_last.

@Test
public void hook_with_no_order_is_last() {
    objectFactory.setInstance(new HasHooks());
    backend.buildWorld();
    backend.addHook(BEFORE.getAnnotation(Before.class), BEFORE);
    HookDefinition hookDef = glue.getBeforeHooks().get(0);
    assertEquals(10000, hookDef.getOrder());
}
Also used : Before(cucumber.api.java.Before) HookDefinition(cucumber.runtime.HookDefinition) Test(org.junit.Test)

Example 4 with HookDefinition

use of cucumber.runtime.HookDefinition in project cucumber-jvm by cucumber.

the class JavaHookTest method hook_order_gets_registered.

@Test
public void hook_order_gets_registered() {
    objectFactory.setInstance(new HasHooks());
    backend.buildWorld();
    backend.addHook(AFTER.getAnnotation(After.class), AFTER);
    HookDefinition hookDef = glue.getAfterHooks().get(0);
    assertEquals(1, hookDef.getOrder());
}
Also used : After(cucumber.api.java.After) HookDefinition(cucumber.runtime.HookDefinition) Test(org.junit.Test)

Example 5 with HookDefinition

use of cucumber.runtime.HookDefinition in project cucumber-jvm by cucumber.

the class JavaHookTest method does_not_match_non_matching_tags.

@Test
public void does_not_match_non_matching_tags() {
    objectFactory.setInstance(new HasHooks());
    backend.buildWorld();
    backend.addHook(BEFORE.getAnnotation(Before.class), BEFORE);
    HookDefinition before = glue.getBeforeHooks().get(0);
    assertFalse(before.matches(asList(new Tag("@bar", 0))));
}
Also used : Before(cucumber.api.java.Before) Tag(gherkin.formatter.model.Tag) HookDefinition(cucumber.runtime.HookDefinition) Test(org.junit.Test)

Aggregations

HookDefinition (cucumber.runtime.HookDefinition)6 Test (org.junit.Test)5 Before (cucumber.api.java.Before)3 Tag (gherkin.formatter.model.Tag)3 After (cucumber.api.java.After)2 Scenario (cucumber.api.Scenario)1 Backend (cucumber.runtime.Backend)1 CucumberException (cucumber.runtime.CucumberException)1 Runtime (cucumber.runtime.Runtime)1 RuntimeOptions (cucumber.runtime.RuntimeOptions)1 StopWatch (cucumber.runtime.StopWatch)1 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)1 FunctionNameGenerator (cucumber.runtime.snippets.FunctionNameGenerator)1 Step (gherkin.formatter.model.Step)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1