Search in sources :

Example 11 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class PrintStreamOutputBehaviour method shouldBuildPrintStreamReportersAndOverrideDefaultForAGivenFormat.

@Test
public void shouldBuildPrintStreamReportersAndOverrideDefaultForAGivenFormat() throws IOException {
    final String storyPath = storyPath(MyStory.class);
    final FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(CodeLocations.codeLocationFromClass(this.getClass()), storyPath));
    StoryReporter reporter = new StoryReporterBuilder() {

        @Override
        public StoryReporter reporterFor(String storyPath, org.jbehave.core.reporters.Format format) {
            if (format == org.jbehave.core.reporters.Format.TXT) {
                factory.useConfiguration(new FilePrintStreamFactory.FileConfiguration("text"));
                return new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
            } else {
                return super.reporterFor(storyPath, format);
            }
        }
    }.withFormats(TXT).build(storyPath);
    // When
    StoryNarrator.narrateAnInterestingStory(reporter, false);
    ((ConcurrentStoryReporter) reporter).invokeDelayed();
    // Then
    File outputFile = factory.getOutputFile();
    ensureFileExists(outputFile);
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class StoryReporterBuilderBehaviour method shouldBuildWithCustomReporterForAGivenFormat.

@Test
public void shouldBuildWithCustomReporterForAGivenFormat() throws IOException {
    // Given
    String storyPath = storyPath(MyStory.class);
    final FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(CodeLocations.codeLocationFromClass(MyStory.class), storyPath));
    final StoryReporter txtReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    StoryReporterBuilder builder = new StoryReporterBuilder() {

        @Override
        public StoryReporter reporterFor(String storyPath, org.jbehave.core.reporters.Format format) {
            if (format == org.jbehave.core.reporters.Format.TXT) {
                factory.useConfiguration(new FilePrintStreamFactory.FileConfiguration("text"));
                return txtReporter;
            } else {
                return super.reporterFor(storyPath, format);
            }
        }
    };
    // When
    StoryReporter reporter = builder.withDefaultFormats().withFormats(TXT).build(storyPath);
    // Then
    assertThat(reporter, instanceOf(ConcurrentStoryReporter.class));
    StoryReporter delegate = ((ConcurrentStoryReporter) reporter).getDelegate();
    assertThat(delegate, instanceOf(DelegatingStoryReporter.class));
    Collection<StoryReporter> delegates = ((DelegatingStoryReporter) delegate).getDelegates();
    assertThat(delegates.size(), equalTo(2));
    assertThat(delegates.contains(txtReporter), is(true));
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) StoryLocation(org.jbehave.core.io.StoryLocation) Test(org.junit.Test)

Example 13 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class StoryReporterBuilderBehaviour method shouldBuildWithCustomReportersAsProvidedFormat.

@Test
public void shouldBuildWithCustomReportersAsProvidedFormat() throws IOException {
    // Given
    String storyPath = storyPath(MyStory.class);
    FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(CodeLocations.codeLocationFromClass(MyStory.class), storyPath));
    StoryReporter txtReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    StoryReporter htmlReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    StoryReporterBuilder builder = new StoryReporterBuilder();
    // When
    StoryReporter reporter = builder.withReporters(txtReporter, htmlReporter).build(storyPath);
    // Then
    assertThat(reporter, instanceOf(ConcurrentStoryReporter.class));
    StoryReporter delegate = ((ConcurrentStoryReporter) reporter).getDelegate();
    assertThat(delegate, instanceOf(DelegatingStoryReporter.class));
    Collection<StoryReporter> delegates = ((DelegatingStoryReporter) delegate).getDelegates();
    assertThat(delegates.size(), equalTo(2));
    assertThat(delegates.contains(txtReporter), is(true));
    assertThat(delegates.contains(htmlReporter), is(true));
}
Also used : StoryLocation(org.jbehave.core.io.StoryLocation) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class StepsBehaviour method shouldAllowLocalizationOfSteps.

@Test
public void shouldAllowLocalizationOfSteps() {
    Configuration configuration = new MostUsefulConfiguration();
    configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
    LocalizedSteps steps = new LocalizedSteps(configuration);
    List<StepCandidate> candidates = steps.listCandidates();
    assertThat(candidates.size(), equalTo(3));
    findCandidate(candidates, "GIVEN un dato che").createMatchedStep("Dato che un dato che", tableRow).perform(null);
    findCandidate(candidates, "WHEN un quando").createMatchedStep("Quando un quando", tableRow).perform(null);
    findCandidate(candidates, "THEN un allora").createMatchedStep("Allora un allora", tableRow).perform(null);
    assertThat(steps.givens, equalTo(1));
    assertThat(steps.whens, equalTo(1));
    assertThat(steps.thens, equalTo(1));
}
Also used : Locale(java.util.Locale) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Test(org.junit.Test)

Example 15 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class TemplateOutputBehaviour method shouldOutputStoryToHtml.

@Test
public void shouldOutputStoryToHtml() throws IOException {
    // Given
    String name = "template-story.html";
    File file = newFile("target/" + name);
    StoryReporter reporter = new HtmlTemplateOutput(file, new LocalizedKeywords());
    // When
    StoryNarrator.narrateAnInterestingStory(reporter, true);
    // Then
    assertFileOutputIsSameAs(file, name);
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Test(org.junit.Test)

Aggregations

LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)35 Test (org.junit.Test)23 Properties (java.util.Properties)14 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)10 Locale (java.util.Locale)8 Keywords (org.jbehave.core.configuration.Keywords)8 SimpleDateFormat (java.text.SimpleDateFormat)7 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)7 TableTransformers (org.jbehave.core.model.TableTransformers)7 Configuration (org.jbehave.core.configuration.Configuration)6 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)6 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)6 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)5 LoadFromURL (org.jbehave.core.io.LoadFromURL)5 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)5 ParameterConverters (org.jbehave.core.steps.ParameterConverters)5 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)4 ArrayList (java.util.ArrayList)3 StoryLocation (org.jbehave.core.io.StoryLocation)3 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)3