- Revision
- 1243
- Author
- mauro
- Date
- 2009-09-13 06:23:39 -0500 (Sun, 13 Sep 2009)
Log Message
Refactored StepsConfiguration to derive the starting words from the KeyWords. The methods and constructors with explicit starting words should probably be deprecated as it likely to lead to inconsistencies and confusion, as in the i18n use case.
Modified Paths
Diff
Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java (1242 => 1243)
--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2009-09-13 10:17:50 UTC (rev 1242) +++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2009-09-13 11:23:39 UTC (rev 1243) @@ -10,8 +10,15 @@ import java.util.ArrayList; import java.util.List; -import org.jbehave.scenario.annotations.*; +import org.jbehave.scenario.annotations.AfterScenario; +import org.jbehave.scenario.annotations.Alias; +import org.jbehave.scenario.annotations.Aliases; +import org.jbehave.scenario.annotations.BeforeScenario; +import org.jbehave.scenario.annotations.Given; +import org.jbehave.scenario.annotations.Then; +import org.jbehave.scenario.annotations.When; import org.jbehave.scenario.annotations.AfterScenario.Outcome; +import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.errors.BeforeOrAfterScenarioException; import org.jbehave.scenario.reporters.ScenarioReporter; @@ -72,6 +79,18 @@ * Creates Steps with all default configuration except for custom starting * keywords * + * @param keywords + * the KeyWords which hold the words with which we expect steps in + * the scenarios to start + */ + public Steps(KeyWords keywords) { + this(new StepsConfiguration(keywords)); + } + + /** + * Creates Steps with all default configuration except for custom starting + * keywords + * * @param startingWords * the words with which we expect steps in the scenarios to start */ @@ -130,12 +149,13 @@ private void createCandidateStep(List<CandidateStep> steps, Method method, String stepAsString) { checkForDuplicateCandidateSteps(steps, stepAsString); - CandidateStep step = new CandidateStep(stepAsString, method, this, configuration - .getPatternBuilder(), configuration - .getParameterConverters(), configuration.getStartingWords()); - step.useStepMonitor(configuration.getMonitor()); - step.useParanamer(configuration.getParanamer()); - steps.add(step); + CandidateStep step = new CandidateStep(stepAsString, method, this, + configuration.getPatternBuilder(), configuration + .getParameterConverters(), configuration + .getStartingWords()); + step.useStepMonitor(configuration.getMonitor()); + step.useParanamer(configuration.getParanamer()); + steps.add(step); } private void checkForDuplicateCandidateSteps(List<CandidateStep> steps, @@ -156,7 +176,8 @@ } } if (method.isAnnotationPresent(Alias.class)) { - createCandidateStep(steps, method, method.getAnnotation(Alias.class).value()); + createCandidateStep(steps, method, method + .getAnnotation(Alias.class).value()); } } @@ -264,7 +285,8 @@ } @SuppressWarnings("serial") - public static class DuplicateCandidateStepFoundException extends RuntimeException { + public static class DuplicateCandidateStepFoundException extends + RuntimeException { public DuplicateCandidateStepFoundException(String message) { super(message);
Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java (1242 => 1243)
--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java 2009-09-13 10:17:50 UTC (rev 1242) +++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java 2009-09-13 11:23:39 UTC (rev 1243) @@ -1,5 +1,7 @@ package org.jbehave.scenario.steps; +import org.jbehave.scenario.definition.KeyWords; +import org.jbehave.scenario.i18n.I18nKeyWords; import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder; import org.jbehave.scenario.parser.StepPatternBuilder; @@ -21,39 +23,58 @@ */ public class StepsConfiguration { - public static final String[] DEFAULT_STARTING_WORDS = new String[] { - "Given", "When", "Then", "And" }; - private StepPatternBuilder patternBuilder; private StepMonitor monitor; private Paranamer paranamer; private ParameterConverters parameterConverters; + private KeyWords keywords; private String[] startingWords; public StepsConfiguration() { - this(DEFAULT_STARTING_WORDS); + this(new I18nKeyWords()); } - public StepsConfiguration(String... startingWords) { + public StepsConfiguration(KeyWords keywords) { this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), - new NullParanamer(), new ParameterConverters(), startingWords); + new NullParanamer(), new ParameterConverters(), keywords); } public StepsConfiguration(ParameterConverters converters) { this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), - new NullParanamer(), converters, DEFAULT_STARTING_WORDS); + new NullParanamer(), converters, new I18nKeyWords()); } public StepsConfiguration(StepPatternBuilder patternBuilder, StepMonitor monitor, Paranamer paranamer, + ParameterConverters parameterConverters, KeyWords keywords) { + this.patternBuilder = patternBuilder; + this.monitor = monitor; + this.paranamer = paranamer; + this.parameterConverters = parameterConverters; + this.keywords = keywords; + this.startingWords = startingWordsFrom(this.keywords); + } + + public StepsConfiguration(String... startingWords) { + this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), + new NullParanamer(), new ParameterConverters(), startingWords); + } + + public StepsConfiguration(StepPatternBuilder patternBuilder, + StepMonitor monitor, Paranamer paranamer, ParameterConverters parameterConverters, String... startingWords) { this.patternBuilder = patternBuilder; this.monitor = monitor; this.paranamer = paranamer; this.parameterConverters = parameterConverters; + this.keywords = new I18nKeyWords(); this.startingWords = startingWords; } + protected String[] startingWordsFrom(KeyWords keywords) { + return new String[]{keywords.given(), keywords.when(), keywords.then(), keywords.and()}; + } + public StepPatternBuilder getPatternBuilder() { return patternBuilder; } @@ -93,5 +114,14 @@ public void useStartingWords(String... startingWords) { this.startingWords = startingWords; } + + public KeyWords getKeywords() { + return keywords; + } + public void useKeyWords(KeyWords keywords) { + this.keywords = keywords; + this.startingWords = startingWordsFrom(this.keywords); + } + }
To unsubscribe from this list please visit:
