Skip to content

Commit b934ebc

Browse files
authored
JBEHAVE-1607 Remove meta data from scenario test data
1 parent 5ca4b87 commit b934ebc

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

jbehave-core/src/main/java/org/jbehave/core/embedder/PerformableTree.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ private Meta parameterMeta(RunContext context, Map<String, String> parameters) {
259259
String metaText = keywords.meta();
260260
if (parameters.containsKey(metaText)) {
261261
meta = Meta.createMeta(parameters.get(metaText), keywords);
262+
parameters.remove(metaText);
262263
}
263264
return meta;
264265
}

jbehave-core/src/test/java/org/jbehave/core/embedder/PerformableTreeBehaviour.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static java.util.Arrays.asList;
44
import static java.util.Collections.emptyList;
55
import static java.util.Collections.singletonList;
6+
import static java.util.Collections.singletonMap;
67
import static org.hamcrest.MatcherAssert.assertThat;
78
import static org.hamcrest.Matchers.equalTo;
89
import static org.hamcrest.Matchers.instanceOf;
@@ -42,6 +43,7 @@
4243
import org.jbehave.core.configuration.Configuration;
4344
import org.jbehave.core.configuration.Keywords;
4445
import org.jbehave.core.configuration.MostUsefulConfiguration;
46+
import org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario;
4547
import org.jbehave.core.embedder.PerformableTree.RunContext;
4648
import org.jbehave.core.failures.BatchFailures;
4749
import org.jbehave.core.failures.IgnoringStepsFailure;
@@ -268,6 +270,62 @@ void shouldReplaceParameters() {
268270
scenarioParameters.add(performableScenarios.get(1).getExamples().get(1).getParameters());
269271
assertEquals(scenarioParameters, scenarioParametersCaptor.getAllValues());
270272
}
273+
274+
@Test
275+
void shouldRemoveMetaFromFinalScenarioParameters() {
276+
ParameterControls parameterControls = new ParameterControls();
277+
Configuration configuration = mock(Configuration.class);
278+
when(configuration.storyControls()).thenReturn(new StoryControls());
279+
280+
StoryControls storyControls = mock(StoryControls.class);
281+
when(configuration.storyControls()).thenReturn(storyControls);
282+
when(storyControls.skipBeforeAndAfterScenarioStepsIfGivenStory()).thenReturn(false);
283+
when(configuration.parameterConverters()).thenReturn(new DefaultParameterConverters());
284+
when(configuration.parameterControls()).thenReturn(parameterControls);
285+
286+
when(configuration.keywords()).thenReturn(new Keywords());
287+
288+
StepMonitor stepMonitor = mock(StepMonitor.class);
289+
when(configuration.stepMonitor()).thenReturn(stepMonitor);
290+
StepCollector stepCollector = mock(StepCollector.class);
291+
when(configuration.stepCollector()).thenReturn(stepCollector);
292+
293+
ExamplesTable scenarioExamplesTable = ExamplesTable.empty().withRows(asList(
294+
createExamplesRow("Meta:", "@test", "value", "1")
295+
));
296+
297+
Scenario scenario = new Scenario("", new Meta(), GivenStories.EMPTY, scenarioExamplesTable,
298+
emptyList());
299+
300+
Lifecycle lifecycle = mock(Lifecycle.class);
301+
Story story = new Story(null, null, new Meta(), mock(Narrative.class), GivenStories.EMPTY, lifecycle,
302+
singletonList(scenario));
303+
304+
when(lifecycle.getExamplesTable()).thenReturn(ExamplesTable.EMPTY);
305+
306+
Map<Stage, List<Step>> lifecycleSteps = new EnumMap<>(Stage.class);
307+
lifecycleSteps.put(Stage.BEFORE, emptyList());
308+
lifecycleSteps.put(Stage.AFTER, emptyList());
309+
310+
ArgumentCaptor<Map<String, String>> storyParametersCaptor = ArgumentCaptor.forClass(Map.class);
311+
when(stepCollector.collectLifecycleSteps(eq(emptyList()), eq(lifecycle), isEmptyMeta(), eq(Scope.STORY),
312+
storyParametersCaptor.capture(), any(MatchingStepMonitor.class))).thenReturn(lifecycleSteps);
313+
314+
ArgumentCaptor<Map<String, String>> scenarioParametersCaptor = ArgumentCaptor.forClass(Map.class);
315+
when(stepCollector.collectLifecycleSteps(eq(emptyList()), eq(lifecycle), isEmptyMeta(), eq(Scope.SCENARIO),
316+
scenarioParametersCaptor.capture(), any(MatchingStepMonitor.class))).thenReturn(lifecycleSteps);
317+
318+
PerformableTree performableTree = new PerformableTree();
319+
createRunContext(configuration, performableTree, mock(BatchFailures.class), singletonList(story));
320+
List<PerformableTree.PerformableScenario> performableScenarios = performableTree.getRoot().getStories().get(0)
321+
.getScenarios();
322+
323+
assertThat(performableScenarios.size(), is(1));
324+
List<ExamplePerformableScenario> exampleScenarios = performableScenarios.get(0).getExamples();
325+
assertThat(exampleScenarios.size(), is(1));
326+
assertThat(singletonMap("value", "1"), equalTo(exampleScenarios.get(0).getParameters()));
327+
328+
}
271329

272330
private Map<String, String> createExamplesRow(String key1, String value1, String key2, String value2) {
273331
Map<String, String> storyExampleFirstRow = new HashMap<>();

0 commit comments

Comments
 (0)