Title: [1108] trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps: add sig for StepDoc and tests and finer grained stepdoc comparable
Revision
1108
Author
paul
Date
2009-02-22 13:46:44 -0600 (Sun, 22 Feb 2009)

Log Message

add sig for StepDoc and tests and finer grained stepdoc comparable

Modified Paths


Diff

Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepdocGeneratorBehaviour.java (1107 => 1108)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepdocGeneratorBehaviour.java	2009-02-22 18:57:56 UTC (rev 1107)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepdocGeneratorBehaviour.java	2009-02-22 19:46:44 UTC (rev 1108)
@@ -2,6 +2,9 @@
 
 import static java.util.Arrays.asList;
 import static org.hamcrest.CoreMatchers.equalTo;
+import org.hamcrest.Matcher;
+import org.hamcrest.Description;
+import org.hamcrest.BaseMatcher;
 import static org.jbehave.Ensure.ensureThat;
 
 import java.util.List;
@@ -25,7 +28,58 @@
         ensureThat(stepdocs.get(2).getAliasPatterns(), equalTo(asList("a then alias", "another then alias")));
         ensureThat(stepdocs.get(2).getMethod().getName(), equalTo("then"));
     }    
+
+    @Test
+    public void shouldHaveTerseSignatures() {
+        StepdocGenerator generator = new DefaultStepdocGenerator();
+        MoreSteps steps = new MoreSteps();
+        List<Stepdoc> stepdocs = generator.generate(steps.getClass());
+        ensureThat(stepdocs.get(0).getSignature(), equalTo("org.jbehave.scenario.steps.StepdocGeneratorBehaviour$MoreSteps.givenAbc(int,int)"));
+        ensureThat(stepdocs.get(1).getSignature(), equalTo("org.jbehave.scenario.steps.StepdocGeneratorBehaviour$MoreSteps.whenAbc(int,int)"));
+        ensureThat(stepdocs.get(2).getSignature(), equalTo("org.jbehave.scenario.steps.StepdocGeneratorBehaviour$MoreSteps.whenXyz(int,int)"));
+        ensureThat(stepdocs.get(3).getSignature(), equalTo("org.jbehave.scenario.steps.StepdocGeneratorBehaviour$MoreSteps.thenAbc(int,int)"));
+    }
+
+    @Test
+    public void shouldHaveFinerGrainedComparablesThanJustPriority() {
+        StepdocGenerator generator = new DefaultStepdocGenerator();
+        MoreSteps steps = new MoreSteps();
+        List<Stepdoc> stepdocs = generator.generate(steps.getClass());
+        Stepdoc when1 = stepdocs.get(1);
+        Stepdoc when2 = stepdocs.get(2);
+
+        ensureThat(when1.compareTo(when2), lessThan(0));
+
+        ensureThat(when2.compareTo(when1), greaterThan(0));
+    }
+
+    private Matcher<Integer> lessThan(final int i) {
+        return new BaseMatcher<Integer>() {
+            public boolean matches(Object o) {
+                int i1 = ((Integer) o).compareTo(i);
+                return i1 < 0;
+            }
+
+            public void describeTo(Description description) {
+                description.appendText("not less than");
+            }
+        };
+    }
     
+    private Matcher<Integer> greaterThan(final int i) {
+        return new BaseMatcher<Integer>() {
+            public boolean matches(Object o) {
+                int i1 = ((Integer) o).compareTo(i);
+                return i1 > 0;
+            }
+
+            public void describeTo(Description description) {
+                description.appendText("not greater than");
+            }
+        };
+    }
+
+
     public static class MySteps extends Steps {
         
         private int givens;
@@ -51,5 +105,25 @@
         }
                 
     }
-    
+
+    public static class MoreSteps extends Steps {
+
+        @org.jbehave.scenario.annotations.Given("blah $xx blah $yy")
+        public void givenAbc(int xx, int yy) {
+        }
+
+        @org.jbehave.scenario.annotations.When("blah $xx blah $yy")
+        public void whenAbc(int xx, int yy) {
+        }
+        
+        @org.jbehave.scenario.annotations.When("blah $xx blah $yy blah")
+        public void whenXyz(int xx, int yy) {
+        }
+
+        @org.jbehave.scenario.annotations.Then("blah $xx blah $yy")
+        public void thenAbc(int xx, int yy) {
+        }
+
+    }
+
 }

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Stepdoc.java (1107 => 1108)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Stepdoc.java	2009-02-22 18:57:56 UTC (rev 1107)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Stepdoc.java	2009-02-22 19:46:44 UTC (rev 1108)
@@ -4,6 +4,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.List;
 
 import org.jbehave.scenario.annotations.Given;
@@ -54,15 +55,30 @@
 		return method;
 	}
 
-	@Override
+    /**
+     * Method signature without "public void" (etc) prefix
+     * @return
+     */
+    public String getSignature() {
+        String methodSignature = method.toString();
+        int ix = methodSignature.indexOf(" ");
+        ix = methodSignature.indexOf(" ", ix+1);
+        return methodSignature.substring(ix+1);
+    }
+
+    @Override
 	public String toString() {
 		StringBuffer sb = new StringBuffer();
 		sb.append("[Stepdoc pattern=").append(pattern).append(", aliases=")
-				.append(aliasPatterns).append(", method=").append(method).append("]");
+				.append(aliasPatterns).append(", method=").append(getSignature()).append("]");
 		return sb.toString();
 	}
 
 	public int compareTo(Stepdoc that) {
-		return this.priority.compareTo(that.priority);
+        int retVal = this.priority.compareTo(that.priority);
+        if (retVal == 0) {
+            retVal = this.getPattern().compareTo(that.getPattern());
+        }
+        return retVal;
 	}
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to