Title: [1219] trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps: JBEHAVE-173: Added fine-grained monitoring of step arg lookup.

Diff

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

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java	2009-09-05 09:06:08 UTC (rev 1218)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java	2009-09-05 10:05:20 UTC (rev 1219)
@@ -4,6 +4,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -112,19 +113,29 @@
 		int parameterNameIndex = parameterIndex(parameterNames, index);
 		String arg = null;
 		if (annotatedNameIndex != -1 && isGroupName(annotationNames[index])) {
-			arg = getGroup(matcher, annotationNames[index]);
+			String name = annotationNames[index];
+			stepMonitor.usingAnnotatedName(name, index);
+			arg = getGroup(matcher, name);
 		} else if (parameterNameIndex != -1
 				&& isGroupName(parameterNames[index])) {
-			arg = getGroup(matcher, parameterNames[index]);
+			String name = parameterNames[index];
+			stepMonitor.usingParameterName(name, index);
+			arg = getGroup(matcher, name);
 		} else if (annotatedNameIndex != -1
 				&& isTableFieldName(tableValues, annotationNames[index])) {
-			arg = getTableValue(tableValues, annotationNames[index]);
+			String name = annotationNames[index];
+			stepMonitor.usingTableAnnotatedName(name, index);
+			arg = getTableValue(tableValues, name);
 		} else if (parameterNameIndex != -1
 				&& isTableFieldName(tableValues, parameterNames[index])) {
-			arg = getTableValue(tableValues, parameterNames[index]);
+			String name = parameterNames[index];
+			stepMonitor.usingTableParameterName(name, index);
+			arg = getTableValue(tableValues, name);
 		} else {
+			stepMonitor.usingNaturalOrder(index);
 			arg = matcher.group(index + 1);
 		}
+		stepMonitor.foundArg(arg, index);
 		return arg;
 	}
 
@@ -144,7 +155,7 @@
 				return matcher.group(i + 1);
 			}
 		}
-		throw new RuntimeException("no group for name");
+		throw new NoGroupFoundForNameException("No group found for name "+name+" amongst "+Arrays.asList(groupNames));
 	}
 
 	private boolean isGroupName(String name) {
@@ -245,5 +256,14 @@
 	public String toString() {
 		return stepAsString;
 	}
+	
+	@SuppressWarnings("serial")
+	public static class NoGroupFoundForNameException extends RuntimeException {
 
+		public NoGroupFoundForNameException(String message) {
+			super(message);
+		}
+
+	}
+
 }

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

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java	2009-09-05 09:06:08 UTC (rev 1218)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java	2009-09-05 10:05:20 UTC (rev 1219)
@@ -83,7 +83,7 @@
 				double.class, Float.class, float.class });
 
 		public boolean accept(Type type) {
-			if (type instanceof Class) {
+			if (type instanceof Class<?>) {
 				return acceptedClasses.contains(type);
 			}
 			return false;

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

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/PrintStreamStepMonitor.java	2009-09-05 09:06:08 UTC (rev 1218)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/PrintStreamStepMonitor.java	2009-09-05 10:05:20 UTC (rev 1219)
@@ -14,6 +14,10 @@
 	private static final String STEP_MATCHES_PATTERN = "Step ''{0}'' {1} pattern ''{2}''";
 	private static final String MATCHES = "matches";
 	private static final String DOES_NOT_MATCH = "does not match";
+	private static final String USING_NAME_FOR_INDEX = "Using {0} name {1} for index {2}";
+	private static final String USING_NATURAL_ORDER_FOR_INDEX = "Using natural order for index {0}";
+	private static final String FOUND_ARG_FOR_INDEX = "Found argument ''{0}'' for index {1}";
+
 	private final PrintStream output;
 
 	public PrintStreamStepMonitor() {
@@ -41,8 +45,39 @@
 		print(output, step);
 	}
 
+	public void usingAnnotatedName(String name, int index) {
+		String message = format(USING_NAME_FOR_INDEX, "annotated", name, index);
+		print(output, message);
+	}
+
+	public void usingParameterName(String name, int index) {
+		String message = format(USING_NAME_FOR_INDEX, "parameter", name, index);
+		print(output, message);		
+	}
+
+	public void usingTableAnnotatedName(String name, int index) {
+		String message = format(USING_NAME_FOR_INDEX, "table annotated", name, index);
+		print(output, message);		
+	}
+
+	public void usingTableParameterName(String name, int index) {
+		String message = format(USING_NAME_FOR_INDEX, "table parameter", name, index);
+		print(output, message);		
+	}
+
+	public void usingNaturalOrder(int index) {
+		String message = format(USING_NATURAL_ORDER_FOR_INDEX, index);
+		print(output, message);		
+	}
+
+	public void foundArg(String arg, int index) {
+		String message = format(FOUND_ARG_FOR_INDEX, arg, index);
+		print(output, message);		
+	}
+	
 	protected void print(PrintStream output, String message) {
 		output.println(message);
 	}
 
+
 }

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

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepMonitor.java	2009-09-05 09:06:08 UTC (rev 1218)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepMonitor.java	2009-09-05 10:05:20 UTC (rev 1219)
@@ -14,4 +14,16 @@
     void convertedValueOfType(String value, Type type, Object converted, Class<?> converterClass);
 
     void performing(String step);
+
+	void usingAnnotatedName(String name, int index);
+
+	void usingParameterName(String name, int index);
+
+	void usingTableAnnotatedName(String name, int index);
+
+	void usingTableParameterName(String name, int index);
+
+	void usingNaturalOrder(int index);
+
+	void foundArg(String arg, int index);
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to