Search in sources :

Example 31 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldRunMultipleStories.

@Test
public void shouldRunMultipleStories() throws Throwable {
    // Given
    Embedder embedder = mock(Embedder.class);
    Configuration configuration = mock(Configuration.class);
    CandidateSteps steps = mock(CandidateSteps.class);
    // When
    MyStories story = new MyStories(configuration, steps);
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).runStoriesAsPaths(asList("org/jbehave/core/story1", "org/jbehave/core/story2"));
}
Also used : 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 32 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldAllowOverrideOfDefaultConfiguration.

@Test
public void shouldAllowOverrideOfDefaultConfiguration() 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(new MostUsefulConfiguration(), steps);
    assertThat(story.configuration(), is(not(sameInstance(configuration))));
    story.useConfiguration(configuration);
    assertThat(story.configuration(), is(sameInstance(configuration)));
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).useConfiguration(configuration);
    verify(embedder).useCandidateSteps(Mockito.eq(Arrays.asList(steps)));
    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) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 33 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldRunASingleStory.

@Test
public void shouldRunASingleStory() 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).useConfiguration(configuration);
    verify(embedder).useCandidateSteps(eq(asList(steps)));
    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 34 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class AnnotationBuilderBehaviour method shouldCreateEmbeddableInstanceFromConfigurableEmbedder.

@Test
public void shouldCreateEmbeddableInstanceFromConfigurableEmbedder() {
    AnnotationBuilder annotatedConfigurable = new AnnotationBuilder(AnnotedConfigurable.class);
    Object instance = annotatedConfigurable.embeddableInstance();
    assertThat(instance, Matchers.instanceOf(ConfigurableEmbedder.class));
    Embedder embedder = ((ConfigurableEmbedder) instance).configuredEmbedder();
    assertThat(embedder.configuration().keywords(), instanceOf(MyKeywords.class));
    assertThat(embedder.metaFilters(), equalTo(asList("+embedder configurable")));
    assertThatStepsInstancesAre(embedder.stepsFactory().createCandidateSteps(), MySteps.class);
}
Also used : ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Example 35 with Embedder

use of org.jbehave.core.embedder.Embedder in project jbehave-core by jbehave.

the class AnnotationBuilderBehaviour method shouldCreateEmbeddableInstanceFromConfigurableEmbedderWithoutStepsFactory.

@Test
public void shouldCreateEmbeddableInstanceFromConfigurableEmbedderWithoutStepsFactory() {
    AnnotationBuilder annotatedConfigurable = new AnnotationBuilder(AnnotedConfigurableWithoutStepsFactory.class);
    Object instance = annotatedConfigurable.embeddableInstance();
    assertThat(instance, Matchers.instanceOf(ConfigurableEmbedder.class));
    Embedder embedder = ((ConfigurableEmbedder) instance).configuredEmbedder();
    assertThat(embedder.configuration().keywords(), instanceOf(MyKeywords.class));
    assertThat(embedder.metaFilters(), equalTo(asList("+embedder configurable")));
    assertThatStepsInstancesAre(embedder.candidateSteps(), MySteps.class);
}
Also used : ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Aggregations

Embedder (org.jbehave.core.embedder.Embedder)56 Test (org.junit.Test)33 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)25 ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)10 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 EmbedderControls (org.jbehave.core.embedder.EmbedderControls)7 Configuration (org.jbehave.core.configuration.Configuration)6 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)6 File (java.io.File)5 Properties (java.util.Properties)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 CandidateSteps (org.jbehave.core.steps.CandidateSteps)5 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)4 HashSet (java.util.HashSet)3 Artifact (org.apache.maven.artifact.Artifact)3 Build (org.apache.maven.model.Build)3 MavenProject (org.apache.maven.project.MavenProject)3 ArchiverManager (org.codehaus.plexus.archiver.manager.ArchiverManager)3 StoryFinder (org.jbehave.core.io.StoryFinder)3