Search in sources :

Example 26 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class BeforeOrAfterStepBehaviour method shouldPassMetaToStepCreatorWhenCreatingStepWithMeta.

@Test
public void shouldPassMetaToStepCreatorWhenCreatingStepWithMeta() throws Exception {
    StepCreator stepCreator = mock(StepCreator.class);
    Method method = methodFor("aMethodWith");
    BeforeOrAfterStep beforeOrAfterStep = new BeforeOrAfterStep(Stage.BEFORE, method, stepCreator);
    Meta meta = mock(Meta.class);
    beforeOrAfterStep.createStepWith(meta);
    verify(stepCreator).createBeforeOrAfterStep(method, meta);
}
Also used : Meta(org.jbehave.core.model.Meta) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 27 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPendingBehaviour method assertThatBeforeAndAfterScenarioAnnotatedStepsCanBeCollectedForGivenType.

private void assertThatBeforeAndAfterScenarioAnnotatedStepsCanBeCollectedForGivenType(ScenarioType scenarioType) {
    // Given some candidate steps classes with before and after scenario
    // methods
    Meta storyAndScenarioMeta = mock(Meta.class);
    CandidateSteps steps1 = mock(Steps.class);
    CandidateSteps steps2 = mock(Steps.class);
    BeforeOrAfterStep bafStep11 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep12 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep21 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep22 = mock(BeforeOrAfterStep.class);
    Step stepBefore1 = mock(Step.class);
    Step stepBefore2 = mock(Step.class);
    Step stepAfter1 = mock(Step.class);
    Step stepAfter2 = mock(Step.class);
    when(bafStep11.getStage()).thenReturn(Stage.BEFORE);
    when(bafStep11.createStepWith(storyAndScenarioMeta)).thenReturn(stepBefore1);
    when(bafStep12.getStage()).thenReturn(Stage.BEFORE);
    when(bafStep12.createStepWith(storyAndScenarioMeta)).thenReturn(stepBefore2);
    when(bafStep21.getStage()).thenReturn(Stage.AFTER);
    when(bafStep21.createStepUponOutcome(storyAndScenarioMeta)).thenReturn(stepAfter1);
    when(bafStep22.getStage()).thenReturn(Stage.AFTER);
    when(bafStep22.createStepUponOutcome(storyAndScenarioMeta)).thenReturn(stepAfter2);
    when(steps1.listBeforeOrAfterScenario(scenarioType)).thenReturn(asList(bafStep11, bafStep12));
    when(steps2.listBeforeOrAfterScenario(scenarioType)).thenReturn(asList(bafStep21, bafStep22));
    // When we collect the list of steps
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterScenarioSteps(asList(steps1, steps2), storyAndScenarioMeta, Stage.BEFORE, scenarioType);
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterScenarioSteps(asList(steps1, steps2), storyAndScenarioMeta, Stage.AFTER, scenarioType);
    // Then all before and after steps should be added
    assertThat(beforeSteps, equalTo(asList(stepBefore1, stepBefore2)));
    assertThat(afterSteps, equalTo(asList(stepAfter1, stepAfter2)));
}
Also used : Meta(org.jbehave.core.model.Meta) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep)

Example 28 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPendingBehaviour method shouldInvokeBeforeOrAfterScenarioWithParameter.

@Test
public void shouldInvokeBeforeOrAfterScenarioWithParameter() throws Exception {
    BeforeOrAfterScenarioWithParameterSteps steps = new BeforeOrAfterScenarioWithParameterSteps();
    Meta meta = beforeAndAfterMeta();
    ScenarioType scenarioType = ScenarioType.NORMAL;
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterScenarioSteps(asList((CandidateSteps) steps), meta, Stage.BEFORE, scenarioType);
    beforeSteps.get(0).perform(null);
    assertThat(steps.value, equalTo("before"));
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterScenarioSteps(asList((CandidateSteps) steps), meta, Stage.AFTER, scenarioType);
    afterSteps.get(0).perform(null);
    assertThat(steps.value, equalTo("after"));
}
Also used : Meta(org.jbehave.core.model.Meta) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Test(org.junit.Test)

Example 29 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPendingBehaviour method shouldInvokeBeforeOrAfterScenarioWithParameterAndException.

