java - org.jbehave.core.steps.Steps$DuplicateCandidateFound: THEN the result will be $expected -
i have below jbehave story file:
scenario: scene1 given number of <input> when result estimated result <expected> examples: |input|expected| |1|1| |2|1, 2| |3|1, 2, 3| |4|1, 2, 3, 4| scenario: scene2 given number of <input> when result estimated , result sorted in descending order result <expected> examples: |input|expected| |1|1| |2|2, 1| |3|3, 2, 1| |4|4, 3, 2, 1|
now wanted test both scenarios in program, have written below code:
import static org.junit.assert.assertequals; import java.util.list; import org.jbehave.core.annotations.given; import org.jbehave.core.annotations.then; import org.jbehave.core.annotations.when; public class estimatorsteps { private estimator estimator; @given("the number of $input") public void given(int input) { estimator = new estimator(input); } @when("the result estimated") public void when1() { estimator.estimate(estimator.getinput()); } @then("the result $expected) public void then1(list<integer> result) { assertequals(estimator.getresult(), result); } @when("the result sorted in descending order") public void when2() { estimator.descending(estimator.getresult()); } @then("the result $expected) public void then1(list<integer> result) { assertequals(estimator.getresult(), result); } }
when run test case, below error message:
org.jbehave.core.steps.steps$duplicatecandidatefound: result $expected
what right way test both cases, changes have in java code. not want change story file.
here jbehave configuration file:
import org.jbehave.core.configuration.configuration; import org.jbehave.core.configuration.mostusefulconfiguration; import org.jbehave.core.io.codelocations; import org.jbehave.core.io.loadfromclasspath; import org.jbehave.core.io.storyfinder; import org.jbehave.core.junit.junitstories; import org.jbehave.core.reporters.storyreporterbuilder; import org.jbehave.core.steps.injectablestepsfactory; import org.jbehave.core.steps.instancestepsfactory; import java.util.arrays; import java.util.list; import static org.jbehave.core.io.codelocations.codelocationfromclass; import static org.jbehave.core.reporters.storyreporterbuilder.format.console; public class jbehavestories extends junitstories { @override public configuration configuration() { return new mostusefulconfiguration().usestoryloader(new loadfromclasspath(this.getclass())) .usestoryreporterbuilder(new storyreporterbuilder() .withcodelocation(codelocationfromclass(this.getclass())).withformats(console)); } @override public injectablestepsfactory stepsfactory() { return new instancestepsfactory(configuration(), new estimatorsteps()); } @override protected list<string> storypaths() { return new storyfinder().findpaths(codelocations.codelocationfromclass(this.getclass()), arrays.aslist("**/*.story"), arrays.aslist("")); } }
there 2 identical @then steps in estimatorsteps
class:
@then("the result $expected) public void then1(list<integer> result) { assertequals(estimator.getresult(), result); } .... @then("the result $expected) public void then1(list<integer> result) { assertequals(estimator.getresult(), result); }
and jbehave complains:
duplicatecandidatefound: result $expected
remove 1 of these method , error not appear.
btw wonder how did class compile @ all, since java shouldn't allow 2 overloaded methods same signature.
Comments
Post a Comment