Title: [1238] trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java: Better javadocs.
Revision
1238
Author
mauro
Date
2009-09-10 06:53:20 -0500 (Thu, 10 Sep 2009)

Log Message

Better javadocs.

Modified Paths


Diff

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java (1237 => 1238)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2009-09-10 11:13:20 UTC (rev 1237)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2009-09-10 11:53:20 UTC (rev 1238)
@@ -15,6 +15,38 @@
  * <p>
  * Scenario reporter that outputs to a PrintStream, defaulting to System.out.
  * </p>
+ * <p>
+ * The output of each reported event is (optionally) configurable via two means:
+ * <ul>
+ * <li>custom output patterns</li>
+ * <li>keywords in different languages</li>
+ * </ul>
+ * </p>
+ * <p>
+ * Let's look at example of providing custom output patterns, e.g. for the
+ * failed event. <br/>
+ * we'd need to provide the custom pattern, say we want to have something like
+ * "(step being executed) <<< FAILED", keyed on the method name:
+ * 
+ * <pre>
+ * Properties patterns = new Properties();
+ * patterns.setProperty(&quot;failed&quot;, &quot;{0} &lt;&lt;&lt; {1}&quot;);
+ * </pre>
+ * 
+ * The pattern is by default processed and formatted by the
+ * {...@link MessageFormat}.  Both the {...@link #format()} and {...@link #lookupPattern()} methods are overrideable
+ * and a different formatter or pattern lookup can be used by subclasses.
+ * </p>
+ * <p>
+ * 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 {...@link I18nKeyWords} using the appropriate {...@link Locale}, e.g.
+ * 
+ * <pre>
+ *   KeyWords keywords = new I18nKeyWords(new Locale(&quot;it&quot;);
+ * </pre>
+ * 
+ * </p>
  */
 public class PrintStreamScenarioReporter implements ScenarioReporter {
 
@@ -32,10 +64,11 @@
 		this(output, new Properties(), new I18nKeyWords(), false);
 	}
 
-	public PrintStreamScenarioReporter(PrintStream output, Properties outputPatterns, KeyWords keywords, boolean reportErrors) {
+	public PrintStreamScenarioReporter(PrintStream output,
+			Properties outputPatterns, KeyWords keywords, boolean reportErrors) {
 		this.output = output;
+		this.outputPatterns = outputPatterns;
 		this.keywords = keywords;
-		this.outputPatterns = outputPatterns;
 		this.reportErrors = reportErrors;
 	}
 
@@ -44,11 +77,13 @@
 	}
 
 	public void pending(String step) {
-		output.println(format("pending", "{0} ({1})", step, keywords.pending()));
+		output.println(format("pending", "{0} ({1})", step, keywords
+						.pending()));
 	}
 
 	public void notPerformed(String step) {
-		output.println(format("notPerformed", "{0} ({1})", step, keywords.notPerformed()));
+		output.println(format("notPerformed", "{0} ({1})", step, keywords
+				.notPerformed()));
 	}
 
 	public void failed(String step, Throwable cause) {
@@ -66,7 +101,8 @@
 
 	public void beforeScenario(String title) {
 		cause = null;
-		output.println(format("beforeScenario", "{0} {1}\n", keywords.scenario(), title));		
+		output.println(format("beforeScenario", "{0} {1}\n", keywords
+				.scenario(), title));
 	}
 
 	public void afterStory() {
@@ -78,43 +114,51 @@
 	}
 
 	public void givenScenarios(List<String> givenScenarios) {
-		output.println(format("givenScenarios", "{0} {1}\n",
-				keywords.givenScenarios(), givenScenarios));
+		output.println(format("givenScenarios", "{0} {1}\n", keywords
+				.givenScenarios(), givenScenarios));
 	}
 
 	public void examplesTable(ExamplesTable table) {
-		output.println(format("examplesTable",
-				"{0}\n\n{1}\n\n", keywords.examplesTable(), table));
+		output.println(format("examplesTable", "{0}\n\n{1}\n\n", keywords
+				.examplesTable(), table));
 	}
 
 	public void examplesTableRow(Map<String, String> tableRow) {
-		output.println(format("examplesTableRow", "{0} {1}\n", keywords.examplesTableRow(), tableRow));
+		output.println(format("examplesTableRow", "{0} {1}\n", keywords
+				.examplesTableRow(), tableRow));
 	}
 
 	/**
 	 * Formats event output by key, conventionally equal to the method name.
 	 * 
-	 * @param key the event key
-	 * @param defaultPattern the default pattern to return if a custom pattern is not found
-	 * @param args the args used to format output
+	 * @param key
+	 *            the event key
+	 * @param defaultPattern
+	 *            the default pattern to return if a custom pattern is not found
+	 * @param args
+	 *            the args used to format output
 	 * @return A formatted event output
 	 */
 	protected String format(String key, String defaultPattern, Object... args) {
-		return MessageFormat.format(patternFor(key, defaultPattern), args);
+		return MessageFormat.format(lookupPattern(key, defaultPattern), args);
 	}
 
 	/**
-	 * 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 {...@link MessageFormat#format()} method.
-	 * If no pattern is found for key or needs to be overridden, the default pattern should be returned. 
+	 * 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 {...@link MessageFormat#format()} method. 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 
+	 * @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) {
-		if ( outputPatterns.containsKey(key) ){
+	protected String lookupPattern(String key, String defaultPattern) {
+		if (outputPatterns.containsKey(key)) {
 			return outputPatterns.getProperty(key);
 		}
 		return defaultPattern;


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to