Search in sources :

Example 6 with StoryLocation

use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.

the class FilePrintStreamFactoryBehaviour method ensureOutputFileIsSame.

private void ensureOutputFileIsSame(URL codeLocation, String storyPath) {
    FileConfiguration configuration = new FileConfiguration("ext");
    FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration);
    factory.createPrintStream();
    File outputFile = factory.getOutputFile();
    String expected = new File(codeLocation.getFile()).getParent().replace('\\', '/') + "/" + configuration.getRelativeDirectory() + "/" + "org.jbehave.examples.trader.stories.my_given." + configuration.getExtension();
    assertThat(outputFile.toString().replace('\\', '/'), equalTo(expected));
}
Also used : FileConfiguration(org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration) StoryLocation(org.jbehave.core.io.StoryLocation) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File)

Example 7 with StoryLocation

use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.

the class StoryReporterBuilderBehaviour method shouldBuildWithCustomKeywords.

@Test
public void shouldBuildWithCustomKeywords() throws IOException {
    // Given
    String storyPath = storyPath(MyStory.class);
    Keywords keywords = new LocalizedKeywords(new Locale("it"));
    final OutputStream out = new ByteArrayOutputStream();
    StoryReporterBuilder builder = new StoryReporterBuilder() {

        @Override
        protected FilePrintStreamFactory filePrintStreamFactory(String storyPath) {
            return new FilePrintStreamFactory(new StoryLocation(codeLocation(), storyPath)) {

                @Override
                public PrintStream createPrintStream() {
                    return new PrintStream(out);
                }
            };
        }
    };
    // When
    StoryReporter reporter = builder.withDefaultFormats().withFormats(TXT).withKeywords(keywords).build(storyPath);
    reporter.failed("Dato un passo che fallisce", new UUIDExceptionWrapper(new RuntimeException("ouch")));
    ((ConcurrentStoryReporter) reporter).invokeDelayed();
    // Then
    assertThat(builder.keywords(), equalTo(keywords));
    assertThat(out.toString(), equalTo("Dato un passo che fallisce (FALLITO)\n(java.lang.RuntimeException: ouch)\n"));
}
Also used : Locale(java.util.Locale) PrintStream(java.io.PrintStream) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoryLocation(org.jbehave.core.io.StoryLocation) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Aggregations

StoryLocation (org.jbehave.core.io.StoryLocation)7 Test (org.junit.Test)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 FileConfiguration (org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration)4 URL (java.net.URL)3 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)3 File (java.io.File)2 Properties (java.util.Properties)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Locale (java.util.Locale)1 Keywords (org.jbehave.core.configuration.Keywords)1 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)1