Search in sources :

Example 1 with AbstractStep

use of org.jbehave.core.steps.StepCreator.AbstractStep in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldNotPerformStepsAfterRestaringScenarioFailure.

@Test
public void shouldNotPerformStepsAfterRestaringScenarioFailure() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step firstStepNormal = mockSuccessfulStep("Given I succeed");
    final RestartingScenarioFailure hi = new RestartingScenarioFailure("hi");
    Step restartStep = new AbstractStep() {

        private int count = 0;

        public StepResult perform(UUIDExceptionWrapper storyFailureIfItHappened) {
            if (count == 0) {
                count++;
                throw hi;
            }
            return new AbstractStepResult.Successful("When happened on second attempt");
        }

        public StepResult doNotPerform(UUIDExceptionWrapper storyFailureIfItHappened) {
            return null;
        }

        @Override
        public String toString() {
            return "<fooStep>";
        }
    };
    Step lastStepNormal = mockSuccessfulStep("Then I succeeded");
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy strategy = mock(FailureStrategy.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario), eq(parameters))).thenReturn(asList(firstStepNormal, restartStep, lastStepNormal));
    Story story = new Story(asList(scenario));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, strategy), asList(mySteps), story);
    verify(reporter, times(2)).successful("Given I succeed");
    verify(reporter).restarted(eq("<fooStep>"), isA(RestartingScenarioFailure.class));
    verify(reporter).successful("When happened on second attempt");
    verify(reporter).successful("Then I succeeded");
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Aggregations

ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)1 StoryReporter (org.jbehave.core.reporters.StoryReporter)1 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)1 Test (org.junit.Test)1