use of cucumber.api.java8.StepdefBody in project cucumber-jvm by cucumber.
the class Java8StepDefinition method getParameterInfos.
private List<ParameterInfo> getParameterInfos(Class<? extends StepdefBody> bodyClass, TypeIntrospector typeIntrospector, int parameterCount) throws Exception {
Type genericInterface = bodyClass.getGenericInterfaces()[0];
Type[] argumentTypes;
if (genericInterface instanceof ParameterizedType) {
argumentTypes = ((ParameterizedType) genericInterface).getActualTypeArguments();
} else {
Class<? extends StepdefBody> interfac3 = (Class<? extends StepdefBody>) bodyClass.getInterfaces()[0];
argumentTypes = typeIntrospector.getGenericTypes(bodyClass, interfac3);
}
Type[] argumentTypesOfCorrectLength = new Type[parameterCount];
System.arraycopy(argumentTypes, argumentTypes.length - parameterCount, argumentTypesOfCorrectLength, 0, parameterCount);
verifyNotListOrMap(argumentTypesOfCorrectLength);
return ParameterInfo.fromTypes(argumentTypesOfCorrectLength);
}
use of cucumber.api.java8.StepdefBody in project cucumber-jvm by cucumber.
the class Java8StepDefinitionTest method should_pass_for_param_with_generic_list.
@Test
public void should_pass_for_param_with_generic_list() throws Exception {
try {
StepdefBody body = (StepdefBody.A1<List<String>>) p1 -> {
};
new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, body, typeIntrospector);
} catch (CucumberException expected) {
assertEquals("Can't use java.util.List in lambda step definition. Declare a DataTable argument instead and convert manually with asList/asLists/asMap/asMaps", expected.getMessage());
}
}
use of cucumber.api.java8.StepdefBody in project cucumber-jvm by cucumber.
the class Java8StepDefinitionTest method should_calculate_parameters_count_from_body_with_one_param.
@Test
public void should_calculate_parameters_count_from_body_with_one_param() throws Exception {
StepdefBody body = (StepdefBody.A1<String>) p1 -> {
};
Java8StepDefinition def = new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, body, typeIntrospector);
assertEquals(new Integer(1), def.getParameterCount());
}
use of cucumber.api.java8.StepdefBody in project cucumber-jvm by cucumber.
the class Java8StepDefinitionTest method should_fail_for_param_with_non_generic_list.
@Test
public void should_fail_for_param_with_non_generic_list() throws Exception {
try {
StepdefBody body = (StepdefBody.A1<List>) p1 -> {
};
new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, body, typeIntrospector);
} catch (CucumberException expected) {
assertEquals("Can't use java.util.List in lambda step definition. Declare a DataTable argument instead and convert manually with asList/asLists/asMap/asMaps", expected.getMessage());
}
}
use of cucumber.api.java8.StepdefBody in project cucumber-jvm by cucumber.
the class Java8StepDefinitionTest method should_calculate_parameters_count_from_body_with_two_params.
@Test
public void should_calculate_parameters_count_from_body_with_two_params() throws Exception {
StepdefBody body = (StepdefBody.A2<String, String>) (p1, p2) -> {
};
Java8StepDefinition def = new Java8StepDefinition(Pattern.compile("^I have some step $"), 0, body, typeIntrospector);
assertEquals(new Integer(2), def.getParameterCount());
}
Aggregations