Title: [1500] trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps: Refactored PicoEnabledCandidateStep to use ParameterConverters for String values.

Diff

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

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2010-01-06 14:39:18 UTC (rev 1499)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2010-01-06 15:12:07 UTC (rev 1500)
@@ -117,6 +117,7 @@
         verify(reporter).successful("Then I live on the 1st floor");
     }
 
+    @Test
     public void shouldConvertStringParameterValuesToUseSystemNewline() throws Exception {
         String windowsNewline = "\r\n";
         String unixNewline = "\n";

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

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java	2010-01-06 14:39:18 UTC (rev 1499)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java	2010-01-06 15:12:07 UTC (rev 1500)
@@ -35,7 +35,7 @@
     private final StepType stepType;
     private final Method method;
     protected final CandidateSteps steps;
-    private final ParameterConverters parameterConverters;
+    protected final ParameterConverters parameterConverters;
     private final Map<StepType, String> startingWordsByType;
     private final Pattern pattern;
     private final String[] groupNames;
@@ -137,7 +137,7 @@
             arg = getTableValue(tableRow, name);
         } else {
             stepMonitor.usingNaturalOrderForArg(position);
-            arg = matcher.group(position + 1);
+            arg = getGroup(matcher, position);
         }
         stepMonitor.foundArg(arg, position);
         return arg;
@@ -176,16 +176,16 @@
         for (int i = 0; i < groupNames.length; i++) {
             String groupName = groupNames[i];
             if (name.equals(groupName)) {
-                return dos2unix(matcher.group(i + 1));
+                return getGroup(matcher, i);
             }
         }
         throw new NoGroupFoundForName(name, groupNames);
     }
+
+	private String getGroup(Matcher matcher, int i) {
+		return matcher.group(i + 1);
+	}
     
-    private String dos2unix(String string) {
-        return string.replace("\r\n", "\n");
-    }
-
     private boolean isGroupName(String name) {
         for (String groupName : groupNames) {
             if (name.equals(groupName)) {

Modified: trunk/core/jbehave-pico/src/behaviour/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStepBehaviour.java (1499 => 1500)

--- trunk/core/jbehave-pico/src/behaviour/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStepBehaviour.java	2010-01-06 14:39:18 UTC (rev 1499)
+++ trunk/core/jbehave-pico/src/behaviour/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStepBehaviour.java	2010-01-06 15:12:07 UTC (rev 1500)
@@ -1,12 +1,39 @@
 package org.jbehave.scenario.steps.pico;
 
+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;
+import static org.jbehave.scenario.steps.StepType.THEN;
+import static org.jbehave.scenario.steps.StepType.WHEN;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.MethodDescriptor;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Named;
+
 import org.jbehave.scenario.annotations.Given;
 import org.jbehave.scenario.annotations.When;
 import org.jbehave.scenario.definition.ExamplesTable;
 import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder;
 import org.jbehave.scenario.parser.StepPatternBuilder;
 import org.jbehave.scenario.reporters.ScenarioReporter;
-import org.jbehave.scenario.steps.*;
+import org.jbehave.scenario.steps.CandidateStep;
+import org.jbehave.scenario.steps.ParameterConverters;
+import org.jbehave.scenario.steps.Step;
+import org.jbehave.scenario.steps.StepResult;
+import org.jbehave.scenario.steps.StepType;
+import org.jbehave.scenario.steps.Steps;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -17,28 +44,6 @@
 import org.picocontainer.containers.EmptyPicoContainer;
 import org.picocontainer.injectors.ConstructorInjection;
 
-import javax.inject.Named;
-
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.MethodDescriptor;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-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;
-import static org.jbehave.scenario.steps.StepType.THEN;
-import static org.jbehave.scenario.steps.StepType.WHEN;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
 public class PicoEnabledCandidateStepBehaviour {
 
     private static final StepPatternBuilder PATTERN_BUILDER = new PrefixCapturingPatternBuilder();
@@ -135,20 +140,20 @@
     }
 
     @Test
-    public void shouldConvertStringParameterValuesToUseUnixNewline() throws Exception {
-    	// conversion to system new line is done in ParameterConverters - still todo 
+    public void shouldConvertStringParameterValuesToUseSystemNewline() throws Exception {
         String windowsNewline = "\r\n";
         String unixNewline = "\n";
-        parent.as(Characteristics.USE_NAMES).addComponent(SomeSteps.class);
-        SomeSteps someSteps = parent.getComponent(SomeSteps.class);
-        PicoEnabledCandidateStep candidateStep = new PicoEnabledCandidateStep("the grid should look like $grid", THEN, SomeSteps.class.getMethod(
-				        "aMethodWith", String.class), someSteps, PATTERN_BUILDER, new ParameterConverters(), startingWords, parent);
+        String systemNewline = System.getProperty("line.separator");
+        SomeSteps someSteps = new SomeSteps(null);
+        CandidateStep candidateStep = new CandidateStep("the grid should look like $grid", THEN, SomeSteps.class.getMethod(
+				        "aMethodWith", String.class), someSteps, PATTERN_BUILDER, new ParameterConverters(), startingWords);
         Step step = candidateStep.createFrom(tableRow, "Then the grid should look like" + windowsNewline + ".." + unixNewline
                 + ".." + windowsNewline);
         step.perform();
-        ensureThat((String) someSteps.args, equalTo(".." + unixNewline + ".." + unixNewline));
+        ensureThat((String) someSteps.args, equalTo(".." + systemNewline + ".." + systemNewline));
     }
 
+
     @Test
     @Ignore
     public void shouldConvertArgsToListOfNumbers() throws Exception {

Modified: trunk/core/jbehave-pico/src/main/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStep.java (1499 => 1500)

--- trunk/core/jbehave-pico/src/main/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStep.java	2010-01-06 14:39:18 UTC (rev 1499)
+++ trunk/core/jbehave-pico/src/main/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStep.java	2010-01-06 15:12:07 UTC (rev 1500)
@@ -46,7 +46,8 @@
 
         // populate named entries from regex match
         for (String groupName : groupNames) {
-            stepContainer.addConfig(groupName, getGroup(matcher, groupName));
+        	String value = getGroup(matcher, groupName);
+			stepContainer.addConfig(groupName, parameterConverters.convert(value, String.class));
         }
 
         return new Step() {


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to