|
3 | 3 | import static java.util.Arrays.asList;
|
4 | 4 | import static java.util.Collections.emptyList;
|
5 | 5 | import static java.util.Collections.singletonList;
|
| 6 | +import static java.util.Collections.singletonMap; |
6 | 7 | import static org.hamcrest.MatcherAssert.assertThat;
|
7 | 8 | import static org.hamcrest.Matchers.equalTo;
|
8 | 9 | import static org.hamcrest.Matchers.instanceOf;
|
|
42 | 43 | import org.jbehave.core.configuration.Configuration;
|
43 | 44 | import org.jbehave.core.configuration.Keywords;
|
44 | 45 | import org.jbehave.core.configuration.MostUsefulConfiguration;
|
| 46 | +import org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario; |
45 | 47 | import org.jbehave.core.embedder.PerformableTree.RunContext;
|
46 | 48 | import org.jbehave.core.failures.BatchFailures;
|
47 | 49 | import org.jbehave.core.failures.IgnoringStepsFailure;
|
@@ -268,6 +270,62 @@ void shouldReplaceParameters() {
|
268 | 270 | scenarioParameters.add(performableScenarios.get(1).getExamples().get(1).getParameters());
|
269 | 271 | assertEquals(scenarioParameters, scenarioParametersCaptor.getAllValues());
|
270 | 272 | }
|
| 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 | + } |
271 | 329 |
|
272 | 330 | private Map<String, String> createExamplesRow(String key1, String value1, String key2, String value2) {
|
273 | 331 | Map<String, String> storyExampleFirstRow = new HashMap<>();
|
|
0 commit comments