Search in sources :

Example 1 with State

use of org.jbehave.core.embedder.StoryRunner.State in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldReportStoryCancellation.

@Test
public void shouldReportStoryCancellation() {
    // Given
    Configuration configuration = mock(Configuration.class, Mockito.RETURNS_DEEP_STUBS);
    when(configuration.storyControls().dryRun()).thenReturn(false);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    when(configuration.storyReporter(Matchers.anyString())).thenReturn(reporter);
    Story story = mock(Story.class);
    String storyPath = "story/path";
    when(story.getPath()).thenReturn(storyPath);
    RuntimeException expected = new RuntimeException();
    when(story.getMeta()).thenThrow(expected);
    InjectableStepsFactory stepsFactory = mock(InjectableStepsFactory.class);
    MetaFilter metaFilter = mock(MetaFilter.class);
    State state = mock(State.class);
    // When
    long durationInSecs = 2;
    long timeoutInSecs = 1;
    StoryDuration storyDuration = new StoryDuration(timeoutInSecs);
    try {
        StoryRunner runner = new StoryRunner();
        runner.cancelStory(story, storyDuration);
        runner.run(configuration, stepsFactory, story, metaFilter, state);
        throw new AssertionError("A exception should be thrown");
    } catch (Throwable e) {
        // Then
        assertThat(e.equals(expected), is(true));
    }
    verify(reporter).storyCancelled(story, storyDuration);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) State(org.jbehave.core.embedder.StoryRunner.State) Test(org.junit.Test)

Aggregations

Configuration (org.jbehave.core.configuration.Configuration)1 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)1 State (org.jbehave.core.embedder.StoryRunner.State)1 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)1 StoryReporter (org.jbehave.core.reporters.StoryReporter)1 Test (org.junit.Test)1