Title: [1366] trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps: Moved ConfusingStepsBehaviour to CandidateStepBehaviour.
Revision
1366
Author
mauro
Date
2009-10-26 17:30:04 -0500 (Mon, 26 Oct 2009)

Log Message

Moved ConfusingStepsBehaviour to CandidateStepBehaviour.

Modified Paths


Removed Paths

Diff

Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java (1365 => 1366)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2009-10-26 21:15:24 UTC (rev 1365)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2009-10-26 22:30:04 UTC (rev 1366)
@@ -2,6 +2,7 @@
 
 import static java.util.Arrays.asList;
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.jbehave.Ensure.ensureThat;
 import static org.jbehave.Ensure.not;
 import static org.jbehave.scenario.steps.StepType.GIVEN;
@@ -19,10 +20,13 @@
 import java.util.List;
 import java.util.Map;
 
+import org.jbehave.scenario.annotations.Given;
 import org.jbehave.scenario.annotations.Named;
+import org.jbehave.scenario.annotations.When;
 import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder;
 import org.jbehave.scenario.parser.StepPatternBuilder;
 import org.jbehave.scenario.reporters.ScenarioReporter;
+import org.jbehave.scenario.steps.CandidateStep.StartingWordNotFound;
 import org.junit.Test;
 
 import com.thoughtworks.paranamer.BytecodeReadingParanamer;
@@ -228,7 +232,45 @@
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));
     }
+    
+    @Test
+    public void shouldCreateStepsOfDifferentTypesWithSameMatchingPattern() {
+        NamedTypeSteps steps = new NamedTypeSteps();
+        CandidateStep[] candidateSteps = steps.getSteps();
+        ensureThat(candidateSteps.length, equalTo(2));
+        candidateSteps[0].createFrom(tableRow, "Given foo named xyz").perform();
+        candidateSteps[1].createFrom(tableRow, "When foo named Bar").perform();
+        ensureThat(steps.givenName, equalTo("xyz"));
+        ensureThat(steps.whenName, equalTo("Bar"));
+    }
 
+	@Test(expected=StartingWordNotFound.class)
+    public void shouldNotCreateStepOfWrongType() {
+        NamedTypeSteps steps = new NamedTypeSteps();
+        CandidateStep[] candidateSteps = steps.getSteps();
+        ensureThat(candidateSteps.length, equalTo(2));
+        candidateSteps[0].createFrom(tableRow, "Given foo named xyz").perform();
+        ensureThat(steps.givenName, equalTo("xyz"));
+        ensureThat(steps.whenName, nullValue());
+        candidateSteps[0].createFrom(tableRow, "Then foo named xyz").perform();
+    }
+	
+    static class NamedTypeSteps extends Steps {
+        String givenName;
+        String whenName;
+
+        @Given("foo named $name")
+        public void givenFoo(String name) {
+        	givenName = name;
+        }
+
+        @When("foo named $name")
+        public void whenFoo(String name) {
+        	whenName = name;
+        }
+
+    }
+
     static class AnnotationNamedParameterSteps extends Steps {
     	String ith;
         String nth;

Deleted: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ConfusingStepsBehavior.java (1365 => 1366)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ConfusingStepsBehavior.java	2009-10-26 21:15:24 UTC (rev 1365)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ConfusingStepsBehavior.java	2009-10-26 22:30:04 UTC (rev 1366)
@@ -1,56 +0,0 @@
-package org.jbehave.scenario.steps;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.jbehave.Ensure.ensureThat;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jbehave.scenario.annotations.Given;
-import org.jbehave.scenario.annotations.When;
-import org.jbehave.scenario.steps.CandidateStep.StartingWordNotFound;
-import org.junit.Test;
-
-public class ConfusingStepsBehavior {
-
-    private Map<String, String> tableRow = new HashMap<String, String>();
-
-	@Test
-    public void shouldAllowStepOfDifferentTypesWithPatternThatMatchesSameStep() {
-        MySteps steps = new MySteps();
-        CandidateStep[] candidateSteps = steps.getSteps();
-        ensureThat(candidateSteps.length, equalTo(2));
-        candidateSteps[0].createFrom(tableRow, "Given foo named xyz").perform();
-        candidateSteps[1].createFrom(tableRow, "When foo named Bar is created").perform();
-        ensureThat(steps.givenName, equalTo("xyz"));
-        ensureThat(steps.whenName, equalTo("Bar"));
-    }
-
-	@Test(expected=StartingWordNotFound.class)
-    public void shouldFailWhenTryingToMatchStepOfWrongType() {
-        MySteps steps = new MySteps();
-        CandidateStep[] candidateSteps = steps.getSteps();
-        ensureThat(candidateSteps.length, equalTo(2));
-        candidateSteps[0].createFrom(tableRow, "Given foo named xyz").perform();
-        ensureThat(steps.givenName, equalTo("xyz"));
-        candidateSteps[0].createFrom(tableRow, "Then foo named xyz").perform();
-    }
-	
-    static class MySteps extends Steps {
-        private String givenName;
-        private String whenName;
-
-        @Given("foo named $name")
-        public void givenFoo(String name) {
-        	givenName = name;
-        }
-
-        @When("foo named $name is created")
-        public void createFoo(String name) {
-        	whenName = name;
-        }
-
-    }
-
-
-}


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to