Package org.jbehave.core.reporters
Class PrintStreamOutput
- java.lang.Object
-
- org.jbehave.core.reporters.NullStoryReporter
-
- org.jbehave.core.reporters.PrintStreamOutput
-
- All Implemented Interfaces:
StoryReporter
- Direct Known Subclasses:
HtmlOutput
,JsonOutput
,TxtOutput
,XmlOutput
public abstract class PrintStreamOutput extends NullStoryReporter
Abstract story reporter that outputs to a PrintStream.
The output of the reported event is configurable via:
- custom output patterns, providing only the patterns that differ from default
- keywords localised for different languages, providing the formatOutcome Locale
- flag to report failure trace
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 theMessageFormat
. Both theformat(String key, String defaultPattern, Object... args)
andlookupPattern(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 appropriateLocale
, e.g.Keywords keywords = new LocalizedKeywords(new Locale("it"));
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PrintStreamOutput.Format
-
Constructor Summary
Constructors Modifier Constructor Description protected
PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords)
protected
PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)
protected
PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)
-
Method Summary
Modifier and Type Method Description void
afterComposedSteps()
void
afterExamples()
void
afterGivenStories()
void
afterScenario(Timing timing)
void
afterScenarios()
void
afterScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
void
afterStoriesSteps(StepCollector.Stage stage)
void
afterStory(boolean givenOrRestartingStory)
void
afterStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
void
beforeComposedSteps()
void
beforeExamples(List<String> steps, ExamplesTable table)
void
beforeGivenStories()
void
beforeScenario(Scenario scenario)
void
beforeScenarios()
void
beforeScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
void
beforeStep(Step step)
void
beforeStoriesSteps(StepCollector.Stage stage)
void
beforeStory(Story story, boolean givenStory)
void
beforeStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
void
comment(String step)
boolean
compressFailureTrace()
PrintStreamOutput
doCompressFailureTrace(boolean compressFailureTrace)
PrintStreamOutput
doReportFailureTrace(boolean reportFailureTrace)
void
dryRun()
protected Object[]
escape(PrintStreamOutput.Format format, Object... args)
Escapes args' string values according to formatvoid
example(Map<String,String> tableRow, int exampleIndex)
void
failed(String step, Throwable storyFailure)
void
failedOutcomes(String step, OutcomesTable table)
protected String
format(String key, String defaultPattern, Object... args)
Formats event output by key, usually equal to the method name.protected String
formatTable(ExamplesTable table)
protected String
formatVerbatim(Verbatim verbatim)
void
givenStories(List<String> storyPaths)
void
givenStories(GivenStories givenStories)
void
ignorable(String step)
void
lifecycle(Lifecycle lifecycle)
protected String
lookupPattern(String key, String defaultPattern)
Looks up the format pattern for the event output by key, conventionally equal to the method name.void
narrative(Narrative narrative)
void
notPerformed(String step)
protected void
overwritePattern(String key, String pattern)
void
pending(StepCreator.PendingStep step)
protected void
print(PrintStream output, String text)
protected void
print(String text)
Prints text to output stream, replacing parameter start and end placeholdersboolean
reportFailureTrace()
void
restarted(String step, Throwable cause)
void
restartedStory(Story story, Throwable cause)
void
scenarioExcluded(Scenario scenario, String filter)
void
storyCancelled(Story story, StoryDuration storyDuration)
void
storyExcluded(Story story, String filter)
void
successful(String step)
String
toString()
protected String
transformPrintingTable(String text, String tableStart, String tableEnd)
protected String
transformPrintingVerbatim(String text, String verbatimStart, String verbatimEnd)
-
Methods inherited from class org.jbehave.core.reporters.NullStoryReporter
pending, pendingMethods
-
-
-
-
Field Detail
-
NL
public static final String NL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PrintStreamOutput
protected PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords)
-
PrintStreamOutput
protected PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)
-
PrintStreamOutput
protected PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)
-
-
Method Detail
-
beforeStep
public void beforeStep(Step step)
- Specified by:
beforeStep
in interfaceStoryReporter
- Overrides:
beforeStep
in classNullStoryReporter
-
successful
public void successful(String step)
- Specified by:
successful
in interfaceStoryReporter
- Overrides:
successful
in classNullStoryReporter
-
ignorable
public void ignorable(String step)
- Specified by:
ignorable
in interfaceStoryReporter
- Overrides:
ignorable
in classNullStoryReporter
-
comment
public void comment(String step)
- Specified by:
comment
in interfaceStoryReporter
- Overrides:
comment
in classNullStoryReporter
-
pending
public void pending(StepCreator.PendingStep step)
- Specified by:
pending
in interfaceStoryReporter
- Overrides:
pending
in classNullStoryReporter
-
notPerformed
public void notPerformed(String step)
- Specified by:
notPerformed
in interfaceStoryReporter
- Overrides:
notPerformed
in classNullStoryReporter
-
failed
public void failed(String step, Throwable storyFailure)
- Specified by:
failed
in interfaceStoryReporter
- Overrides:
failed
in classNullStoryReporter
-
failedOutcomes
public void failedOutcomes(String step, OutcomesTable table)
- Specified by:
failedOutcomes
in interfaceStoryReporter
- Overrides:
failedOutcomes
in classNullStoryReporter
-
storyExcluded
public void storyExcluded(Story story, String filter)
- Specified by:
storyExcluded
in interfaceStoryReporter
- Overrides:
storyExcluded
in classNullStoryReporter
-
storyCancelled
public void storyCancelled(Story story, StoryDuration storyDuration)
- Specified by:
storyCancelled
in interfaceStoryReporter
- Overrides:
storyCancelled
in classNullStoryReporter
-
beforeStory
public void beforeStory(Story story, boolean givenStory)
- Specified by:
beforeStory
in interfaceStoryReporter
- Overrides:
beforeStory
in classNullStoryReporter
-
beforeScenarios
public void beforeScenarios()
- Specified by:
beforeScenarios
in interfaceStoryReporter
- Overrides:
beforeScenarios
in classNullStoryReporter
-
afterScenarios
public void afterScenarios()
- Specified by:
afterScenarios
in interfaceStoryReporter
- Overrides:
afterScenarios
in classNullStoryReporter
-
narrative
public void narrative(Narrative narrative)
- Specified by:
narrative
in interfaceStoryReporter
- Overrides:
narrative
in classNullStoryReporter
-
lifecycle
public void lifecycle(Lifecycle lifecycle)
- Specified by:
lifecycle
in interfaceStoryReporter
- Overrides:
lifecycle
in classNullStoryReporter
-
beforeScenarioSteps
public void beforeScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
beforeScenarioSteps
in interfaceStoryReporter
- Overrides:
beforeScenarioSteps
in classNullStoryReporter
-
afterScenarioSteps
public void afterScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
afterScenarioSteps
in interfaceStoryReporter
- Overrides:
afterScenarioSteps
in classNullStoryReporter
-
beforeComposedSteps
public void beforeComposedSteps()
- Specified by:
beforeComposedSteps
in interfaceStoryReporter
- Overrides:
beforeComposedSteps
in classNullStoryReporter
-
afterComposedSteps
public void afterComposedSteps()
- Specified by:
afterComposedSteps
in interfaceStoryReporter
- Overrides:
afterComposedSteps
in classNullStoryReporter
-
beforeStoriesSteps
public void beforeStoriesSteps(StepCollector.Stage stage)
- Specified by:
beforeStoriesSteps
in interfaceStoryReporter
- Overrides:
beforeStoriesSteps
in classNullStoryReporter
-
afterStoriesSteps
public void afterStoriesSteps(StepCollector.Stage stage)
- Specified by:
afterStoriesSteps
in interfaceStoryReporter
- Overrides:
afterStoriesSteps
in classNullStoryReporter
-
beforeStorySteps
public void beforeStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
beforeStorySteps
in interfaceStoryReporter
- Overrides:
beforeStorySteps
in classNullStoryReporter
-
afterStorySteps
public void afterStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
afterStorySteps
in interfaceStoryReporter
- Overrides:
afterStorySteps
in classNullStoryReporter
-
afterStory
public void afterStory(boolean givenOrRestartingStory)
- Specified by:
afterStory
in interfaceStoryReporter
- Overrides:
afterStory
in classNullStoryReporter
-
beforeGivenStories
public void beforeGivenStories()
- Specified by:
beforeGivenStories
in interfaceStoryReporter
- Overrides:
beforeGivenStories
in classNullStoryReporter
-
givenStories
public void givenStories(GivenStories givenStories)
- Specified by:
givenStories
in interfaceStoryReporter
- Overrides:
givenStories
in classNullStoryReporter
-
givenStories
public void givenStories(List<String> storyPaths)
- Specified by:
givenStories
in interfaceStoryReporter
- Overrides:
givenStories
in classNullStoryReporter
-
afterGivenStories
public void afterGivenStories()
- Specified by:
afterGivenStories
in interfaceStoryReporter
- Overrides:
afterGivenStories
in classNullStoryReporter
-
scenarioExcluded
public void scenarioExcluded(Scenario scenario, String filter)
- Specified by:
scenarioExcluded
in interfaceStoryReporter
- Overrides:
scenarioExcluded
in classNullStoryReporter
-
beforeScenario
public void beforeScenario(Scenario scenario)
- Specified by:
beforeScenario
in interfaceStoryReporter
- Overrides:
beforeScenario
in classNullStoryReporter
-
afterScenario
public void afterScenario(Timing timing)
- Specified by:
afterScenario
in interfaceStoryReporter
- Overrides:
afterScenario
in classNullStoryReporter
-
beforeExamples
public void beforeExamples(List<String> steps, ExamplesTable table)
- Specified by:
beforeExamples
in interfaceStoryReporter
- Overrides:
beforeExamples
in classNullStoryReporter
-
example
public void example(Map<String,String> tableRow, int exampleIndex)
- Specified by:
example
in interfaceStoryReporter
- Overrides:
example
in classNullStoryReporter
-
afterExamples
public void afterExamples()
- Specified by:
afterExamples
in interfaceStoryReporter
- Overrides:
afterExamples
in classNullStoryReporter
-
dryRun
public void dryRun()
- Specified by:
dryRun
in interfaceStoryReporter
- Overrides:
dryRun
in classNullStoryReporter
-
restarted
public void restarted(String step, Throwable cause)
- Specified by:
restarted
in interfaceStoryReporter
- Overrides:
restarted
in classNullStoryReporter
-
restartedStory
public void restartedStory(Story story, Throwable cause)
- Specified by:
restartedStory
in interfaceStoryReporter
- Overrides:
restartedStory
in classNullStoryReporter
-
format
protected String format(String key, String defaultPattern, Object... args)
Formats event output by key, usually equal to the method name.- Parameters:
key
- the event keydefaultPattern
- the default pattern to return if a custom pattern is not foundargs
- the args used to format output- Returns:
- A formatted event output
-
formatTable
protected String formatTable(ExamplesTable table)
-
escape
protected Object[] escape(PrintStreamOutput.Format format, Object... args)
Escapes args' string values according to format- Parameters:
format
- the Format used by the PrintStreamargs
- the array of args to escape- Returns:
- The cloned and escaped array of args
-
lookupPattern
protected String lookupPattern(String key, 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 theMessageFormat.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 keydefaultPattern
- the default pattern if no pattern is- Returns:
- The format patter for the given key
-
reportFailureTrace
public boolean reportFailureTrace()
-
doReportFailureTrace
public PrintStreamOutput doReportFailureTrace(boolean reportFailureTrace)
-
compressFailureTrace
public boolean compressFailureTrace()
-
doCompressFailureTrace
public PrintStreamOutput doCompressFailureTrace(boolean compressFailureTrace)
-
print
protected void print(String text)
Prints text to output stream, replacing parameter start and end placeholders- Parameters:
text
- the String to print
-
print
protected void print(PrintStream output, String text)
-
transformPrintingTable
protected String transformPrintingTable(String text, String tableStart, String tableEnd)
-
transformPrintingVerbatim
protected String transformPrintingVerbatim(String text, String verbatimStart, String verbatimEnd)
-
-