Title: [935] trunk/examples/trader: JBEHAVE-133: Introduced StepsConfiguration object so decorator classes extending Steps can easily provide custom configuration.
Revision
935
Author
mauro
Date
2008-09-21 06:13:52 -0500 (Sun, 21 Sep 2008)

Log Message

JBEHAVE-133: Introduced StepsConfiguration object so decorator classes extending Steps can easily provide custom configuration.  Configuration object also provides most common default constructors.

Modified Paths

Added Paths

Diff

Modified: trunk/examples/trader/pom.xml (934 => 935)

--- trunk/examples/trader/pom.xml	2008-09-21 09:36:39 UTC (rev 934)
+++ trunk/examples/trader/pom.xml	2008-09-21 11:13:52 UTC (rev 935)
@@ -9,7 +9,24 @@
   <artifactId>jbehave-trader-example</artifactId>
   <name>JBehave Trader Example</name>
 
-  <dependencies></dependencies>
+  <dependencies>
+    <dependency>
+      <groupId>org.jbehave</groupId>
+      <artifactId>jbehave-core</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.picocontainer.script</groupId>
+      <artifactId>picocontainer-script-core</artifactId>
+      <version>2.0</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.thoughtworks.xstream</groupId>
+      <artifactId>xstream</artifactId>
+      <version>1.3</version>
+    </dependency>
+  </dependencies>
   <build>
     <sourceDirectory>src/main/java</sourceDirectory>
     <testSourceDirectory>src/behaviour/java</testSourceDirectory>

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StockSteps.java (934 => 935)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StockSteps.java	2008-09-21 09:36:39 UTC (rev 934)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StockSteps.java	2008-09-21 11:13:52 UTC (rev 935)
@@ -18,6 +18,7 @@
 import org.jbehave.scenario.steps.SilentStepMonitor;
 import org.jbehave.scenario.steps.StepMonitor;
 import org.jbehave.scenario.steps.Steps;
+import org.jbehave.scenario.steps.StepsConfiguration;
 
 public class StockSteps extends Steps {
 
@@ -27,7 +28,8 @@
     private Trader trader;
 
     public StockSteps(double threshold) {
-        super(new PrefixCapturingPatternBuilder(), MONITOR, new ParameterConverters(new SilentStepMonitor(), new TraderConverter(mockTradePersister())), "Given", "When", "Then", "And");
+        super(new StepsConfiguration(new PrefixCapturingPatternBuilder(), MONITOR, new ParameterConverters(
+                new SilentStepMonitor(), new TraderConverter(mockTradePersister())), "Given", "When", "Then", "And"));
         this.threshold = threshold;
     }
 
@@ -56,7 +58,7 @@
     }
 
     @Then("the trader sells all stocks")
