Search in sources :

Example 1 with CandidateSteps

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()));
    }
}
Also used : PrintStream(java.io.PrintStream) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Embeddable(org.jbehave.core.Embeddable) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 2 with CandidateSteps

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));
}
Also used : StoryPathResolver(org.jbehave.core.io.StoryPathResolver) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 3 with CandidateSteps

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));
    }
}
Also used : Steps(org.jbehave.core.steps.Steps) CandidateSteps(org.jbehave.core.steps.CandidateSteps) UsingSteps(org.jbehave.core.annotations.UsingSteps) CandidateSteps(org.jbehave.core.steps.CandidateSteps)

Example 4 with CandidateSteps

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());
        }
    }
}
Also used : ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Embeddable(org.jbehave.core.Embeddable)

Example 5 with CandidateSteps

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));
}
Also used : MutablePicoContainer(org.picocontainer.MutablePicoContainer) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Aggregations

CandidateSteps (org.jbehave.core.steps.CandidateSteps)29 Test (org.junit.Test)23 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)18 Configuration (org.jbehave.core.configuration.Configuration)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 PrintStream (java.io.PrintStream)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 Embedder (org.jbehave.core.embedder.Embedder)5 StepFinder (org.jbehave.core.steps.StepFinder)5 PrintStreamStepdocReporter (org.jbehave.core.reporters.PrintStreamStepdocReporter)4 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)3 InjectableStepsFactory (org.jbehave.core.steps.InjectableStepsFactory)3 Steps (org.jbehave.core.steps.Steps)3 AbstractModule (com.google.inject.AbstractModule)2 Injector (com.google.inject.Injector)2 ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)2