If the following is true:
Hence, you cannot use it in conjunction with the normal parameter matching, which uses natural ordering.
...then isn't the documentation at http://jbehave.org/reference/stable/parameter-injection.html wrong? It states:
One reason to use named parameters is that then we can have method parameter appearing in any order:
@Given("a stock of symbol $symbol and a threshold of $threshold")
public void aStock(@Named("threshold") double aThreshold, @Named("symbol") String aSymbol) {
}
I'm seeing the same issue when using slightly complicated regexs, such as a regex in which the parameters are not surrounded with whitespace.
For example, no issues, even though not all parameters are surrounded by whitespace:
@Given("I have $a and $b")
public void givenAAndB(String myA, String myB) {
LOG.info("given A={}, B={}", myA, myB);
assertThat(myA).isEqualTo("1st");
assertThat(myB).isEqualTo("2nd");
}
@When("doing $a, and $b")
public void whenAAndB(@Named("a") String myA, @Named("b") String myB) {
LOG.info("when A={}, B={}", myA, myB);
assertThat(myA).isEqualTo("this");
assertThat(myB).isEqualTo("that");
}
@Then("we have $a or $b")
public void thenAOrdB(@Named("b") String myB, @Named("a") String myA) {
LOG.info("then A={}, B={}", myA, myB);
assertThat(myA).isEqualTo("success");
assertThat(myB).isEqualTo("failure");
}
...but, troublesome when named parameters are not in the natural order, and not all parameters are fully surrounded with whitespace:
@Then("we have $a, $b")
public void thenACommaB(@Named("b") String myB, @Named("a") String myA) {
assertThat(myA).isEqualTo("a problem");
assertThat(myB).isEqualTo("Houston");
}
...with
Given I have 1st and 2nd
When doing this, and that
Then we have success or failure
And we have a problem, Houston
...I get:
Failed to run story login.story
org.junit.ComparisonFailure: expected:<'[a problem]'> but was:<'[Houston]'>
So it seems that parameters always need to be surrounded by whitespace?
(It's not so much an issue that a test would fail with PENDING, but silently falling back to the natural order doesn't seem to nice to me.)
The @Named annotation is intended for use with parameterised scenarios (http://jbehave.org/reference/stable/parametrised-scenarios.html).
Hence, you cannot use it in conjunction with the normal parameter matching, which uses natural ordering.
Have a look at the trader example module for uses of the @Named annotation.