Title: [1245] trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java: Extracted method to return step method from class by name.
Revision
1245
Author
mauro
Date
2009-09-13 07:53:05 -0500 (Sun, 13 Sep 2009)

Log Message

Extracted method to return step method from class by name.

Modified Paths


Diff

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

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2009-09-13 12:48:14 UTC (rev 1244)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2009-09-13 12:53:05 UTC (rev 1245)
@@ -155,7 +155,7 @@
     public void shouldMatchMethodParametersByAnnotatedNamesInNaturalOrder() throws Exception {
     	AnnotationNamedParameterSteps steps = new AnnotationNamedParameterSteps();
         CandidateStep candidateStep = new CandidateStep("I live on the $ith floor but some call it the $nth",
-        		AnnotationNamedParameterSteps.methodFor("methodWithNamedParametersInNaturalOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
+        		stepMethodFor("methodWithNamedParametersInNaturalOrder", AnnotationNamedParameterSteps.class), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
         candidateStep.createFrom(tableRow, "When I live on the first floor but some call it the ground").perform();
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));
@@ -165,7 +165,7 @@
     public void shouldMatchMethodParametersByAnnotatedNamesInverseOrder() throws Exception {
     	AnnotationNamedParameterSteps steps = new AnnotationNamedParameterSteps();
         CandidateStep candidateStep = new CandidateStep("I live on the $ith floor but some call it the $nth",
-        		AnnotationNamedParameterSteps.methodFor("methodWithNamedParametersInInverseOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
+        		stepMethodFor("methodWithNamedParametersInInverseOrder", AnnotationNamedParameterSteps.class), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
         candidateStep.createFrom(tableRow, "When I live on the first floor but some call it the ground").perform();
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));
@@ -177,43 +177,17 @@
     	tableRow.put("ith", "first");
     	tableRow.put("nth", "ground");
         CandidateStep candidateStep = new CandidateStep("I live on the ith floor but some call it the nth",
-        		AnnotationNamedParameterSteps.methodFor("methodWithNamedParametersInNaturalOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
+        		stepMethodFor("methodWithNamedParametersInNaturalOrder", AnnotationNamedParameterSteps.class), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
         candidateStep.createFrom(tableRow, "When I live on the <ith> floor but some call it the <nth>").perform();
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));
     }
-    
-    
-    static class AnnotationNamedParameterSteps extends Steps {
-    	String ith;
-        String nth;
-
-        public void methodWithNamedParametersInNaturalOrder(@Named("ith") String ithName, @Named("nth") String nthName){
-    		this.ith = ithName;    	
-    		this.nth = nthName;
-        }
         
-        public void methodWithNamedParametersInInverseOrder(@Named("nth") String nthName, @Named("ith") String ithName){
-    		this.ith = ithName;    	
-    		this.nth = nthName;
-        }
-
-        public static Method methodFor(String methodName) throws IntrospectionException {
-            BeanInfo beanInfo = Introspector.getBeanInfo(AnnotationNamedParameterSteps.class);
-            for (MethodDescriptor md : beanInfo.getMethodDescriptors()) {
-                if (md.getMethod().getName().equals(methodName)) {
-                    return md.getMethod();
-                }
-            }
-            return null;
-        }
-    }
-
     @Test
     public void shouldMatchMethodParametersByParanamerNamesInNaturalOrder() throws Exception {
     	ParanamerNamedParameterSteps steps = new ParanamerNamedParameterSteps();
         CandidateStep candidateStep = new CandidateStep("I live on the $ith floor but some call it the $nth",
-        		ParanamerNamedParameterSteps.methodFor("methodWithNamedParametersInNaturalOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
+        		stepMethodFor("methodWithNamedParametersInNaturalOrder", ParanamerNamedParameterSteps.class), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
         candidateStep.useParanamer(paranamer);
         candidateStep.createFrom(tableRow, "When I live on the first floor but some call it the ground").perform();
         ensureThat(steps.ith, equalTo("first"));
@@ -224,7 +198,7 @@
     public void shouldMatchMethodParametersByParanamerInverseOrder() throws Exception {
     	ParanamerNamedParameterSteps steps = new ParanamerNamedParameterSteps();
         CandidateStep candidateStep = new CandidateStep("I live on the $ith floor but some call it the $nth",
-        		ParanamerNamedParameterSteps.methodFor("methodWithNamedParametersInInverseOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
+        		stepMethodFor("methodWithNamedParametersInInverseOrder", ParanamerNamedParameterSteps.class), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
         candidateStep.useParanamer(paranamer);
         candidateStep.createFrom(tableRow, "When I live on the first floor but some call it the ground").perform();
         ensureThat(steps.ith, equalTo("first"));
@@ -237,13 +211,29 @@
     	tableRow.put("ith", "first");
     	tableRow.put("nth", "ground");
         CandidateStep candidateStep = new CandidateStep("I live on the ith floor but some call it the nth",
-        		ParanamerNamedParameterSteps.methodFor("methodWithNamedParametersInNaturalOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
+        		stepMethodFor("methodWithNamedParametersInNaturalOrder", ParanamerNamedParameterSteps.class), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
         candidateStep.useParanamer(paranamer);
         candidateStep.createFrom(tableRow, "When I live on the <ith> floor but some call it the <nth>").perform();
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));
     }
 
+    static class AnnotationNamedParameterSteps extends Steps {
+    	String ith;
+        String nth;
+
+        public void methodWithNamedParametersInNaturalOrder(@Named("ith") String ithName, @Named("nth") String nthName){
+    		this.ith = ithName;    	
+    		this.nth = nthName;
+        }
+        
+        public void methodWithNamedParametersInInverseOrder(@Named("nth") String nthName, @Named("ith") String ithName){
+    		this.ith = ithName;    	
+    		this.nth = nthName;
+        }
+
+    }
+
     static class ParanamerNamedParameterSteps extends Steps {
     	String ith;
         String nth;
@@ -258,15 +248,16 @@
     		this.nth = nth;
         }
 
-        public static Method methodFor(String methodName) throws IntrospectionException {
-            BeanInfo beanInfo = Introspector.getBeanInfo(ParanamerNamedParameterSteps.class);
-            for (MethodDescriptor md : beanInfo.getMethodDescriptors()) {
-                if (md.getMethod().getName().equals(methodName)) {
-                    return md.getMethod();
-                }
+    }
+
+    static Method stepMethodFor(String methodName, Class<? extends Steps> stepsClass) throws IntrospectionException {
+        BeanInfo beanInfo = Introspector.getBeanInfo(stepsClass);
+        for (MethodDescriptor md : beanInfo.getMethodDescriptors()) {
+            if (md.getMethod().getName().equals(methodName)) {
+                return md.getMethod();
             }
-            return null;
         }
+        return null;
     }
 
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to