From 47aaf2fff190dbbf2524ce2ac1e4430d41070c80 Mon Sep 17 00:00:00 2001 From: Nils Wloka Date: Mon, 12 Mar 2012 14:02:59 +0100 Subject: [PATCH] Fixed StepDefinitionMatch to work with StepDefinitions that return null for getParameterTypes (e.g. ClojureStepDefinition) --- .../cucumber/runtime/clojure/cukes.feature | 5 +++++ .../resources/cucumber/runtime/clojure/stepdefs.clj | 3 +++ .../java/cucumber/runtime/StepDefinitionMatch.java | 13 ++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/clojure/src/test/resources/cucumber/runtime/clojure/cukes.feature b/clojure/src/test/resources/cucumber/runtime/clojure/cukes.feature index 89e8c751e3..3cf4a3ed42 100644 --- a/clojure/src/test/resources/cucumber/runtime/clojure/cukes.feature +++ b/clojure/src/test/resources/cucumber/runtime/clojure/cukes.feature @@ -2,3 +2,8 @@ Feature: Cukes Scenario: in the belly Given I have 4 cukes in my belly Then there are 4 cukes in my belly + + Scenario: in the belly (list) + Given I have this many cukes in my belly: + | 13 | + Then there are 13 cukes in my belly diff --git a/clojure/src/test/resources/cucumber/runtime/clojure/stepdefs.clj b/clojure/src/test/resources/cucumber/runtime/clojure/stepdefs.clj index 496666b159..afa0a34849 100644 --- a/clojure/src/test/resources/cucumber/runtime/clojure/stepdefs.clj +++ b/clojure/src/test/resources/cucumber/runtime/clojure/stepdefs.clj @@ -6,6 +6,9 @@ (Given #"^I have (\d+) cukes in my belly$" #(eat (Float. %1))) +(Given #"^I have this many cukes in my belly:$" + #(doseq [x (.raw %1)] (eat (Float. (first x))))) + (When #"^there are (\d+) cukes in my belly$" (fn [expected] (assert (= (last-meal) (Float. expected))))) diff --git a/core/src/main/java/cucumber/runtime/StepDefinitionMatch.java b/core/src/main/java/cucumber/runtime/StepDefinitionMatch.java index 341f6b27d5..d70abaaf10 100644 --- a/core/src/main/java/cucumber/runtime/StepDefinitionMatch.java +++ b/core/src/main/java/cucumber/runtime/StepDefinitionMatch.java @@ -142,9 +142,16 @@ private Object tableArgument(Step step, int argIndex, XStream xStream, String da } private Type getGenericListType(int argIndex) { - ParameterType parameterType = stepDefinition.getParameterTypes().get(argIndex); - Type[] actualTypeArguments = parameterType.getActualTypeArguments(); - return actualTypeArguments != null && actualTypeArguments.length > 0 ? actualTypeArguments[0] : null; + Type result = null; + List parameterTypes = stepDefinition.getParameterTypes(); + if (parameterTypes != null) { + ParameterType parameterType = parameterTypes.get(argIndex); + Type[] actualTypeArguments = parameterType.getActualTypeArguments(); + if (actualTypeArguments != null && actualTypeArguments.length > 0) { + result = actualTypeArguments[0]; + } + } + return result; } public Throwable removeFrameworkFramesAndAppendStepLocation(Throwable error, StackTraceElement stepLocation) {