Cucumber expression support for double NaN (in Java)

Viewed 90
  Given Java is a language supporting Double.NaN
  Then cucumber's double expression should support 1.234 
  And cucumber's double expression should support NaN <<< FAIL

and

  @Given("cucumber's double expression should support {double}")
  public void check(double expected) {}

Is there a proper method to make this work with the builtins?

1 Answers

The easiest way is to introduce custom parameter like this:

public class StepDef {

    @ParameterType(".*")
    public Double doubleNaNable(String val){
        try{
            return Double.parseDouble(val);
        }catch (NumberFormatException e){
            return Double.NaN;
        }
    }

    @Given("Java is a language supporting Double.NaN")
    public void givenStep() {
        System.out.println("Java is a language supporting Double.NaN");
    }
    @Then("cucumber's double expression should support {doubleNaNable}")
    public void thenStep(double value) {
        System.out.println(value);
    }

}

More nice way is to add your text representation of NaN to regexp that captures double value from gherkin.

Related