org.jbehave.scenario.reporters
Class PrintStreamScenarioReporter

java.lang.Object
  extended by org.jbehave.scenario.reporters.PrintStreamScenarioReporter
All Implemented Interfaces:
ScenarioReporter
Direct Known Subclasses:
HtmlPrintStreamScenarioReporter, XmlPrintStreamScenarioReporter

public class PrintStreamScenarioReporter
extends java.lang.Object
implements ScenarioReporter

Scenario reporter that outputs to a PrintStream, defaulting to System.out.

The output of the reported event is also configurable via two other means:

Let's look at example of providing custom output patterns, e.g. for the failed event.
we'd need to provide the custom pattern, say we want to have something like "(step being executed) <<< FAILED", keyed on the method name:

 Properties patterns = new Properties();
 patterns.setProperty("failed", "{0} <<< {1}");
 
The pattern is by default processed and formatted by the MessageFormat. Both the #format() and #lookupPattern() methods are overrideable and a different formatter or pattern lookup can be used by subclasses.

If the keyword "FAILED" (or any other keyword used by the reporter) needs to be expressed in a different language, all we need to do is to provide an instance of I18nKeyWords using the appropriate Locale, e.g.

 KeyWords keywords = new I18nKeyWords(new Locale("it");
 


Nested Class Summary
static class PrintStreamScenarioReporter.Format
           
 
Field Summary
protected  java.io.PrintStream output
           
 
Constructor Summary
PrintStreamScenarioReporter()
           
PrintStreamScenarioReporter(KeyWords keywords)
           
PrintStreamScenarioReporter(java.io.PrintStream output)
           
PrintStreamScenarioReporter(java.io.PrintStream output, java.util.Properties outputPatterns, KeyWords keywords, boolean reportErrors)
           
PrintStreamScenarioReporter(java.io.PrintStream output, java.util.Properties outputPatterns, PrintStreamScenarioReporter.Format format, KeyWords keywords, boolean reportErrors)
           
PrintStreamScenarioReporter(java.util.Properties outputPatterns)
           
PrintStreamScenarioReporter(java.util.Properties outputPatterns, PrintStreamScenarioReporter.Format format)
           
 
Method Summary
 void afterExamples()
           
 void afterScenario()
           
 void afterStory()
           
 void afterStory(boolean embeddedStory)
           
 void beforeExamples(java.util.List<java.lang.String> steps, ExamplesTable table)
           
 void beforeScenario(java.lang.String title)
           
 void beforeStory(Blurb blurb)
           
 void beforeStory(StoryDefinition story, boolean embeddedStory)
           
protected  java.lang.Object[] escape(PrintStreamScenarioReporter.Format format, java.lang.Object... args)
          Escapes args' string values according to format
 void example(java.util.Map<java.lang.String,java.lang.String> tableRow)
           
 void examplesTable(ExamplesTable table)
           
 void examplesTableRow(java.util.Map<java.lang.String,java.lang.String> tableRow)
           
 void failed(java.lang.String step, java.lang.Throwable cause)
           
protected  java.lang.String format(java.lang.String key, java.lang.String defaultPattern, java.lang.Object... args)
          Formats event output by key, usually equal to the method name.
 void givenScenarios(java.util.List<java.lang.String> givenScenarios)
           
 void ignorable(java.lang.String step)
           
protected  java.lang.String lookupPattern(java.lang.String key, java.lang.String defaultPattern)
          Looks up the format pattern for the event output by key, conventionally equal to the method name.
 void notPerformed(java.lang.String step)
           
 void pending(java.lang.String step)
           
protected  void print(java.lang.String text)
          Prints text to output stream, replacing parameter start and end placeholders
 void successful(java.lang.String step)
           
protected  void usePrintStream(java.io.PrintStream output)
          Changes print stream used for output
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

output

protected java.io.PrintStream output
Constructor Detail

PrintStreamScenarioReporter

public PrintStreamScenarioReporter()

PrintStreamScenarioReporter

public PrintStreamScenarioReporter(java.io.PrintStream output)

PrintStreamScenarioReporter

public PrintStreamScenarioReporter(java.util.Properties outputPatterns)

PrintStreamScenarioReporter

public PrintStreamScenarioReporter(java.util.Properties outputPatterns,
                                   PrintStreamScenarioReporter.Format format)

PrintStreamScenarioReporter

public PrintStreamScenarioReporter(KeyWords keywords)

PrintStreamScenarioReporter

public PrintStreamScenarioReporter(java.io.PrintStream output,
                                   java.util.Properties outputPatterns,
                                   KeyWords keywords,
                                   boolean reportErrors)

PrintStreamScenarioReporter

public PrintStreamScenarioReporter(java.io.PrintStream output,
                                   java.util.Properties outputPatterns,
                                   PrintStreamScenarioReporter.Format format,
                                   KeyWords keywords,
                                   boolean reportErrors)
Method Detail

successful

public void successful(java.lang.String step)
Specified by:
successful in interface ScenarioReporter

ignorable

public void ignorable(java.lang.String step)
Specified by:
ignorable in interface ScenarioReporter

pending

public void pending(java.lang.String step)
Specified by:
pending in interface ScenarioReporter

notPerformed

public void notPerformed(java.lang.String step)
Specified by:
notPerformed in interface ScenarioReporter

failed

public void failed(java.lang.String step,
                   java.lang.Throwable cause)
Specified by:
failed in interface ScenarioReporter

beforeStory

public void beforeStory(StoryDefinition story,
                        boolean embeddedStory)
Specified by:
beforeStory in interface ScenarioReporter

beforeStory

public void beforeStory(Blurb blurb)
Specified by:
beforeStory in interface ScenarioReporter

afterStory

public void afterStory(boolean embeddedStory)
Specified by:
afterStory in interface ScenarioReporter

afterStory

public void afterStory()
Specified by:
afterStory in interface ScenarioReporter

givenScenarios

public void givenScenarios(java.util.List<java.lang.String> givenScenarios)
Specified by:
givenScenarios in interface ScenarioReporter

beforeScenario

public void beforeScenario(java.lang.String title)
Specified by:
beforeScenario in interface ScenarioReporter

afterScenario

public void afterScenario()
Specified by:
afterScenario in interface ScenarioReporter

beforeExamples

public void beforeExamples(java.util.List<java.lang.String> steps,
                           ExamplesTable table)
Specified by:
beforeExamples in interface ScenarioReporter

example

public void example(java.util.Map<java.lang.String,java.lang.String> tableRow)
Specified by:
example in interface ScenarioReporter

afterExamples

public void afterExamples()
Specified by:
afterExamples in interface ScenarioReporter

examplesTable

public void examplesTable(ExamplesTable table)
Specified by:
examplesTable in interface ScenarioReporter

examplesTableRow

public void examplesTableRow(java.util.Map<java.lang.String,java.lang.String> tableRow)
Specified by:
examplesTableRow in interface ScenarioReporter

format

protected java.lang.String format(java.lang.String key,
                                  java.lang.String defaultPattern,
                                  java.lang.Object... args)
Formats event output by key, usually equal to the method name.

Parameters:
key - the event key
defaultPattern - the default pattern to return if a custom pattern is not found
args - the args used to format output
Returns:
A formatted event output

escape

protected java.lang.Object[] escape(PrintStreamScenarioReporter.Format format,
                                    java.lang.Object... args)
Escapes args' string values according to format

Parameters:
format - the Format used by the PrintStream
args - the array of args to escape
Returns:
The cloned and escaped array of args

lookupPattern

protected java.lang.String lookupPattern(java.lang.String key,
                                         java.lang.String defaultPattern)
Looks up the format pattern for the event output by key, conventionally equal to the method name. The pattern is used by the {#format(String,String,Object...)} method and by default is formatted using the MessageFormat#format() method. If no pattern is found for key or needs to be overridden, the default pattern should be returned.

Parameters:
key - the format pattern key
defaultPattern - the default pattern if no pattern is
Returns:
The format patter for the given key

usePrintStream

protected void usePrintStream(java.io.PrintStream output)
Changes print stream used for output

Parameters:
output - the new PrintStream to use

print

protected void print(java.lang.String text)
Prints text to output stream, replacing parameter start and end placeholders

Parameters:
text - the String to print


Copyright © 2003-2010. All Rights Reserved.