Search in sources :

Example 6 with DataTableType

use of io.cucumber.datatable.DataTableType 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

DataTableType (io.cucumber.datatable.DataTableType)6 Test (org.junit.jupiter.api.Test)5 StepDefinition (io.cucumber.core.backend.StepDefinition)4 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)4 Feature (io.cucumber.core.gherkin.Feature)2 Step (io.cucumber.core.gherkin.Step)2 Argument (io.cucumber.core.stepexpression.Argument)2 StepExpression (io.cucumber.core.stepexpression.StepExpression)2 DataTable (io.cucumber.datatable.DataTable)2 List (java.util.List)2 Executable (org.junit.jupiter.api.function.Executable)2 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)1 CucumberException (io.cucumber.core.exception.CucumberException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Map (java.util.Map)1