org.jbehave.core.reporters
Class StoryReporterBuilder
java.lang.Object
org.jbehave.core.reporters.StoryReporterBuilder
public class StoryReporterBuilder
- extends Object
A Builder for
StoryReporter
s. It builds a DelegatingStoryReporter
with delegates for a number of formats - mostly file-based ones except
. It requires a
FilePrintStreamFactory
and provides default delegate instances for
each format.
To build reporter with default delegates for given formats:
Class<MyStory> storyClass = MyStory.class;
StoryPathResolver resolver = new UnderscoredCamelCaseResolver();
String storyPath = resolver.resolve(storyClass);
FilePrintStreamFactory printStreamFactory = new FilePrintStreamFactory(storyPath);
StoryReporter reporter = new StoryReporterBuilder(printStreamFactory).with(HTML).with(TXT).build();
The builder is configured to build with the StoryReporterBuilder.Format.STATS
format by default. To change the default formats
the user can override the method:
new StoryReporterBuilder(printStreamFactory){
protected void withDefaultFormats() {
with(Format.STATS);
}
}
The builder configures the file-based reporters to output to the default file directory FilePrintStreamFactory.FileConfiguration.DIRECTORY
.
To change the default:
new StoryReporterBuilder(printStreamFactory).outputTo("my-reports").with(HTML).with(TXT).build();
The builder provides default instances for all reporters. To change the reporter for a specific instance,
e.g. to report format TXT to .text files and to inject other non-default parameters,
such as keywords for a different locale:
new StoryReporterBuilder(printStreamFactory){
public StoryReporter reporterFor(Format format){
switch (format) {
case TXT:
factory.useConfiguration(new FileConfiguration("text"));
return new PrintStreamStoryReporter(factory.createPrintStream(), new Properties(), new I18nKeywords(Locale), true);
default:
return super.reporterFor(format);
}
}
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
factory
protected final FilePrintStreamFactory factory
delegates
protected Map<StoryReporterBuilder.Format,StoryReporter> delegates
StoryReporterBuilder
public StoryReporterBuilder(FilePrintStreamFactory factory)
withDefaultFormats
protected void withDefaultFormats()
build
public StoryReporter build()
outputTo
public StoryReporterBuilder outputTo(String fileDirectory)
with
public StoryReporterBuilder with(StoryReporterBuilder.Format format)
reporterFor
public StoryReporter reporterFor(StoryReporterBuilder.Format format)
getDelegates
public Map<StoryReporterBuilder.Format,StoryReporter> getDelegates()
fileConfiguration
protected FilePrintStreamFactory.FileConfiguration fileConfiguration(String extension)
Copyright © 2003-2010. All Rights Reserved.