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());
}
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());
}
}
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());
}
}
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());
}
}
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") });
}
Aggregations