Title: [1392] trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps: JBEHAVE-211: Applied patch from Cyril Ledru.
Revision
1392
Author
mauro
Date
2009-11-26 03:01:43 -0600 (Thu, 26 Nov 2009)

Log Message

JBEHAVE-211:  Applied patch from Cyril Ledru.  

Modified Paths

Diff

Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ParameterConvertersBehaviour.java (1391 => 1392)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ParameterConvertersBehaviour.java	2009-11-25 19:50:44 UTC (rev 1391)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ParameterConvertersBehaviour.java	2009-11-26 09:01:43 UTC (rev 1392)
@@ -10,6 +10,7 @@
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.text.ParseException;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -70,6 +71,31 @@
 		ensureThat(list.get(3), equalTo(numberFormat.parse("8.00")));
 	}
 	
+	@Test
+	public void shouldConvertCommaSeparatedValuesToListOfStrings() throws IntrospectionException {
+		ParameterConverters converters = new ParameterConverters();
+		Type type = SomeSteps.methodFor("aMethodWithListOfStrings")
+				.getGenericParameterTypes()[0];
+        List<String> emptyList = Arrays.asList("a", "string");
+        ensureValueIsConvertedToEmptyList(converters, type, "a, string ", emptyList);
+	}
+	
+	@Test
+	public void shouldConvertEmptyStringToEmptyListOfStrings() throws IntrospectionException {
+		ParameterConverters converters = new ParameterConverters();
+		Type type = SomeSteps.methodFor("aMethodWithListOfStrings")
+				.getGenericParameterTypes()[0];
+        List<String> emptyList = Arrays.asList();
+        ensureValueIsConvertedToEmptyList(converters, type, "", emptyList);
+        ensureValueIsConvertedToEmptyList(converters, type, " ", emptyList);
+	}
+
+    @SuppressWarnings("unchecked")
+    private void ensureValueIsConvertedToEmptyList(ParameterConverters converters, Type type, String value, List<String> expected) {
+        List<String> list = (List<String>) converters.convert(value, type);
+        ensureThat(list.size(), equalTo(expected.size()));
+    }
+	
     @Test
     public void shouldConvertMultilineTableParameter()
             throws ParseException, IntrospectionException {

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java (1391 => 1392)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java	2009-11-25 19:50:44 UTC (rev 1391)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java	2009-11-26 09:01:43 UTC (rev 1392)
@@ -179,6 +179,7 @@
 		}
 
 		public Object convertValue(String value, Type type) {
+			if (value.trim().length() == 0) return asList();
 			return trim(asList(value.split(valueSeparator)));
 		}
 


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to