Title: [1469] trunk/core/distribution/src/site/content: JBEHAVE-215: Refactored trader example to show that the same Java Steps methods (with @Named parameters) can be used to match steps that are executed both as standalone or via examples table.
Revision
1469
Author
mauro
Date
2009-12-24 11:32:51 -0600 (Thu, 24 Dec 2009)

Log Message

JBEHAVE-215:  Refactored trader example to show that the same Java Steps methods (with @Named parameters) can be used to match steps that are executed both as standalone or via examples table.

Modified Paths

Diff

Modified: trunk/core/distribution/src/site/content/table-examples.html (1468 => 1469)

--- trunk/core/distribution/src/site/content/table-examples.html	2009-12-24 16:03:41 UTC (rev 1468)
+++ trunk/core/distribution/src/site/content/table-examples.html	2009-12-24 17:32:51 UTC (rev 1469)
@@ -24,17 +24,18 @@
 <p>We notice that two lines are repeated and identical but for the
 values. We can then rewrite this scenario as:</p>
 
-<pre class="brush: bdd">
-    Given a stock of symbol [symbol] and a threshold of [threshold]
-    When the stock is traded at [price]
-    Then the alert status should be [status]
+<script type="syntaxhighlighter" class="brush: bdd"><![CDATA[
+    Given a stock of <symbol> and a <threshold>
+    When the stock is traded at <price>
+    Then the alert status should be <status>
     
     Examples: 
     
     |symbol|threshold|price|status|
     |STK1|10.0|5.0|OFF|
     |STK1|10.0|11.0|ON|
-</pre>
+]]></script>
+
 <p>The <b>Examples:</b> keyword signals that the scenario should be
 repeated for as many times as there are data rows in the examples table.
 At each execution, the named parameters are taken from the corresponding
@@ -46,13 +47,19 @@
 values with the corresponding header name, instead of being extracted
 from the annotation pattern match. As such, <b>the step annotation pattern
 must hold the verbatim textual step</b>. e.g.:</p>
-<pre class="brush: java">
-    @Given("a stock of symbol [symbol] and a threshold of [threshold]")
+
+<script type="syntaxhighlighter" class="brush: java"><![CDATA[
+    @Given("a stock of <symbol> and a <threshold>")
     public void aStock(@Named("symbol") String symbol, @Named("threshold") double threshold) {
         // ...
     }
-</pre>
+]]></script>
 
+<p>Also note that while the characters delimiting the parameter names in the regex pattern are
+purely conventional - they only serve the purpose of matching the step method in a readable manner - 
+the use of the angle brackets is required as it is used to replace the name with the value in the reporting.
+</p>
+
 <div class="clear">
 <hr />
 </div>

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderSteps.java (1468 => 1469)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderSteps.java	2009-12-24 16:03:41 UTC (rev 1468)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderSteps.java	2009-12-24 17:32:51 UTC (rev 1469)
@@ -89,32 +89,19 @@
         return traders;
     }
     
-    @Given("a stock of <symbol> and a <threshold>")
-    public void aStockWithTableParams(@Named("symbol") String symbol, @Named("threshold") double threshold) {
-        stock = new Stock(symbol, threshold);
-    }
-
     @Given("a stock of symbol %symbol and a threshold of %threshold")
-    public void aStockWithNamedParams(@Named("symbol") String symbol, @Named("threshold") double threshold) {
+    @Alias("a stock of <symbol> and a <threshold>") // alias used with examples table
+    public void aStock(@Named("symbol") String symbol, @Named("threshold") double threshold) {
         stock = new Stock(symbol, threshold);
     }
 
-    @When("the stock is traded with <price>")
-    public void theStockIsTradedAtWithTableParam(@Named("price") double price) {
-        stock.tradeAt(price);
-    }
-
     @When("the stock is traded at price %price")
-    @Aliases(values={"the stock is sold at price %price", "the stock is exchanged at price %price"}) // multiple aliases
-    public void theStockIsTradedAtWithNamedParam(@Named("price") double price) {
+    @Aliases(values={"the stock is sold at price %price", "the stock is exchanged at price %price",
+            "the stock is traded with <price>"}) // multiple aliases, one used with examples table
+    public void theStockIsTraded(@Named("price") double price) {
         stock.tradeAt(price);
     }
 
-    @Then("the trader is alerted with <status>")
-    public void theAlertStatusIsWithTableParam(@Named("status") String status) {
-        ensureThat(stock.getStatus().name(), equalTo(status));
-    }
-
     @Given("the alert status is %status") // shows that matching pattern need only be unique for step type
     public void theAlertStatusIsReset(@Named("status") String status) {
     	if ( AlertStatus.OFF.name().startsWith(status) && stock != null ){
@@ -123,8 +110,8 @@
     }
 
     @Then("the alert status is %status")
-    @Alias("the alert status will be %status") // single alias
-    public void theAlertStatusIsWithNamedParam(@Named("status") String status) {
+    @Alias("the trader is alerted with <status>") // alias used with examples table
+    public void theAlertStatusIs(@Named("status") String status) {
         ensureThat(stock.getStatus().name(), equalTo(status));
     }
 


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to