Search in sources :

Example 6 with Tag

use of gherkin.formatter.model.Tag 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 7 with Tag

use of gherkin.formatter.model.Tag in project cucumber-jvm by cucumber.

the class HookOrderTest method after_hooks_execute_in_reverse_order.

@Test
public void after_hooks_execute_in_reverse_order() throws Throwable {
    List<HookDefinition> hooks = mockHooks(Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0, 10000);
    for (HookDefinition hook : hooks) {
        glue.addAfterHook(hook);
    }
    runtime.runAfterHooks(mock(Reporter.class), new HashSet<Tag>());
    InOrder inOrder = inOrder(hooks.toArray());
    inOrder.verify(hooks.get(2)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(6)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(3)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(1)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(5)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(4)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(0)).execute(Matchers.<Scenario>any());
}
Also used : InOrder(org.mockito.InOrder) Reporter(gherkin.formatter.Reporter) Tag(gherkin.formatter.model.Tag) Test(org.junit.Test)

Example 8 with Tag

use of gherkin.formatter.model.Tag 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>.
     * TODO: ensure this is no longer needed with the alternate approach taken in Runtime
     * TODO: this test is rather brittle, since there's lots of mocking :(
     */
@Test
public void after_hooks_execute_before_objects_are_disposed() throws Throwable {
    Backend backend = mock(Backend.class);
    HookDefinition hook = mock(HookDefinition.class);
    when(hook.matches(anyListOf(Tag.class))).thenReturn(true);
    gherkin.formatter.model.Scenario gherkinScenario = mock(gherkin.formatter.model.Scenario.class);
    CucumberFeature feature = mock(CucumberFeature.class);
    Feature gherkinFeature = mock(Feature.class);
    when(feature.getGherkinFeature()).thenReturn(gherkinFeature);
    when(gherkinFeature.getTags()).thenReturn(new ArrayList<Tag>());
    CucumberScenario scenario = new CucumberScenario(feature, null, gherkinScenario);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    RuntimeOptions runtimeOptions = new RuntimeOptions("");
    Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
    runtime.getGlue().addAfterHook(hook);
    scenario.run(mock(Formatter.class), mock(Reporter.class), runtime);
    InOrder inOrder = inOrder(hook, backend);
    inOrder.verify(hook).execute(Matchers.<Scenario>any());
    inOrder.verify(backend).disposeWorld();
}
Also used : InOrder(org.mockito.InOrder) Formatter(gherkin.formatter.Formatter) Reporter(gherkin.formatter.Reporter) CucumberScenario(cucumber.runtime.model.CucumberScenario) CucumberFeature(cucumber.runtime.model.CucumberFeature) Feature(gherkin.formatter.model.Feature) CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Tag(gherkin.formatter.model.Tag) Test(org.junit.Test)

Example 9 with Tag

use of gherkin.formatter.model.Tag in project cucumber-jvm by cucumber.

the class RhinoHooksTest method assertHook.

private void assertHook(HookDefinition hookDefinition, String[] tagExprs, int order, long timeoutMillis) {
    assertThat(hookDefinition, instanceOf(RhinoHookDefinition.class));
    RhinoHookDefinition rhinoHook = (RhinoHookDefinition) hookDefinition;
    List<Tag> tags = new ArrayList<Tag>();
    for (String tagExpr : tagExprs) {
        tags.add(new Tag(tagExpr, null));
    }
    assertTrue(rhinoHook.getTagExpression().evaluate(tags));
    assertThat(rhinoHook.getOrder(), equalTo(order));
    assertThat(rhinoHook.getTimeout(), equalTo(timeoutMillis));
}
Also used : ArrayList(java.util.ArrayList) Tag(gherkin.formatter.model.Tag)

Example 10 with Tag

use of gherkin.formatter.model.Tag in project cucumber-jvm by cucumber.

the class JavaStepDefinitionTest method throws_ambiguous_when_two_matches_are_found.

@Test
public void throws_ambiguous_when_two_matches_are_found() throws Throwable {
    backend.addStepDefinition(THREE_DISABLED_MICE.getAnnotation(Given.class), THREE_DISABLED_MICE);
    backend.addStepDefinition(THREE_BLIND_ANIMALS.getAnnotation(Given.class), THREE_BLIND_ANIMALS);
    Reporter reporter = mock(Reporter.class);
    runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), mock(Scenario.class));
    Tag tag = new Tag("@foo", 0);
    runtime.runBeforeHooks(reporter, asSet(tag));
    runtime.runStep("some.feature", new Step(NO_COMMENTS, "Given ", "three blind mice", 1, null, null), reporter, ENGLISH);
    ArgumentCaptor<Result> result = ArgumentCaptor.forClass(Result.class);
    verify(reporter).result(result.capture());
    assertEquals(AmbiguousStepDefinitionsException.class, result.getValue().getError().getClass());
}
Also used : Given(cucumber.api.java.en.Given) Reporter(gherkin.formatter.Reporter) Tag(gherkin.formatter.model.Tag) Step(gherkin.formatter.model.Step) Scenario(gherkin.formatter.model.Scenario) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Aggregations

Tag (gherkin.formatter.model.Tag)12 Test (org.junit.Test)9 Reporter (gherkin.formatter.Reporter)6 InOrder (org.mockito.InOrder)4 Scenario (gherkin.formatter.model.Scenario)3 Step (gherkin.formatter.model.Step)3 Before (cucumber.api.java.Before)2 Given (cucumber.api.java.en.Given)2 HookDefinition (cucumber.runtime.HookDefinition)2 Feature (gherkin.formatter.model.Feature)2 Result (gherkin.formatter.model.Result)2 ArrayList (java.util.ArrayList)2 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)1 CucumberFeature (cucumber.runtime.model.CucumberFeature)1 CucumberScenario (cucumber.runtime.model.CucumberScenario)1 Formatter (gherkin.formatter.Formatter)1 Comment (gherkin.formatter.model.Comment)1 Examples (gherkin.formatter.model.Examples)1 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)1 Match (gherkin.formatter.model.Match)1