org.jbehave.core.reporters
Class PrintStreamOutput

java.lang.Object
  extended by org.jbehave.core.reporters.PrintStreamOutput
All Implemented Interfaces:
StoryReporter
Direct Known Subclasses:
HtmlOutput, TxtOutput, XmlOutput

public abstract class PrintStreamOutput
extends java.lang.Object
implements StoryReporter

Abstract story reporter that outputs to a PrintStream.

The output of the reported event is configurable via:

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(String key, String defaultPattern, Object... args) and lookupPattern(String key, String defaultPattern) methods are override-able 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 LocalizedKeywords using the appropriate Locale, e.g.

 Keywords keywords = new LocalizedKeywords(new Locale("it"));
 


Nested Class Summary
static class PrintStreamOutput.Format
           
 
Constructor Summary
protected PrintStreamOutput(PrintStreamOutput.Format format, java.io.PrintStream output, java.util.Properties outputPatterns, Keywords keywords, boolean reportFailureTrace)
           
 
Method Summary
 void afterExamples()
           
 void afterScenario()
           
 void afterStory(boolean givenStory)
           
 void beforeExamples(java.util.List<java.lang.String> steps, ExamplesTable table)
           
 void beforeScenario(java.lang.String title)
           
 void beforeStory(Story story, boolean givenStory)
           
 PrintStreamOutput doReportFailureTrace(boolean reportFailureTrace)
           
 void dryRun()
           
protected  java.lang.Object[] escape(PrintStreamOutput.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 failed(java.lang.String step, java.lang.Throwable cause)
           
 void failedOutcomes(java.lang.String step, OutcomesTable table)
           
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 givenStories(java.util.List<java.lang.String> storyPaths)
           
 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)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrintStreamOutput

protected PrintStreamOutput(PrintStreamOutput.Format format,
                            java.io.PrintStream output,
                            java.util.Properties outputPatterns,
                            Keywords keywords,
                            boolean reportFailureTrace)
Method Detail

successful

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

ignorable

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

pending

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

notPerformed

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

failed

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

failedOutcomes

public void failedOutcomes(java.lang.String step,
                           OutcomesTable table)
Specified by:
failedOutcomes in interface StoryReporter

beforeStory

public void beforeStory(Story story,
                        boolean givenStory)
Specified by:
beforeStory in interface StoryReporter

afterStory

public void afterStory(boolean givenStory)
Specified by:
afterStory in interface StoryReporter

givenStories

public void givenStories(java.util.List<java.lang.String> storyPaths)
Specified by:
givenStories in interface StoryReporter

beforeScenario

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

afterScenario

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

beforeExamples

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

example

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

afterExamples

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

dryRun

public void dryRun()
Specified by:
dryRun in interface StoryReporter

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(PrintStreamOutput.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(String, Object...) 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

doReportFailureTrace

public PrintStreamOutput doReportFailureTrace(boolean reportFailureTrace)

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2003-2010. All Rights Reserved.