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);
}
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));
}
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));
}
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));
}
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);
}
Aggregations