use of gherkin.formatter.Argument in project cucumber-jvm by cucumber.
the class StepDefinitionMatch method transformedArgs.
/**
* @param step the step to run
* @param xStream used to convert a string to declared stepdef arguments
* @return an Array matching the types or {@code parameterTypes}, or an array of String if {@code parameterTypes} is null
*/
private Object[] transformedArgs(Step step, LocalizedXStreams.LocalizedXStream xStream) {
int argumentCount = getArguments().size();
if (step.getRows() != null) {
argumentCount++;
} else if (step.getDocString() != null) {
argumentCount++;
}
Integer parameterCount = stepDefinition.getParameterCount();
if (parameterCount != null && argumentCount != parameterCount) {
throw arityMismatch(parameterCount);
}
List<Object> result = new ArrayList<Object>();
int n = 0;
for (Argument a : getArguments()) {
ParameterInfo parameterInfo = getParameterType(n, String.class);
Object arg = parameterInfo.convert(a.getVal(), xStream);
result.add(arg);
n++;
}
if (step.getRows() != null) {
result.add(tableArgument(step, n, xStream));
} else if (step.getDocString() != null) {
ParameterInfo parameterInfo = getParameterType(n, String.class);
Object arg = parameterInfo.convert(step.getDocString().getValue(), xStream);
result.add(arg);
}
return result.toArray(new Object[result.size()]);
}
use of gherkin.formatter.Argument in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method gives_nice_error_message_when_conversion_fails.
@Test
public void gives_nice_error_message_when_conversion_fails() throws Throwable {
StepDefinition stepDefinition = mock(StepDefinition.class);
when(stepDefinition.getParameterCount()).thenReturn(1);
when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Thang.class, null, null, null));
Step stepWithoutDocStringOrTable = mock(Step.class);
when(stepWithoutDocStringOrTable.getDocString()).thenReturn(null);
when(stepWithoutDocStringOrTable.getRows()).thenReturn(null);
StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(Arrays.asList(new Argument(0, "blah")), stepDefinition, "some.feature", stepWithoutDocStringOrTable, new LocalizedXStreams(classLoader));
try {
stepDefinitionMatch.runStep(ENGLISH);
fail();
} catch (CucumberException expected) {
assertEquals("Don't know how to convert \"blah\" into cucumber.runtime.StepDefinitionMatchTest$Thang.\n" + "Try writing your own converter:\n" + "\n" + "@cucumber.deps.com.thoughtworks.xstream.annotations.XStreamConverter(ThangConverter.class)\n" + "public class Thang {}\n", expected.getMessage());
}
}
Aggregations