Search in sources :

Example 11 with DataTable

use of io.cucumber.datatable.DataTable in project cucumber-jvm by cucumber.

the class JavaDataTableTypeDefinition method createDataTableType.

private DataTableType createDataTableType(Method method) {
    Type returnType = requireValidReturnType(method);
    Type parameterType = requireValidParameterType(method);
    if (DataTable.class.equals(parameterType)) {
        return new DataTableType(returnType, (DataTable table) -> invokeMethod(replaceEmptyPatternsWithEmptyString(table)));
    }
    if (List.class.equals(parameterType)) {
        return new DataTableType(returnType, (List<String> row) -> invokeMethod(replaceEmptyPatternsWithEmptyString(row)));
    }
    if (Map.class.equals(parameterType)) {
        return new DataTableType(returnType, (Map<String, String> entry) -> invokeMethod(replaceEmptyPatternsWithEmptyString(entry)));
    }
    if (String.class.equals(parameterType)) {
        return new DataTableType(returnType, (String cell) -> invokeMethod(replaceEmptyPatternsWithEmptyString(cell)));
    }
    throw createInvalidSignatureException(method);
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) DataTable(io.cucumber.datatable.DataTable) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) DataTableType(io.cucumber.datatable.DataTableType) List(java.util.List) Map(java.util.Map)

Aggregations

DataTable (io.cucumber.datatable.DataTable)11 List (java.util.List)5 Test (org.junit.jupiter.api.Test)4 Then (io.cucumber.java.en.Then)3 When (io.cucumber.java.en.When)3 StepDefinition (io.cucumber.core.backend.StepDefinition)2 Feature (io.cucumber.core.gherkin.Feature)2 DataTableType (io.cucumber.datatable.DataTableType)2 Account (io.syndesis.qe.account.Account)2 Method (java.lang.reflect.Method)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)1 EventBus (io.cucumber.core.eventbus.EventBus)1 CucumberException (io.cucumber.core.exception.CucumberException)1 Expression (io.cucumber.cucumberexpressions.Expression)1 ExpressionFactory (io.cucumber.cucumberexpressions.ExpressionFactory)1 UndefinedParameterTypeException (io.cucumber.cucumberexpressions.UndefinedParameterTypeException)1