Search in sources :

Example 1 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class RuntimeGlueTest method removes_glue_that_is_scenario_scoped.

@Test
public void removes_glue_that_is_scenario_scoped() {
    // This test is a bit fragile - it is testing state, not behaviour.
    // But it was too much hassle creating a better test without refactoring RuntimeGlue
    // and probably some of its immediate collaborators... Aslak.
    RuntimeGlue glue = new RuntimeGlue(new UndefinedStepsTracker(), new LocalizedXStreams(Thread.currentThread().getContextClassLoader()));
    StepDefinition sd = mock(StepDefinition.class);
    when(sd.isScenarioScoped()).thenReturn(true);
    when(sd.getPattern()).thenReturn("pattern");
    glue.addStepDefinition(sd);
    HookDefinition bh = mock(HookDefinition.class);
    when(bh.isScenarioScoped()).thenReturn(true);
    glue.addBeforeHook(bh);
    HookDefinition ah = mock(HookDefinition.class);
    when(ah.isScenarioScoped()).thenReturn(true);
    glue.addAfterHook(ah);
    assertEquals(1, glue.stepDefinitionsByPattern.size());
    assertEquals(1, glue.beforeHooks.size());
    assertEquals(1, glue.afterHooks.size());
    glue.removeScenarioScopedGlue();
    assertEquals(0, glue.stepDefinitionsByPattern.size());
    assertEquals(0, glue.beforeHooks.size());
    assertEquals(0, glue.afterHooks.size());
}
Also used : LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

Example 2 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class RuntimeGlueTest method throws_duplicate_error_on_dupe_stepdefs.

@Test
public void throws_duplicate_error_on_dupe_stepdefs() {
    RuntimeGlue glue = new RuntimeGlue(new UndefinedStepsTracker(), new LocalizedXStreams(Thread.currentThread().getContextClassLoader()));
    StepDefinition a = mock(StepDefinition.class);
    when(a.getPattern()).thenReturn("hello");
    when(a.getLocation(true)).thenReturn("foo.bf:10");
    glue.addStepDefinition(a);
    StepDefinition b = mock(StepDefinition.class);
    when(b.getPattern()).thenReturn("hello");
    when(b.getLocation(true)).thenReturn("bar.bf:90");
    try {
        glue.addStepDefinition(b);
        fail("should have failed");
    } catch (DuplicateStepDefinitionException expected) {
        assertEquals("Duplicate step definitions in foo.bf:10 and bar.bf:90", expected.getMessage());
    }
}
Also used : LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

Example 3 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments.

@Test
public void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments() throws Throwable {
    Step step = new Step(null, "Given ", "I have 4 cukes in my belly", 1, null, null);
    StepDefinition stepDefinition = new StubStepDefinition(new Object(), Object.class.getMethod("toString"), "some pattern");
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(asList(new Argument(7, "4")), stepDefinition, null, step, new LocalizedXStreams(getClass().getClassLoader()));
    try {
        stepDefinitionMatch.runStep(new I18n("en"));
        fail();
    } catch (CucumberException expected) {
        assertEquals("Arity mismatch: Step Definition 'toString' with pattern [some pattern] is declared with 0 parameters. However, the gherkin step has 1 arguments [4]. \n" + "Step: Given I have 4 cukes in my belly", expected.getMessage());
    }
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) I18n(gherkin.I18n) Test(org.junit.Test)

Example 4 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments.

@Test
public void throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments() throws Throwable {
    Step step = new Step(null, "Given ", "I have 4 cukes in my belly", 1, new ArrayList<DataTableRow>(), null);
    StepDefinition stepDefinition = new StubStepDefinition(new Object(), WithTwoParams.class.getMethod("withTwoParams", Integer.TYPE, Short.TYPE, List.class), "some pattern");
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(asList(new Argument(7, "4")), stepDefinition, null, step, new LocalizedXStreams(getClass().getClassLoader()));
    try {
        stepDefinitionMatch.runStep(new I18n("en"));
        fail();
    } catch (CucumberException expected) {
        assertEquals("Arity mismatch: Step Definition 'withTwoParams' with pattern [some pattern] is declared with 3 parameters. However, the gherkin step has 2 arguments [4, Table:[]]. \n" + "Step: Given I have 4 cukes in my belly", expected.getMessage());
    }
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) DataTableRow(gherkin.formatter.model.DataTableRow) I18n(gherkin.I18n) Test(org.junit.Test)

Example 5 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method converts_with_explicit_converter.

@Test
public void converts_with_explicit_converter() throws Throwable {
    StepDefinition stepDefinition = mock(StepDefinition.class);
    when(stepDefinition.getParameterCount()).thenReturn(1);
    when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Thing.class, null, null, null));
    Step stepWithoutDocStringOrTable = mock(Step.class);
    when(stepWithoutDocStringOrTable.getDocString()).thenReturn(null);
    when(stepWithoutDocStringOrTable.getRows()).thenReturn(null);
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(Arrays.asList(new Argument(0, "the thing")), stepDefinition, "some.feature", stepWithoutDocStringOrTable, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(ENGLISH);
    verify(stepDefinition).execute(ENGLISH, new Object[] { new Thing("the thing") });
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

Aggregations

LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)15 Test (org.junit.Test)10 Step (gherkin.formatter.model.Step)9 Argument (gherkin.formatter.Argument)8 I18n (gherkin.I18n)3 DataTableRow (gherkin.formatter.model.DataTableRow)3 DocString (gherkin.formatter.model.DocString)3 ArrayList (java.util.ArrayList)3 DataTable (cucumber.api.DataTable)2 ParameterInfo (cucumber.runtime.ParameterInfo)2 StepDefinition (cucumber.runtime.StepDefinition)1 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)1 StubStepDefinition (cucumber.runtime.StubStepDefinition)1 TableConverter (cucumber.runtime.table.TableConverter)1 En (gherkin.lexer.En)1 Lexer (gherkin.lexer.Lexer)1 Listener (gherkin.lexer.Listener)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Before (org.junit.Before)1