Title: [986] trunk/jbehave-core/src/java/org/jbehave/scenario/steps: JBEHAVE-141: Added use methods for all StepsConfiguration dependencies.

Diff

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertCanBeActivated.java (985 => 986)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertCanBeActivated.java	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertCanBeActivated.java	2008-10-25 12:06:10 UTC (rev 986)
@@ -20,7 +20,7 @@
             public ScenarioDefiner forDefiningScenarios() {
                 return new ClasspathScenarioDefiner(new UnderscoredCamelCaseResolver(".scenario"), new PatternScenarioParser(new PropertyBasedConfiguration()), classLoader);
             }
-        }, new TraderSteps(10.0, classLoader));
+        }, new TraderSteps(classLoader));
     }
 
 }

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertIsNeverActivated.java (985 => 986)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertIsNeverActivated.java	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertIsNeverActivated.java	2008-10-25 12:06:10 UTC (rev 986)
@@ -19,7 +19,7 @@
             public ClasspathScenarioDefiner forDefiningScenarios() {
                 return new ClasspathScenarioDefiner(new UnderscoredCamelCaseResolver(".scenario"), new PatternScenarioParser(new PropertyBasedConfiguration()), classLoader);
             }
-        }, new TraderSteps(100.0, classLoader));
+        }, new TraderSteps(classLoader));
     }
 
 }

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSellsAllStocks.java (985 => 986)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSellsAllStocks.java	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSellsAllStocks.java	2008-10-25 12:06:10 UTC (rev 986)
@@ -19,7 +19,7 @@
             public ScenarioDefiner forDefiningScenarios() {
                 return new ClasspathScenarioDefiner(new UnderscoredCamelCaseResolver(".scenario"), new PatternScenarioParser(this), classLoader);
             }