-    public void theTraderSellsAllStocks(){
+    public void theTraderSellsAllStocks() {
         trader.sellAllStocks();
         ensureThat(trader.getStocks().size(), equalTo(0));
     }

Modified: trunk/jbehave-core/src/java/org/jbehave/container/ContainerSteps.java (934 => 935)

--- trunk/jbehave-core/src/java/org/jbehave/container/ContainerSteps.java	2008-09-21 09:36:39 UTC (rev 934)
+++ trunk/jbehave-core/src/java/org/jbehave/container/ContainerSteps.java	2008-09-21 11:13:52 UTC (rev 935)
@@ -2,6 +2,7 @@
 
 import org.jbehave.container.pico.XMLPicoContainerSteps;
 import org.jbehave.scenario.steps.Steps;
+import org.jbehave.scenario.steps.StepsConfiguration;
 
 /**
  * <p>
@@ -23,6 +24,11 @@
     }
 
     public ContainerSteps(String containerResource, ClassLoader classLoader) {    
+        this(containerResource, classLoader, new StepsConfiguration());
+    }
+
+    public ContainerSteps(String containerResource, ClassLoader classLoader, StepsConfiguration configuration) {
+        super(configuration);
         container = createContainer(containerResource, classLoader);
     }
 

Modified: trunk/jbehave-core/src/java/org/jbehave/container/pico/XMLPicoContainerSteps.java (934 => 935)

--- trunk/jbehave-core/src/java/org/jbehave/container/pico/XMLPicoContainerSteps.java	2008-09-21 09:36:39 UTC (rev 934)
+++ trunk/jbehave-core/src/java/org/jbehave/container/pico/XMLPicoContainerSteps.java	2008-09-21 11:13:52 UTC (rev 935)
@@ -2,6 +2,7 @@
 
 import org.jbehave.container.Container;
 import org.jbehave.container.ContainerSteps;
+import org.jbehave.scenario.steps.StepsConfiguration;
 
 /**
  * XMLPicoContainer-based Steps decorator.
@@ -17,6 +18,10 @@
     public XMLPicoContainerSteps(String containerResource, ClassLoader classLoader) {
         super(containerResource, classLoader);
     }
+    
+    public XMLPicoContainerSteps(String containerResource, ClassLoader classLoader, StepsConfiguration configuration) {
+        super(containerResource, classLoader, configuration);
+    }
 
     protected Container createContainer(String containerResource, ClassLoader classLoader) {
         return new XMLPicoContainer(containerResource, classLoader);

Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java (934 => 935)

--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java	2008-09-21 09:36:39 UTC (rev 934)
+++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java	2008-09-21 11:13:52 UTC (rev 935)
@@ -6,43 +6,36 @@
 import org.jbehave.scenario.annotations.Given;
 import org.jbehave.scenario.annotations.Then;
 import org.jbehave.scenario.annotations.When;
-import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder;
 import org.jbehave.scenario.parser.StepPatternBuilder;
 
 /**
  * <p>
- * Extend this class to provide the definition of steps that
- * match the scenario you want to run.
+ * Extend this class to provide the definition of steps that match the scenario
+ * you want to run.
  * </p>
- * 
- * <p>You can define the methods that should be run when each step
- * is performed by annotating them with @Given, @When or @Then,
- * and providing a value for each annotation that matches the
- * step. By default, the match is performed using a '$' prefix
- * to pick up parameters.</p>
- * 
- * <p>For instance, you could define a method as:
- * 
- * <code lang="java">
- * @When(&quot; I log in as $username with password: $password&quot;)
- * public void logIn(String username, String password) {
- *   //...
- * }
- * </code>
- * 
- * and this would match the step:
- * 
- * <code>When I log in as Liz with password: Pa55word</code>
- * 
- * <p>When the step is perfomed, the parameters in the scenario definition
- * will be passed to the class, so in this case the effect will be
- * 
- * <code>mySteps.logIn("Liz", "Pa55word");</code>
+ * <p>
+ * You can define the methods that should be run when each step is performed by
+ * annotating them with @Given, @When or @Then, and providing a value for each
+ * annotation that matches the step. By default, the match is performed using a
+ * '$' prefix to pick up parameters.
  * </p>
+ * <p>
+ * For instance, you could define a method as: <code lang="java">
  * 
- * <p>ParameterConverters can be used to convert parameters from any String format
- * to another class. Custom converters can be provided here in addition to the
- * defaults.</p>
+ * @When(&quot; I log in as $username with password: $password&quot;) public
+ *                void logIn(String username, String password) { //... } </code>
+ *                and this would match the step:
+ *                <code>When I log in as Liz with password: Pa55word</code>
+ *                <p>
+ *                When the step is perfomed, the parameters in the scenario
+ *                definition will be passed to the class, so in this case the
+ *                effect will be <code>mySteps.logIn("Liz", "Pa55word");</code>
+ *                </p>
+ *                <p>
+ *                ParameterConverters can be used to convert parameters from any
+ *                String format to another class. Custom converters can be
+ *                provided here in addition to the defaults.
+ *                </p>
  */
 public class Steps {
 
@@ -52,36 +45,33 @@
     private final String[] startingWords;
 
     /**
-     * Creates Steps with all default dependencies
+     * Creates Steps with default configuration
      */
     public Steps() {
-        this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), new ParameterConverters(), "Given", "When",
-                "Then", "And");
+        this(new StepsConfiguration());
     }
 
     /**
-     * Creates Steps with all default dependencies except for custom starting keywords
+     * Creates Steps with all default configuration except for custom starting
+     * keywords
      * 
-     * @param startingWords the words with which we expect steps in the scenarios to start
+     * @param startingWords the words with which we expect steps in the
+     *            scenarios to start
      */
     public Steps(String... startingWords) {
-       this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), new ParameterConverters(), startingWords);
+        this(new StepsConfiguration(startingWords));
     }
 
     /**
      * Creates Steps with all custom dependencies
      * 
-     * @param patternBuilder how we build patterns from annotations which will match the steps in the scenarios
-     * @param stepMonitor how we monitor the matching of the patterns
-     * @param parameterConverters how we convert parameters from Strings to other objects
-     * @param startingWords the words with which we expect steps in the scenarios to start
+     * @param configuration the StepsConfiguration
      */
-    public Steps(StepPatternBuilder patternBuilder, StepMonitor stepMonitor, ParameterConverters parameterConverters,
-            String... startingWords) {
-        this.patternBuilder = patternBuilder;
-        this.stepMonitor = stepMonitor;
-        this.parameterConverters = parameterConverters;
-        this.startingWords = startingWords;
+    public Steps(StepsConfiguration configuration) {
+        this.patternBuilder = configuration.getPatternBuilder();
+        this.stepMonitor = configuration.getMonitor();
+        this.parameterConverters = configuration.getParameterConverters();
+        this.startingWords = configuration.getStartingWords();
     }
 
     /**

Added: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java (0 => 935)

--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	                        (rev 0)
+++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	2008-09-21 11:13:52 UTC (rev 935)
@@ -0,0 +1,50 @@
+package org.jbehave.scenario.steps;
+
+import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder;
+import org.jbehave.scenario.parser.StepPatternBuilder;
+
+/**
+ * <p>
+ * Class allowing steps functionality to be fully configurable, while providing
+ * default values for most commonly-used cases.
+ * </p>
+ */
+public class StepsConfiguration {
+    private StepPatternBuilder patternBuilder;
+    private StepMonitor monitor;
+    private ParameterConverters parameterConverters;
+    private String[] startingWords;
+
+    public StepsConfiguration() {
+        this("Given", "When", "Then", "And");
+    }
+
+    public StepsConfiguration(String... startingWords) {
+        this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), new ParameterConverters(), startingWords);
+    }
+
+    public StepsConfiguration(StepPatternBuilder patternBuilder, StepMonitor monitor,
+            ParameterConverters parameterConverters, String... startingWords) {
+        this.patternBuilder = patternBuilder;
+        this.monitor = monitor;
+        this.parameterConverters = parameterConverters;
+        this.startingWords = startingWords;
+    }
+
+    public StepPatternBuilder getPatternBuilder() {
+        return patternBuilder;
+    }
+
+    public StepMonitor getMonitor() {
+        return monitor;
+    }
+
+    public ParameterConverters getParameterConverters() {
+        return parameterConverters;
+    }
+
+    public String[] getStartingWords() {
+        return startingWords;
+    }
+
+}


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to