- Revision
- 1000
- Author
- mauro
- Date
- 2008-10-29 03:28:33 -0500 (Wed, 29 Oct 2008)
Log Message
JBEHAVE-131: Added @Aliases annotation for steps. It assumes a @Given/@When/@Then annotation is present before it.
Modified Paths
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSteps.java
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepsBehaviour.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java
Added Paths
Diff
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSteps.java (999 => 1000)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSteps.java 2008-10-28 21:35:22 UTC (rev 999) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/TraderSteps.java 2008-10-29 08:28:33 UTC (rev 1000) @@ -10,6 +10,7 @@ import org.jbehave.examples.trader.model.Stock; import org.jbehave.examples.trader.model.Trader; import org.jbehave.examples.trader.persistence.TraderPersister; +import org.jbehave.scenario.annotations.Aliases; import org.jbehave.scenario.annotations.Given; import org.jbehave.scenario.annotations.Then; import org.jbehave.scenario.annotations.When; @@ -47,6 +48,7 @@ } @When("the stock is traded at %price") + @Aliases(values={"the stock is sold at %price"}) public void theStockIsTradedAt(double price) { stock.tradeAt(price); }
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario (999 => 1000)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario 2008-10-28 21:35:22 UTC (rev 999) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario 2008-10-29 08:28:33 UTC (rev 1000) @@ -1,5 +1,5 @@ Given a stock of prices 0.5,1.0 and a threshold of 10.0 When the stock is traded at 5.0 Then the alert status should be OFF -When the stock is traded at 11.0 +When the stock is sold at 11.0 Then the alert status should be ON
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepsBehaviour.java (999 => 1000)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepsBehaviour.java 2008-10-28 21:35:22 UTC (rev 999) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepsBehaviour.java 2008-10-29 08:28:33 UTC (rev 1000) @@ -14,11 +14,14 @@ public void shouldProvideCandidateStepsCorrespondingToAnnotatedSteps() { MySteps steps = new MySteps(); CandidateStep[] candidateSteps = steps.getSteps(); - ensureThat(candidateSteps.length, equalTo(3)); - + ensureThat(candidateSteps.length, equalTo(6)); + candidateSteps[0].createFrom("Given a given").perform(); - candidateSteps[1].createFrom("When a when").perform(); - candidateSteps[2].createFrom("Then a then").perform(); + candidateSteps[1].createFrom("Given a given alias").perform(); + candidateSteps[2].createFrom("When a when").perform(); + candidateSteps[3].createFrom("When a when alias").perform(); + candidateSteps[4].createFrom("Then a then").perform(); + candidateSteps[5].createFrom("Then a then alias").perform(); ensureThat(steps.given); ensureThat(steps.when); @@ -80,16 +83,19 @@ private boolean afterUnsuccess; @org.jbehave.scenario.annotations.Given("a given") + @org.jbehave.scenario.annotations.Aliases(values={"a given alias"}) public void given() { given = true; } @org.jbehave.scenario.annotations.When("a when") + @org.jbehave.scenario.annotations.Aliases(values={"a when alias"}) public void when() { when = true; } @org.jbehave.scenario.annotations.Then("a then") + @org.jbehave.scenario.annotations.Aliases(values={"a then alias"}) public void then() { then = true; }
Added: trunk/jbehave-core/src/java/org/jbehave/scenario/annotations/Aliases.java (0 => 1000)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/annotations/Aliases.java (rev 0) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/annotations/Aliases.java 2008-10-29 08:28:33 UTC (rev 1000) @@ -0,0 +1,14 @@ +package org.jbehave.scenario.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + [EMAIL PROTECTED](RetentionPolicy.RUNTIME) [EMAIL PROTECTED](ElementType.METHOD) +public @interface Aliases { + + String[] values(); + +}
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java (999 => 1000)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java 2008-10-28 21:35:22 UTC (rev 999) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java 2008-10-29 08:28:33 UTC (rev 1000) @@ -102,5 +102,10 @@ }; } + + @Override + public String toString() { + return pattern.pattern(); + } }
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java (999 => 1000)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2008-10-28 21:35:22 UTC (rev 999) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2008-10-29 08:28:33 UTC (rev 1000) @@ -11,6 +11,7 @@ import java.util.List; import org.jbehave.scenario.annotations.AfterScenario; +import org.jbehave.scenario.annotations.Aliases; import org.jbehave.scenario.annotations.BeforeScenario; import org.jbehave.scenario.annotations.Given; import org.jbehave.scenario.annotations.Then; @@ -110,22 +111,35 @@ for (Method method : stepsClass.getMethods()) { if (method.isAnnotationPresent(Given.class)) { createCandidateStep(steps, method, method.getAnnotation(Given.class).value()); + createCandidateStepsFromAliases(steps, method); } if (method.isAnnotationPresent(When.class)) { createCandidateStep(steps, method, method.getAnnotation(When.class).value()); + createCandidateStepsFromAliases(steps, method); } if (method.isAnnotationPresent(Then.class)) { createCandidateStep(steps, method, method.getAnnotation(Then.class).value()); + createCandidateStepsFromAliases(steps, method); } } return steps.toArray(new CandidateStep[steps.size()]); } - void createCandidateStep(List<CandidateStep> steps, Method method, String stepAsString) { + void createCandidateStep(List<CandidateStep> steps, Method method, String stepAsString) { steps.add(new CandidateStep(stepAsString, method, this, configuration.getPatternBuilder(), configuration .getMonitor(), configuration.getParameterConverters(), configuration.getStartingWords())); } + private void createCandidateStepsFromAliases(List<CandidateStep> steps, + Method method) { + if ( method.isAnnotationPresent(Aliases.class) ){ + String[] aliases = method.getAnnotation(Aliases.class).values(); + for ( String alias : aliases ){ + createCandidateStep(steps, method, alias); + } + } + } + public List<Step> runBeforeScenario() { return stepsHaving(BeforeScenario.class, new OkayToRun()); }
To unsubscribe from this list please visit:
