Skip to content

Add lambda equivalent for @ParameterType annotation #1764

@mpkorstanje

Description

@mpkorstanje

Summary

In #1677 @ParameterType , @DataTableType and various other annotations were introduced as an improvement over using the TypeRegistryConfigurer. However these annotations are part of cucumber-java. The lambda based cucumber-java8 module doesn't have an equivalent yet.

To make this possible additional methods have to be added to io.cucumber.java8.LambdaGlue as well as java 8 equivalents of the the Java.*Definition classes and some plumbing to register them with the glue .

Expected Behavior

Using @DataTableType rather then @ParameterType as an example

public class RpnCalculatorSteps implements En {

    public RpnCalculatorSteps() {

        DataTableType((Map<String, String> entry) -> new RpnCalculatorSteps.Entry(
            Integer.valueOf(entry.get("first")),
            Integer.valueOf(entry.get("second")),
            entry.get("operation")
        ));

        DataTableType((Map<String, String> row) -> new ShoppingSteps.Grocery(
            row.get("name"),
            ShoppingSteps.Price.fromString(row.get("price"))
        ));

    }
}

Current Behavior

Using @DataTableType rather then @ParameterType as an example

public class TypeRegistryConfiguration implements TypeRegistryConfigurer {

    @Override
    public Locale locale() {
        return ENGLISH;
    }

    @Override
    public void configureTypeRegistry(TypeRegistry typeRegistry) {
        typeRegistry.defineDataTableType(new DataTableType(
            RpnCalculatorSteps.Entry.class,
            (Map<String, String> row) -> new RpnCalculatorSteps.Entry(
                Integer.valueOf(row.get("first")),
                Integer.valueOf(row.get("second")),
                row.get("operation")
            )
        ));

        typeRegistry.defineDataTableType(new DataTableType(
            ShoppingSteps.Grocery.class,
            (Map<String, String> row) -> new ShoppingSteps.Grocery(
                row.get("name"),
                ShoppingSteps.Price.fromString(row.get("price"))
            )
        ));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions