Title: [1218] trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps: JBEHAVE-173: Made Parameter instance configurable via StepsConfiguration.

Diff

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

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2009-09-05 08:37:10 UTC (rev 1217)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2009-09-05 09:06:08 UTC (rev 1218)
@@ -22,12 +22,17 @@
 import org.jbehave.scenario.reporters.ScenarioReporter;
 import org.junit.Test;
 
+import com.thoughtworks.paranamer.BytecodeReadingParanamer;
+import com.thoughtworks.paranamer.CachingParanamer;
+import com.thoughtworks.paranamer.Paranamer;
+
 public class CandidateStepBehaviour {
 
     private static final StepPatternBuilder PATTERN_BUILDER = new PrefixCapturingPatternBuilder();
     private static final StepMonitor MONITOR = new SilentStepMonitor();
     private static final String NL = System.getProperty("line.separator");
 	private Map<String, String> tableValues = new HashMap<String, String>();
+	private Paranamer paranamer =  new CachingParanamer(new BytecodeReadingParanamer());
 
     @Test
     public void shouldMatchASimpleString() throws Exception {
@@ -209,7 +214,7 @@
     	NamedParameterStepsViaParanamer steps = new NamedParameterStepsViaParanamer();
         CandidateStep candidateStep = new CandidateStep("I live on the $ith floor but some call it the $nth",
         		NamedParameterStepsViaParanamer.methodFor("methodWithNamedParametersInNaturalOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
-        candidateStep.useParanamer(true);
+        candidateStep.useParanamer(paranamer);
         candidateStep.createFrom(tableValues, "When I live on the first floor but some call it the ground").perform();
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));
@@ -220,7 +225,7 @@
     	NamedParameterStepsViaParanamer steps = new NamedParameterStepsViaParanamer();
         CandidateStep candidateStep = new CandidateStep("I live on the $ith floor but some call it the $nth",
         		NamedParameterStepsViaParanamer.methodFor("methodWithNamedParametersInInverseOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
-        candidateStep.useParanamer(true);
+        candidateStep.useParanamer(paranamer);
         candidateStep.createFrom(tableValues, "When I live on the first floor but some call it the ground").perform();
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));
@@ -233,7 +238,7 @@
     	tableValues.put("nth", "ground");
         CandidateStep candidateStep = new CandidateStep("I live on the ith floor but some call it the nth",
         		NamedParameterStepsViaParanamer.methodFor("methodWithNamedParametersInNaturalOrder"), steps, PATTERN_BUILDER, MONITOR, new ParameterConverters(), "Given", "When", "Then");
-        candidateStep.useParanamer(true);
+        candidateStep.useParanamer(paranamer);
         candidateStep.createFrom(tableValues, "When I live on the <ith> floor but some call it the <nth>").perform();
         ensureThat(steps.ith, equalTo("first"));
         ensureThat(steps.nth, equalTo("ground"));

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java (1217 => 1218)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java	2009-09-05 08:37:10 UTC (rev 1217)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java	2009-09-05 09:06:08 UTC (rev 1218)
@@ -11,10 +11,9 @@
 import org.jbehave.scenario.annotations.Named;
 import org.jbehave.scenario.errors.PendingError;
 import org.jbehave.scenario.parser.StepPatternBuilder;
-import com.thoughtworks.paranamer.Paranamer;
+
 import com.thoughtworks.paranamer.NullParanamer;
-import com.thoughtworks.paranamer.CachingParanamer;
-import com.thoughtworks.paranamer.BytecodeReadingParanamer;
+import com.thoughtworks.paranamer.Paranamer;
 
 /**
  * Creates step from its candidate string representations
@@ -60,6 +59,10 @@
 		this.stepMonitor = stepMonitor;
 	}
 
+	public void useParanamer(Paranamer paranamer) {
+		this.paranamer = paranamer;
+	}
+
 	public boolean matches(String step) {
 		String word = findStartingWord(step);
 		if (word == null) {
@@ -243,12 +246,4 @@
 		return stepAsString;
 	}
 
-	public void useParanamer(boolean useIt) {
-		if (useIt) {
-			this.paranamer = new CachingParanamer(
-					new BytecodeReadingParanamer());
-		} else {
-			this.paranamer = new NullParanamer();
-		}
-	}
 }

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java (1217 => 1218)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java	2009-09-05 08:37:10 UTC (rev 1217)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java	2009-09-05 09:06:08 UTC (rev 1218)
@@ -133,7 +133,8 @@
         CandidateStep step = new CandidateStep(stepAsString, method, this, configuration
                 .getPatternBuilder(), configuration
                 .getParameterConverters(), configuration.getStartingWords());
-        step.useStepMonitor(configuration.getMonitor());
+        step.useStepMonitor(configuration.getMonitor());        
+        step.useParanamer(configuration.getParanamer());
         steps.add(step);
 	}
 

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

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	2009-09-05 08:37:10 UTC (rev 1217)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	2009-09-05 09:06:08 UTC (rev 1218)
@@ -3,6 +3,9 @@
 import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder;
 import org.jbehave.scenario.parser.StepPatternBuilder;
 
+import com.thoughtworks.paranamer.NullParanamer;
+import com.thoughtworks.paranamer.Paranamer;
+
 /**
  * <p>
  * Class allowing steps functionality to be fully configurable, while providing
@@ -23,6 +26,7 @@
 
 	private StepPatternBuilder patternBuilder;
 	private StepMonitor monitor;
+	private Paranamer paranamer;
 	private ParameterConverters parameterConverters;
 	private String[] startingWords;
 
@@ -32,23 +36,24 @@
 
 	public StepsConfiguration(String... startingWords) {
 		this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(),
-				new ParameterConverters(), startingWords);
+				new NullParanamer(), new ParameterConverters(), startingWords);
 	}
 
+	public StepsConfiguration(ParameterConverters converters) {
+		this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(),
+				new NullParanamer(), converters, DEFAULT_STARTING_WORDS);
+	}
+
 	public StepsConfiguration(StepPatternBuilder patternBuilder,
-			StepMonitor monitor, ParameterConverters parameterConverters,
-			String... startingWords) {
+			StepMonitor monitor, Paranamer paranamer,
+			ParameterConverters parameterConverters, String... startingWords) {
 		this.patternBuilder = patternBuilder;
 		this.monitor = monitor;
+		this.paranamer = paranamer;
 		this.parameterConverters = parameterConverters;
 		this.startingWords = startingWords;
 	}
 
-	public StepsConfiguration(ParameterConverters converters) {
-		this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(),
-				converters, DEFAULT_STARTING_WORDS);
-	}
-
 	public StepPatternBuilder getPatternBuilder() {
 		return patternBuilder;
 	}
@@ -65,6 +70,14 @@
 		this.monitor = monitor;
 	}
 
+	public Paranamer getParanamer() {
+		return paranamer;
+	}
+
+	public void useParanamer(Paranamer paranamer) {
+		this.paranamer = paranamer;
+	}
+
 	public ParameterConverters getParameterConverters() {
 		return parameterConverters;
 	}


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to