-        }, new TraderContainerSteps(10.0, classLoader)); // Could also use new TraderSteps(10.0, classLoader)
+        }, new TraderSteps(classLoader)); 
     }
 
 }

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSteps.java (985 => 986)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSteps.java	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSteps.java	2008-10-25 12:06:10 UTC (rev 986)
@@ -16,43 +16,42 @@
 import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder;
 import org.jbehave.scenario.steps.ParameterConverters;
 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 TraderSteps extends Steps {
 
-    private static final StepMonitor MONITOR = new SilentStepMonitor();
-    private double threshold;
+	private static final StepsConfiguration configuration = new StepsConfiguration();
     private Stock stock;
     private Trader trader;
 
-    public TraderSteps(double threshold, ClassLoader classLoader) {
-        super(new StepsConfiguration(new PrefixCapturingPatternBuilder(), MONITOR, new ParameterConverters(
-                new SilentStepMonitor(), new TraderConverter(mockTradePersister())), "Given", "When", "Then", "And"));
-        this.threshold = threshold;
+    public TraderSteps(ClassLoader classLoader) {
+        super(configuration);
+        configuration.useParameterConverters(new ParameterConverters(
+        		new SilentStepMonitor(), new TraderConverter(mockTradePersister())));
+        configuration.usePatternBuilder(new PrefixCapturingPatternBuilder("%"));
     }
 
-    private static TraderPersister mockTradePersister() {
+    private TraderPersister mockTradePersister() {
         return new TraderPersister(new Trader("Mauro", asList(new Stock(asList(1.0d), 10.d))));
     }
 
-    @Given("a trader of name $trader")
+    @Given("a trader of name %trader")
     public void aTrader(Trader trader) {
         this.trader = trader;
     }
 
-    @Given("a stock of prices $prices")
-    public void aStockOfPrice(List<Double> prices) {
+    @Given("a stock of prices %prices and a threshold of %threshold")
+    public void aStockOfPrice(List<Double> prices, double threshold) {
         stock = new Stock(prices, threshold);
     }
 
-    @When("the stock is traded at $price")
+    @When("the stock is traded at %price")
     public void theStockIsTradedAt(double price) {
         stock.tradeAt(price);
     }
 
-    @Then("the alert status should be $status")
+    @Then("the alert status should be %status")
     public void theAlertStatusShouldBe(String status) {
         ensureThat(stock.getStatus().name(), equalTo(status));
     }

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario (985 => 986)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario	2008-10-25 12:06:10 UTC (rev 986)
@@ -1,6 +1,4 @@
-Given a stock of prices 0.5,1.0
-When the stock is traded at 2.0
-Then the alert status should be OFF
+Given a stock of prices 0.5,1.0 and a threshold of 10.0
 When the stock is traded at 5.0
 Then the alert status should be OFF
 When the stock is traded at 11.0

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_is_never_activated.scenario (985 => 986)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_is_never_activated.scenario	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_is_never_activated.scenario	2008-10-25 12:06:10 UTC (rev 986)
@@ -1,6 +1,4 @@
-Given a stock of prices 0.5,1.0
-When the stock is traded at 2.0
-Then the alert status should be OFF
+Given a stock of prices 0.5,1.0 and a threshold of 15.0
 When the stock is traded at 5.0
 Then the alert status should be OFF
 When the stock is traded at 11.0

Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/trader_sells_all_stocks.scenario (985 => 986)

--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/trader_sells_all_stocks.scenario	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/trader_sells_all_stocks.scenario	2008-10-25 12:06:10 UTC (rev 986)
@@ -1,4 +1,4 @@
 Given a trader of name Mauro
-Given a stock of prices 0.5,1.0
+Given a stock of prices 0.5,1.0 and a threshold of 1.5
 When the stock is traded at 2.0
 Then the trader sells all stocks

Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java (985 => 986)

--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	2008-10-25 11:35:56 UTC (rev 985)
+++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	2008-10-25 12:06:10 UTC (rev 986)
@@ -8,56 +8,77 @@
  * Class allowing steps functionality to be fully configurable, while providing
  * default values for most commonly-used cases.
  * </p>
+ * <p>
+ * Configuration dependencies can be provided either via constructor or via
+ * setters (called use* methods to underline that a default value of the
+ * dependency is always set, but can be overridden). The use methods allow to
+ * override the dependencies one by one and play nicer with a Java hierarchical
+ * structure, in that does allow the use of non-static member variables.
+ * </p>
  */
 public class StepsConfiguration {
 
-    public static final String[] DEFAULT_STARTING_WORDS = new String[] {
-        "Given", "When", "Then", "And"
-    };
-    
-    private StepPatternBuilder patternBuilder;
-    private StepMonitor monitor;
-    private ParameterConverters parameterConverters;
-    private String[] startingWords;
+	public static final String[] DEFAULT_STARTING_WORDS = new String[] {
+			"Given", "When", "Then", "And" };
 
-    public StepsConfiguration() {
-        this(DEFAULT_STARTING_WORDS);
-    }
+	private StepPatternBuilder patternBuilder;
+	private StepMonitor monitor;
+	private ParameterConverters parameterConverters;
+	private String[] startingWords;
 
-    public StepsConfiguration(String... startingWords) {
-        this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), new ParameterConverters(), startingWords);
-    }
+	public StepsConfiguration() {
+		this(DEFAULT_STARTING_WORDS);
+	}
 
-    public StepsConfiguration(StepPatternBuilder patternBuilder, StepMonitor monitor,
-            ParameterConverters parameterConverters, String... startingWords) {
-        this.patternBuilder = patternBuilder;
-        this.monitor = monitor;
-        this.parameterConverters = parameterConverters;
-        this.startingWords = startingWords;
-    }
+	public StepsConfiguration(String... startingWords) {
+		this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(),
+				new ParameterConverters(), startingWords);
+	}
 
-    public StepsConfiguration(ParameterConverters converters) {
-        this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), converters, DEFAULT_STARTING_WORDS);
-    }
+	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 StepsConfiguration(ParameterConverters converters) {
+		this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(),
+				converters, DEFAULT_STARTING_WORDS);
+	}
 
-    public StepMonitor getMonitor() {
-        return monitor;
-    }
+	public StepPatternBuilder getPatternBuilder() {
+		return patternBuilder;
+	}
 
-    public void useMonitor(StepMonitor monitor) {
-         this.monitor = monitor;
-    }
+	public void usePatternBuilder(StepPatternBuilder patternBuilder) {
+		this.patternBuilder = patternBuilder;
+	}
 
-    public ParameterConverters getParameterConverters() {
-        return parameterConverters;
-    }
+	public StepMonitor getMonitor() {
+		return monitor;
+	}
 
-    public String[] getStartingWords() {
-        return startingWords;
-    }
+	public void useMonitor(StepMonitor monitor) {
+		this.monitor = monitor;
+	}
 
+	public ParameterConverters getParameterConverters() {
+		return parameterConverters;
+	}
+
+	public void useParameterConverters(ParameterConverters parameterConverters) {
+		this.parameterConverters = parameterConverters;
+	}
+
+	public String[] getStartingWords() {
+		return startingWords;
+	}
+
+	public void useStartingWords(String... startingWords) {
+		this.startingWords = startingWords;
+	}
+
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to