use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldMapStoriesAsEmbeddables.
@Test
public void shouldMapStoriesAsEmbeddables() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyStoryMaps.class.getName();
List<String> classNames = asList(myEmbeddableName);
Embeddable myEmbeddable = new MyStoryMaps();
List<Embeddable> embeddables = asList(myEmbeddable);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
// When
Configuration configuration = new MostUsefulConfiguration();
Embedder embedder = embedderWith(performableTree, new EmbedderControls(), monitor);
embedder.useClassLoader(classLoader);
embedder.useConfiguration(configuration);
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
}
assertThat(MyStoryMaps.run, is(true));
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldNotRunStoriesAsEmbeddablesIfAbstract.
@Test
public void shouldNotRunStoriesAsEmbeddablesIfAbstract() 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 = MyAbstractEmbeddable.class.getName();
String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
Embeddable myEmbeddable = new MyEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.isAbstract(myEmbeddableName)).thenReturn(true);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.isAbstract(myOtherEmbeddableName)).thenReturn(false);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.configuration().useStoryPathResolver(new UnderscoredCamelCaseResolver());
embedder.runAsEmbeddables(classNames);
// Then
assertThat(out.toString(), not(containsString("Running embeddable " + myEmbeddableName)));
assertThat(out.toString(), containsString("Running embeddable " + myOtherEmbeddableName));
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureInStoriesFlagIsNotSet.
@Test(expected = RunningEmbeddablesFailed.class)
public void shouldThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureInStoriesFlagIsNotSet() 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 MyFailingEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.runAsEmbeddables(classNames);
// Then fail as expected
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldNotRunStoriesAsEmbeddablesIfSkipFlagIsSet.
@Test
public void shouldNotRunStoriesAsEmbeddablesIfSkipFlagIsSet() 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));
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
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.configuration().useStoryPathResolver(new UnderscoredCamelCaseResolver());
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), not(containsString("Running embeddable " + embeddable.getClass().getName())));
}
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunFailingStoriesAsEmbeddablesInBatchIfBatchFlagIsSet.
@Test
public void shouldRunFailingStoriesAsEmbeddablesInBatchIfBatchFlagIsSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doBatch(true).doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myStoryName = MyFailingEmbeddable.class.getName();
String myOtherStoryName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myStoryName, myOtherStoryName);
Embeddable myStory = new MyFailingEmbeddable();
Embeddable myOtherStory = new MyOtherEmbeddable();
List<Embeddable> embeddables = asList(myStory, myOtherStory);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myStoryName)).thenReturn(myStory);
when(classLoader.newInstance(Embeddable.class, myOtherStoryName)).thenReturn(myOtherStory);
// When
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
String storyName = embeddable.getClass().getName();
assertThat(out.toString(), containsString("Running embeddable " + storyName));
}
assertThat(out.toString(), containsString("Failed to run batch"));
}
Aggregations