@Test
public void shouldInvokeBeforeOrAfterScenarioWithParameterAndException() throws Exception {
    BeforeOrAfterScenarioWithParameterAndExceptionSteps steps = new BeforeOrAfterScenarioWithParameterAndExceptionSteps();
    Meta meta = beforeAndAfterMeta();
    UUIDExceptionWrapper failureOccurred = new UUIDExceptionWrapper();
    ScenarioType scenarioType = ScenarioType.NORMAL;
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterScenarioSteps(asList((CandidateSteps) steps), meta, Stage.BEFORE, scenarioType);
    beforeSteps.get(0).doNotPerform(failureOccurred);
    assertThat(steps.value, equalTo("before"));
    assertThat(steps.exception, equalTo(failureOccurred));
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterScenarioSteps(asList((CandidateSteps) steps), meta, Stage.AFTER, scenarioType);
    failureOccurred = new UUIDExceptionWrapper();
    afterSteps.get(0).doNotPerform(failureOccurred);
    assertThat(steps.value, equalTo("after"));
    assertThat(steps.exception, equalTo(failureOccurred));
}
Also used : Meta(org.jbehave.core.model.Meta) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 30 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPendingBehaviour method shouldCollectBeforeAndAfterStoryAnnotatedSteps.

@Test
public void shouldCollectBeforeAndAfterStoryAnnotatedSteps() {
    // Given some candidate steps classes with before and after story
    // methods
    Story story = new Story();
    Meta storyMeta = story.getMeta();
    CandidateSteps steps1 = mock(Steps.class);
    CandidateSteps steps2 = mock(Steps.class);
    BeforeOrAfterStep bafStep11 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep21 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep12 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep22 = mock(BeforeOrAfterStep.class);
    Step stepBefore1 = mock(Step.class);
    Step stepBefore2 = mock(Step.class);
    Step stepAfter1 = mock(Step.class);
    Step stepAfter2 = mock(Step.class);
    boolean givenStory = false;
    when(bafStep11.getStage()).thenReturn(Stage.BEFORE);
    when(bafStep11.createStepWith(storyMeta)).thenReturn(stepBefore1);
    when(bafStep21.getStage()).thenReturn(Stage.BEFORE);
    when(bafStep21.createStepWith(storyMeta)).thenReturn(stepBefore2);
    when(bafStep12.getStage()).thenReturn(Stage.AFTER);
    when(bafStep12.createStepWith(storyMeta)).thenReturn(stepAfter1);
    when(bafStep22.getStage()).thenReturn(Stage.AFTER);
    when(bafStep22.createStepWith(storyMeta)).thenReturn(stepAfter2);
    when(steps1.listBeforeOrAfterStory(givenStory)).thenReturn(asList(bafStep11, bafStep12));
    when(steps2.listBeforeOrAfterStory(givenStory)).thenReturn(asList(bafStep21, bafStep22));
    // When we collect the list of steps
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterStorySteps(asList(steps1, steps2), story, Stage.BEFORE, givenStory);
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterStorySteps(asList(steps1, steps2), story, Stage.AFTER, givenStory);
    // Then all before and after steps should be added
    assertThat(beforeSteps, equalTo(asList(stepBefore1, stepBefore2)));
    assertThat(afterSteps, equalTo(asList(stepAfter1, stepAfter2)));
}
Also used : Meta(org.jbehave.core.model.Meta) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

Meta (org.jbehave.core.model.Meta)32 Test (org.junit.Test)23 Story (org.jbehave.core.model.Story)11 Scenario (org.jbehave.core.model.Scenario)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 HashMap (java.util.HashMap)6 Properties (java.util.Properties)6 GivenStory (org.jbehave.core.model.GivenStory)6 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)6 StepMatcher (org.jbehave.core.parsers.StepMatcher)6 Silent (org.jbehave.core.steps.AbstractStepResult.Silent)6 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)6 Map (java.util.Map)4 PendingStep (org.jbehave.core.steps.StepCreator.PendingStep)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ScenarioType (org.jbehave.core.annotations.ScenarioType)3 ExamplesTable (org.jbehave.core.model.ExamplesTable)3 Lifecycle (org.jbehave.core.model.Lifecycle)3 BytecodeReadingParanamer (com.thoughtworks.paranamer.BytecodeReadingParanamer)2 CachingParanamer (com.thoughtworks.paranamer.CachingParanamer)2