Title: [1624] trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps: JBEHAVE-281: Ensured the previous step for matching purposes is only a non And step, so it can be used to determine the step type compatibility with the current step.

Diff

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderSteps.java (1623 => 1624)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderSteps.java	2010-05-01 11:02:33 UTC (rev 1623)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderSteps.java	2010-05-03 22:59:50 UTC (rev 1624)
@@ -4,12 +4,14 @@
 import static org.jbehave.Ensure.ensureThat;
 
 import java.util.Locale;
+import java.util.Map;
 
 import org.jbehave.examples.trader.model.Stock;
 import org.jbehave.scenario.annotations.Given;
 import org.jbehave.scenario.annotations.Named;
 import org.jbehave.scenario.annotations.Then;
 import org.jbehave.scenario.annotations.When;
+import org.jbehave.scenario.definition.ExamplesTable;
 import org.jbehave.scenario.definition.KeyWords;
 import org.jbehave.scenario.i18n.I18nKeyWords;
 import org.jbehave.scenario.i18n.StringEncoder;
@@ -19,12 +21,17 @@
 public class ItTraderSteps extends Steps {
 
     private Stock stock;
+	private ExamplesTable table;
 
     public ItTraderSteps(ClassLoader classLoader) {
     	// Use Italian for keywords
         super(new StepsConfiguration(keywordsFor(new Locale("it"), classLoader)));
     }
 
+	protected static KeyWords keywordsFor(Locale locale, ClassLoader classLoader) {
+		return new I18nKeyWords(locale, new StringEncoder(), "org/jbehave/examples/trader/i18n/keywords", classLoader);
+	}
+
     @Given("ho un'azione con simbolo $symbol e una soglia di $threshold")
     public void aStock(@Named("symbol") String symbol, @Named("threshold") double threshold) {
         stock = new Stock(symbol, threshold);
@@ -40,8 +47,20 @@
         ensureThat(stock.getStatus().name(), equalTo(status));
     }
 
-	protected static KeyWords keywordsFor(Locale locale, ClassLoader classLoader) {
-		return new I18nKeyWords(locale, new StringEncoder(), "org/jbehave/examples/trader/i18n/keywords", classLoader);
-	}
+    @Given("ho una tabella $table")
+    public void aTable(ExamplesTable table) {
+        this.table = table;
+    }
 
+    @Then("la tabella ha $rows righe")
+    public void hasRows(int rows){
+        ensureThat(table.getRowCount(), equalTo(rows));
+    }
+
+    @Then("alla riga $row e colonna $column troviamo: $value")
+    public void theRowValuesAre(int row, String column, String value){
+        Map<String,String> rowValues = table.getRow(row-1);      
+        ensureThat(rowValues.get(column), equalTo(value));
+    }
+
 }

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/it_trader_is_alerted_of_status.scenario (1623 => 1624)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/it_trader_is_alerted_of_status.scenario	2010-05-01 11:02:33 UTC (rev 1623)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/it_trader_is_alerted_of_status.scenario	2010-05-03 22:59:50 UTC (rev 1624)
@@ -11,4 +11,16 @@
 Quando l'azione e' scambiata al prezzo di 16.0
 Allora lo status di allerta e' ON
 Quando l'azione e' scambiata al prezzzzzzzzo di 20.0
-Allora lo status di allerta e' ON
\ No newline at end of file
+Allora lo status di allerta e' ON
+
+Scenario:
+
+Dato che ho una tabella
+|uno|due|
+|11|12|
+|21|22|
+Allora la tabella ha 2 righe
+E alla riga 1 e colonna uno troviamo: 11
+E alla riga 1 e colonna due troviamo: 12
+E alla riga 2 e colonna uno troviamo: 21
+E alla riga 2 e colonna due troviamo: 22

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java (1623 => 1624)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java	2010-05-01 11:02:33 UTC (rev 1623)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java	2010-05-03 22:59:50 UTC (rev 1624)
@@ -93,20 +93,20 @@
     	return matches(stepAsString, null);
     }
 
-    public boolean matches(String stepAsString, String previousAsString) {
+    public boolean matches(String step, String previousNonAndStep) {
         try {
         	boolean matchesType = true;
-        	if ( isAndStep(stepAsString) ){
-        		if ( previousAsString == null ){
+        	if ( isAndStep(step) ){
+        		if ( previousNonAndStep == null ){
         			matchesType = false; // cannot handle AND step with no previous step
         		} else {
         			// previous step type should match candidate step type
-        			matchesType = startingWordFor(stepType).equals(findStartingWord(previousAsString));
+        			matchesType = startingWordFor(stepType).equals(findStartingWord(previousNonAndStep));
         		}
         	}
-            stepMonitor.stepMatchesType(stepAsString, previousAsString, matchesType, stepType);
-            boolean matchesPattern = matcherForStep(stepAsString).matches();
-            stepMonitor.stepMatchesPattern(stepAsString, matchesPattern, pattern.pattern());
+            stepMonitor.stepMatchesType(step, previousNonAndStep, matchesType, stepType);
+            boolean matchesPattern = matcherForStep(step).matches();
+            stepMonitor.stepMatchesPattern(step, matchesPattern, pattern.pattern());
             // must match both type and pattern
             return matchesType && matchesPattern;
         } catch (StartingWordNotFound e) {
@@ -114,8 +114,8 @@
         }
     }
 
-	private boolean isAndStep(String stepAsString) {
-		return stepAsString.startsWith(startingWordFor(StepType.AND));
+	public boolean isAndStep(String step) {
+		return step.startsWith(startingWordFor(StepType.AND));
 	}
 
     private String trimStartingWord(String word, String step) {

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/UnmatchedToPendingStepCreator.java (1623 => 1624)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/UnmatchedToPendingStepCreator.java	2010-05-01 11:02:33 UTC (rev 1623)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/UnmatchedToPendingStepCreator.java	2010-05-03 22:59:50 UTC (rev 1624)
@@ -56,7 +56,7 @@
     private void addMatchedScenarioSteps(ScenarioDefinition scenarioDefinition, List<Step> steps,
             Map<String, String> tableRow, CandidateSteps... candidateSteps) {
         List<CandidateStep> prioritised = prioritise(candidateSteps);
-        String previousStep = null;
+        String previousNonAndStep = null;
         for (String stringStep : scenarioDefinition.getSteps()) {        	
             Step step = new PendingStep(stringStep);
             for (CandidateStep candidate : prioritised) {
@@ -65,22 +65,25 @@
                     step = new IgnorableStep(stringStep);
                     break;
                 }
-                if (matchesCandidate(stringStep, previousStep, candidate)) {
+                if (matchesCandidate(stringStep, previousNonAndStep, candidate)) {
                     step = candidate.createFrom(tableRow, stringStep);
+                    if  ( !candidate.isAndStep(stringStep) ){
+                    	// only update previous step if not AND step
+                        previousNonAndStep = stringStep;            	
+                    }
                     break;
                 }
             }
             steps.add(step);
-            previousStep = stringStep;
         }
     }
 
-	private boolean matchesCandidate(String stringStep, String previousStep,
+	private boolean matchesCandidate(String step, String previousNonAndStep,
 			CandidateStep candidate) {
-		if ( previousStep != null ){
-			return candidate.matches(stringStep, previousStep);			
+		if ( previousNonAndStep != null ){
+			return candidate.matches(step, previousNonAndStep);			
 		}
-		return candidate.matches(stringStep);
+		return candidate.matches(step);
 	}
 
     private List<CandidateStep> prioritise(CandidateSteps[] candidateSteps) {


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to