public abstract class PrintStreamOutput extends NullStoryReporter
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"));
Modifier and Type | Class and Description |
---|---|
static class |
PrintStreamOutput.Format |
Modifier | Constructor and Description |
---|---|
protected |
PrintStreamOutput(PrintStreamOutput.Format format,
PrintStream output,
Properties outputPatterns,
Keywords keywords,
boolean reportFailureTrace,
boolean compressFailureTrace) |
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) |
Modifier and Type | Method and Description |
---|---|
void |
afterExamples() |
void |
afterGivenStories() |
void |
afterScenario() |
void |
afterStory(boolean givenOrRestartingStory) |
void |
afterStorySteps(StepCollector.Stage stage) |
void |
beforeExamples(List<String> steps,
ExamplesTable table) |
void |
beforeGivenStories() |
void |
beforeScenario(Scenario scenario) |
void |
beforeStep(String step) |
void |
beforeStory(Story story,
boolean givenStory) |
void |
beforeStorySteps(StepCollector.Stage stage) |
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 format
|
void |
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(GivenStories givenStories) |
void |
givenStories(List<String> storyPaths) |
void |
ignorable(String step) |
void |
lifecyle(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(String step) |
void |
pendingMethods(List<String> methods) |
protected void |
print(PrintStream output,
String text) |
protected void |
print(String text)
Prints text to output stream, replacing parameter start and end
placeholders
|
boolean |
reportFailureTrace() |
void |
restarted(String step,
Throwable cause) |
void |
restartedStory(Story story,
Throwable cause) |
void |
scenarioNotAllowed(Scenario scenario,
String filter) |
void |
storyCancelled(Story story,
StoryDuration storyDuration) |
void |
storyNotAllowed(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) |
afterScenarioSteps, beforeScenario, beforeScenarioSteps, example, scenarioMeta
public static final String NL
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)
public void beforeStep(String step)
beforeStep
in interface StoryReporter
beforeStep
in class NullStoryReporter
public void successful(String step)
successful
in interface StoryReporter
successful
in class NullStoryReporter
public void ignorable(String step)
ignorable
in interface StoryReporter
ignorable
in class NullStoryReporter
public void comment(String step)
comment
in interface StoryReporter
comment
in class NullStoryReporter
public void pending(String step)
pending
in interface StoryReporter
pending
in class NullStoryReporter
public void notPerformed(String step)
notPerformed
in interface StoryReporter
notPerformed
in class NullStoryReporter
public void failed(String step, Throwable storyFailure)
failed
in interface StoryReporter
failed
in class NullStoryReporter
public void failedOutcomes(String step, OutcomesTable table)
failedOutcomes
in interface StoryReporter
failedOutcomes
in class NullStoryReporter
public void storyNotAllowed(Story story, String filter)
storyNotAllowed
in interface StoryReporter
storyNotAllowed
in class NullStoryReporter
public void storyCancelled(Story story, StoryDuration storyDuration)
storyCancelled
in interface StoryReporter
storyCancelled
in class NullStoryReporter
public void beforeStory(Story story, boolean givenStory)
beforeStory
in interface StoryReporter
beforeStory
in class NullStoryReporter
public void narrative(Narrative narrative)
narrative
in interface StoryReporter
narrative
in class NullStoryReporter
public void lifecyle(Lifecycle lifecycle)
lifecyle
in interface StoryReporter
lifecyle
in class NullStoryReporter
public void beforeStorySteps(StepCollector.Stage stage)
beforeStorySteps
in interface StoryReporter
beforeStorySteps
in class NullStoryReporter
public void afterStorySteps(StepCollector.Stage stage)
afterStorySteps
in interface StoryReporter
afterStorySteps
in class NullStoryReporter
public void afterStory(boolean givenOrRestartingStory)
afterStory
in interface StoryReporter
afterStory
in class NullStoryReporter
public void beforeGivenStories()
beforeGivenStories
in interface StoryReporter
beforeGivenStories
in class NullStoryReporter
public void givenStories(GivenStories givenStories)
givenStories
in interface StoryReporter
givenStories
in class NullStoryReporter
public void givenStories(List<String> storyPaths)
givenStories
in interface StoryReporter
givenStories
in class NullStoryReporter
public void afterGivenStories()
afterGivenStories
in interface StoryReporter
afterGivenStories
in class NullStoryReporter
public void scenarioNotAllowed(Scenario scenario, String filter)
scenarioNotAllowed
in interface StoryReporter
scenarioNotAllowed
in class NullStoryReporter
public void beforeScenario(Scenario scenario)
beforeScenario
in interface StoryReporter
beforeScenario
in class NullStoryReporter
public void afterScenario()
afterScenario
in interface StoryReporter
afterScenario
in class NullStoryReporter
public void beforeExamples(List<String> steps, ExamplesTable table)
beforeExamples
in interface StoryReporter
beforeExamples
in class NullStoryReporter
public void example(Map<String,String> tableRow, int exampleIndex)
example
in interface StoryReporter
example
in class NullStoryReporter
public void afterExamples()
afterExamples
in interface StoryReporter
afterExamples
in class NullStoryReporter
public void dryRun()
dryRun
in interface StoryReporter
dryRun
in class NullStoryReporter
public void pendingMethods(List<String> methods)
pendingMethods
in interface StoryReporter
pendingMethods
in class NullStoryReporter
public void restarted(String step, Throwable cause)
restarted
in interface StoryReporter
restarted
in class NullStoryReporter
public void restartedStory(Story story, Throwable cause)
restartedStory
in interface StoryReporter
restartedStory
in class NullStoryReporter
protected String format(String key, String defaultPattern, Object... args)
key
- the event keydefaultPattern
- the default pattern to return if a custom pattern
is not foundargs
- the args used to format outputprotected String formatTable(ExamplesTable table)
protected Object[] escape(PrintStreamOutput.Format format, Object... args)
format
- the Format used by the PrintStreamargs
- the array of args to escapeprotected String lookupPattern(String key, String defaultPattern)
MessageFormat.format(String, Object...)
method. If no
pattern is found for key or needs to be overridden, the default pattern
should be returned.key
- the format pattern keydefaultPattern
- the default pattern if no pattern ispublic boolean reportFailureTrace()
public PrintStreamOutput doReportFailureTrace(boolean reportFailureTrace)
public boolean compressFailureTrace()
public PrintStreamOutput doCompressFailureTrace(boolean compressFailureTrace)
protected void print(String text)
text
- the String to printprotected String transformPrintingTable(String text, String tableStart, String tableEnd)
protected String transformPrintingVerbatim(String text, String verbatimStart, String verbatimEnd)
protected void print(PrintStream output, String text)
Copyright © 2003–2021. All rights reserved.