- Revision
- 1233
- Author
- mauro
- Date
- 2009-09-07 17:26:12 -0500 (Mon, 07 Sep 2009)
Log Message
JBEHAVE-178: Allow output format message patterns to be overridden in PrintStreamScenarioReporter
Modified Paths
Diff
Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java (1232 => 1233)
--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java 2009-09-07 21:43:09 UTC (rev 1232) +++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java 2009-09-07 22:26:12 UTC (rev 1233) @@ -1,6 +1,7 @@ package org.jbehave.scenario.reporters; import java.io.PrintStream; +import java.text.MessageFormat; import java.util.List; import java.util.Map; @@ -32,20 +33,20 @@ } public void successful(String step) { - output.println(step); + output.println(format("successful", "{0}", step)); } public void pending(String step) { - output.println(step + " (PENDING)"); + output.println(format("pending", "{0} (PENDING)", step)); } public void notPerformed(String step) { - output.println(step + " (NOT PERFORMED)"); + output.println(format("notPerformed", "{0} (NOT PERFORMED)", step)); } public void failed(String step, Throwable cause) { this.cause = cause; - output.println(step + " (FAILED)"); + output.println(format("failed", "{0} (FAILED)", step)); } public void afterScenario() { @@ -58,33 +59,45 @@ public void beforeScenario(String title) { cause = null; - output.println("Scenario: " + title); - output.println(); + output.println(format("beforeScenario", "Scenario: {0}\n", title)); } public void afterStory() { - + output.println(format("afterStory", "" )); } public void beforeStory(Blurb blurb) { - output.println(blurb.asString()); - output.println(); + output.println(format("beforeStory", "{0}", blurb.asString())); } public void givenScenarios(List<String> givenScenarios) { - output.println("GivenScenarios: " + givenScenarios); + output.println(format("givenScenarios", "GivenScenarios: {0}\n", + givenScenarios)); } public void usingExamplesTable(ExamplesTable table) { - output.println("Using examples table:"); - output.println(); - output.println(table); - output.println(); + output.println(format("usingExamplesTable", + "Using examples table:\n\n{0}\n\n", table)); } public void usingTableRow(Map<String, String> tableRow) { - output.println("Using table row: " + tableRow); - output.println(); + output.println(format("usingTableRow", "Using table row: {0}\n", tableRow)); } + protected String format(String key, String defaultPattern, Object... args) { + return MessageFormat.format(patternFor(key, defaultPattern), args); + } + + /** + * Provide format patterns for the output by key, conventionally equal to the method name. + * If no pattern is found for key or needs to be overridden, the default pattern should be returned. + * + * @param key the format pattern key + * @param defaultPattern the default pattern if no pattern is + * @return The format patter for the given key + */ + protected String patternFor(String key, String defaultPattern) { + return defaultPattern; + } + }
To unsubscribe from this list please visit:
