use of org.jbehave.core.steps.InjectableStepsFactory in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet.
@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doBatch(true);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
Configuration configuration = embedder.configuration();
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
MetaFilter filter = embedder.metaFilter();
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
for (String storyPath : storyPaths) {
doNothing().when(performableTree).perform(runContext, stories.get(storyPath));
}
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
assertThat(out.toString(), containsString("Running story " + storyPath));
}
}
use of org.jbehave.core.steps.InjectableStepsFactory in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsPaths.
@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPaths() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
EmbedderMonitor embedderMonitor = mock(EmbedderMonitor.class);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
MetaFilter filter = embedder.metaFilter();
final StoryReporter storyReporter = mock(StoryReporter.class);
MostUsefulConfiguration configuration = new MostUsefulConfiguration() {
@Override
public StoryReporter storyReporter(String storyPath) {
return storyReporter;
}
};
embedder.useConfiguration(configuration);
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
}
RunContext runContext = new RunContext(configuration, stepsFactory, embedderMonitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
verify(performableTree).perform(Matchers.isA(RunContext.class), Matchers.eq(stories.get(storyPath)));
assertThat(out.toString(), containsString("Running story " + storyPath));
}
assertThatReportsViewGenerated(out);
}
use of org.jbehave.core.steps.InjectableStepsFactory in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldNotRunStoriesIfSkipFlagIsSet.
@SuppressWarnings("unchecked")
@Test
public void shouldNotRunStoriesIfSkipFlagIsSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doSkip(true);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
Configuration configuration = embedder.configuration();
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
MetaFilter filter = embedder.metaFilter();
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
verify(performableTree, never()).perform(runContext, stories.get(storyPath));
assertThat(out.toString(), not(containsString("Running story " + storyPath)));
}
assertThat(out.toString(), containsString("Skipped stories " + storyPaths));
}
use of org.jbehave.core.steps.InjectableStepsFactory in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunFailingStoriesAsPathsInBatchIfBatchFlagIsSet.
@SuppressWarnings("unchecked")
@Test
public void shouldRunFailingStoriesAsPathsInBatchIfBatchFlagIsSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doBatch(true).doIgnoreFailureInStories(true);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
Configuration configuration = embedder.configuration();
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
MetaFilter filter = embedder.metaFilter();
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
BatchFailures failures = new BatchFailures();
for (String storyPath : storyPaths) {
RuntimeException thrown = new RuntimeException(storyPath + " failed");
failures.put(storyPath, thrown);
doThrow(thrown).when(performableTree).perform(runContext, stories.get(storyPath));
}
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
String output = out.toString();
for (String storyPath : storyPaths) {
assertThat(output, containsString("Running story " + storyPath));
assertThat(output, containsString("Failed to run story " + storyPath));
}
}
use of org.jbehave.core.steps.InjectableStepsFactory in project jbehave-core by jbehave.
the class NeedleStepsFactoryBehaviour method stepsShouldContainInjectedDependencies.
@Test
public void stepsShouldContainInjectedDependencies() throws NoSuchFieldException, IllegalAccessException {
// Given
final InjectableStepsFactory factory = new NeedleStepsFactory(new MostUsefulConfiguration(), FooStepsWithDependency.class);
// When
List<CandidateSteps> steps = factory.createCandidateSteps();
// Then
assertThat(steps.size(), equalTo(1));
boolean actual1 = steps.get(0) instanceof CandidateSteps;
assertThat(actual1, is(true));
Object instance = stepsInstance(steps.get(0));
boolean actual = instance instanceof FooStepsWithDependency;
assertThat(actual, is(true));
FooStepsWithDependency withDependency = (FooStepsWithDependency) instance;
assertThat(withDependency.getter, is(notNullValue()));
assertThat((String) withDependency.getter.getValue(), equalTo(ValueGetter.VALUE));
}
Aggregations