- Revision
- 955
- Author
- mauro
- Date
- 2008-09-29 02:45:17 -0500 (Mon, 29 Sep 2008)
Log Message
JBEHAVE-134: Pulled up method to return candidate steps for an injected class, which may not be the implementing class.
Modified Paths
Diff
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateSteps.java (954 => 955)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateSteps.java 2008-09-29 07:27:09 UTC (rev 954) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateSteps.java 2008-09-29 07:45:17 UTC (rev 955) @@ -1,10 +1,22 @@ package org.jbehave.scenario.steps; /** - * Represents the set of candidate steps that can be performed + * Represents the list of candidate steps that can be performed */ public interface CandidateSteps { + /** + * Return all the steps that can be performed by the implementing class + * + * @return The list of candidate steps + */ CandidateStep[] getSteps(); + /** + * Return all the steps that can be performed by the given class + * + * @return The list of candidate steps + */ + CandidateStep[] getSteps(Class<?> stepsClass); + }
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java (954 => 955)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2008-09-29 07:27:09 UTC (rev 954) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2008-09-29 07:45:17 UTC (rev 955) @@ -20,28 +20,34 @@ * '$' prefix to pick up parameters. * </p> * <p> - * For instance, you could define a method as: + * For instance, you could define a method as: + * * <pre> - * <code lang="java"> - * @When("I log in as $username with password: $password") <br/> + * <code lang="java"> + * @When("I log in as $username with password: $password") <br/> * public void logIn(String username, String password) { //... } - * </code> + * </code> * </pre> + * * and this would match the step: + * * <pre> * When I log in as Liz with password: Pa55word * </pre> + * * </p> - * <p>When the step is perfomed, the parameters in the scenario - * definition will be passed to the class, so in this case the - * effect will be + * <p> + * When the step is perfomed, the parameters in the scenario definition will be + * passed to the class, so in this case the effect will be + * * <pre> * mySteps.logIn("Liz", "Pa55word"); * </pre> + * * </p> * <p> - * StepsConfiguration can be used to provide customization to the defaults configuration - * elements, eg custom parameters converters. + * StepsConfiguration can be used to provide customization to the defaults + * configuration elements, eg custom parameters converters. * </p> */ public class Steps implements CandidateSteps { @@ -75,12 +81,13 @@ this.configuration = configuration; } - /** - * @return all the steps that can be performed by this class - */ public CandidateStep[] getSteps() { + return getSteps(this.getClass()); + } + + public CandidateStep[] getSteps(Class<?> stepsClass) { List<CandidateStep> steps = new ArrayList<CandidateStep>(); - for (Method method : this.getClass().getMethods()) { + for (Method method : stepsClass.getMethods()) { if (method.isAnnotationPresent(Given.class)) { createCandidateStep(steps, method, method.getAnnotation(Given.class).value()); } @@ -94,7 +101,7 @@ return steps.toArray(new CandidateStep[steps.size()]); } - private 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())); }
To unsubscribe from this list please visit:
