'Cucumber expression support for double NaN (in Java)

  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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1