Search code examples
javamigrationcucumber

Migrating Transformer from cucumber 2 to cucumber 7


I have a task here to upgrade from cucumber 2 to 7 and I managed to find everything but not how to migrate Transformer and @Transform code like bellow one:

import cucumber.api.Transformer;
import cucumber.runtime.java.guice.ScenarioScoped;
import java.util.Optional;

public class OptionalStringTransformer extends Transformer<Optional<String>> {
    @Override
    public Optional<String> transform(String s) {
        return Optional.ofNullable(s);
    }
}

@ScenarioScoped
public class StepDefinitions {
    @And("^Some ?(not)? step?$")
    public void someStep(@Transform(OptionalStringTransformer.class) Optional<String> example){
        // Step code
    }
}

Anyone know how to do it?


Solution

  • By now it is possible to use Optional<String> without any custom code.

      @And("^Some ?(not)? step?$")
      public void someStep(Optional<String> example){
        System.out.println(example);
      }
    

    Will print either Optional.empty or Optional[not].