Search code examples
cucumber

How to map a Map of enum and String in Cucumber 7


I am using cucumber 7 and I have the following Then statement in my step definition file:

    @Then("^with the following Properties:$")
    public void with_the_following_Properties(Map<Gender, String> properties) {
       
    }

This gives me the following exception:

io.cucumber.core.exception.CucumberException: Could not convert arguments for step [^with the following properties:$] defined at 'com.test.glue.TestStepDefs.with_the_following_Properties(java.util.Map<com.test.Gender, java.lang.String>)'.
It appears you did not register a data table type.

    at io.cucumber.core.runner.PickleStepDefinitionMatch.registerDataTableTypeInConfiguration(PickleStepDefinitionMatch.java:96)

It seems only Map<String, String> is allowed.

Any suggestion(s).


Solution

  • I found a simple solution as below :

    @Then("^with the following Properties:$")
    public void with_the_following_Properties(Map<String, String> properties) {
       
      Map<Gender, String> map = new HashMap<>();
      properties.forEach((k, v) -> map.put(Gender.valueOf(k), v));
    }