org.jbehave.scenario.reporters
Class ScenarioReporterBuilder

java.lang.Object
  extended by org.jbehave.scenario.reporters.ScenarioReporterBuilder

public class ScenarioReporterBuilder
extends java.lang.Object

A Builder for ScenarioReporters. It builds a DelegatingScenarioReporter 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<MyScenario> scenarioClass = MyScenario.class;
 ScenarioNameResolver nameResolver = new UnderscoredCamelCaseResolver();
 FilePrintStreamFactory printStreamFactory = new FilePrintStreamFactory(scenarioClass, nameResolver);
 ScenarioReporter reporter = new ScenarioReporterBuilder(printStreamFactory).with(HTML).with(TXT).build();
 

The builder is configured to build with the ScenarioReporterBuilder.Format.STATS format by default. To change the default formats the user can override the method:

 new ScenarioReporterBuilder(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 ScenarioReporterBuilder(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 ScenarioReporterBuilder(printStreamFactory){
   public ScenarioReporter reporterFor(Format format){
       switch (format) {
           case TXT:
               factory.useConfiguration(new FileConfiguration("text"));
               return new PrintStreamScenarioReporter(factory.getPrintStream(), new Properties(), new I18nKeywords(Locale), true);
            default:
               return super.reporterFor(format);
   }
 }
 


Nested Class Summary
static class ScenarioReporterBuilder.Format
           
static class ScenarioReporterBuilder.UnsupportedReporterFormatException
           
 
Field Summary
protected  java.util.Map<ScenarioReporterBuilder.Format,ScenarioReporter> delegates
           
protected  FilePrintStreamFactory factory
           
 
Constructor Summary
ScenarioReporterBuilder(FilePrintStreamFactory factory)
           
 
Method Summary
 ScenarioReporter build()
           
protected  FilePrintStreamFactory.FileConfiguration fileConfiguration(java.lang.String extension)
           
 java.util.Map<ScenarioReporterBuilder.Format,ScenarioReporter> getDelegates()
           
 ScenarioReporterBuilder outputTo(java.lang.String fileDirectory)
           
 ScenarioReporter reporterFor(ScenarioReporterBuilder.Format format)
           
 ScenarioReporterBuilder with(ScenarioReporterBuilder.Format format)
           
protected  void withDefaultFormats()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

protected final FilePrintStreamFactory factory

delegates

protected java.util.Map<ScenarioReporterBuilder.Format,ScenarioReporter> delegates
Constructor Detail

ScenarioReporterBuilder

public ScenarioReporterBuilder(FilePrintStreamFactory factory)
Method Detail

withDefaultFormats

protected void withDefaultFormats()

build

public ScenarioReporter build()

outputTo

public ScenarioReporterBuilder outputTo(java.lang.String fileDirectory)

with

public ScenarioReporterBuilder with(ScenarioReporterBuilder.Format format)

reporterFor

public ScenarioReporter reporterFor(ScenarioReporterBuilder.Format format)

getDelegates

public java.util.Map<ScenarioReporterBuilder.Format,ScenarioReporter> getDelegates()

fileConfiguration

protected FilePrintStreamFactory.FileConfiguration fileConfiguration(java.lang.String extension)


Copyright © 2003-2010. All Rights Reserved.