use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsEmbeddables.
@Test
public void shouldRunStoriesAsEmbeddables() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyEmbeddable.class.getName();
String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
Embeddable myEmbeddable = new MyEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
List<Embeddable> embeddables = asList(myEmbeddable, myOtherEmbeddable);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Configuration configuration = new MostUsefulConfiguration();
CandidateSteps steps = mock(CandidateSteps.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.useConfiguration(configuration);
embedder.useCandidateSteps(asList(steps));
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
}
}
use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.
the class ConfigurableEmbedderBehaviour method shouldAllowAdditionOfSteps.
@Test
public void shouldAllowAdditionOfSteps() throws Throwable {
// Given
Embedder embedder = mock(Embedder.class);
Configuration configuration = mock(Configuration.class);
StoryPathResolver pathResolver = mock(StoryPathResolver.class);
when(embedder.configuration()).thenReturn(configuration);
when(configuration.storyPathResolver()).thenReturn(pathResolver);
Class<MyStory> storyClass = MyStory.class;
String storyPath = "/path/to/story";
when(pathResolver.resolve(storyClass)).thenReturn(storyPath);
CandidateSteps steps = mock(CandidateSteps.class);
// When
MyStory story = new MyStory(configuration, steps);
story.useEmbedder(embedder);
story.run();
// Then
verify(embedder).runStoriesAsPaths(asList(storyPath));
}
use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.
the class AnnotationBuilderBehaviour method assertThatStepsInstancesAre.
private void assertThatStepsInstancesAre(List<CandidateSteps> candidateSteps, Class<?>... stepsClasses) {
for (Class<?> stepsClass : stepsClasses) {
boolean found = false;
for (CandidateSteps steps : candidateSteps) {
Object instance = ((Steps) steps).instance();
if (instance.getClass() == stepsClass) {
found = true;
}
}
assertThat(found, is(true));
}
}
use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.
the class Embedder method reportStepdocsAsEmbeddables.
public void reportStepdocsAsEmbeddables(List<String> classNames) {
EmbedderControls embedderControls = embedderControls();
if (embedderControls.skip()) {
embedderMonitor.embeddablesSkipped(classNames);
return;
}
for (Embeddable embeddable : embeddables(classNames, classLoader())) {
if (embeddable instanceof ConfigurableEmbedder) {
ConfigurableEmbedder configurableEmbedder = (ConfigurableEmbedder) embeddable;
Embedder configuredEmbedder = configurableEmbedder.configuredEmbedder();
List<CandidateSteps> steps = configuredEmbedder.candidateSteps();
if (steps.isEmpty()) {
steps = configuredEmbedder.stepsFactory().createCandidateSteps();
}
reportStepdocs(configuredEmbedder.configuration(), steps);
} else {
embedderMonitor.embeddableNotConfigurable(embeddable.getClass().getName());
}
}
}
use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.
the class PicoStepsFactoryBehaviour method assertThatStepsWithStepsWithDependencyCanBeCreated.
@Test
public void assertThatStepsWithStepsWithDependencyCanBeCreated() throws NoSuchFieldException, IllegalAccessException {
MutablePicoContainer parent = createPicoContainer();
parent.as(Characteristics.USE_NAMES).addComponent(FooStepsWithDependency.class);
parent.addComponent(Integer.class, 42);
// When
PicoStepsFactory factory = new PicoStepsFactory(new MostUsefulConfiguration(), parent);
List<CandidateSteps> steps = factory.createCandidateSteps();
// Then
assertFooStepsFound(steps);
assertThat((int) ((FooStepsWithDependency) stepsInstance(steps.get(0))).integer, equalTo(42));
}
Aggregations