- Revision
- 906
- Author
- sirenian
- Date
- 2008-08-30 02:53:24 -0500 (Sat, 30 Aug 2008)
Log Message
[Liz] Some more javadocs, started examples for ParameterConverters
Modified Paths
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java
- trunk/jbehave-core/src/java/org/jbehave/Configuration.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/MostUsefulConfiguration.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java
Added Paths
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ParameterConvertersBehaviour.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/errors/PendingErrorStrategy.java
Removed Paths
Diff
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java (905 => 906)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java 2008-08-30 07:53:24 UTC (rev 906) @@ -6,9 +6,9 @@ import org.jbehave.scenario.definition.ScenarioGivenWhenThenAnd; import org.jbehave.scenario.errors.ErrorStrategy; +import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.reporters.PassSilentlyDecorator; import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; -import org.jbehave.scenario.steps.PendingStepStrategy; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -41,13 +41,13 @@ @Test public void shouldUsePassingPendingStepStrategyByDefault() { System.clearProperty(PropertyBasedConfiguration.FAIL_ON_PENDING); - ensureThat(new PropertyBasedConfiguration().forPendingSteps(), is(PendingStepStrategy.PASSING)); + ensureThat(new PropertyBasedConfiguration().forPendingSteps(), is(PendingErrorStrategy.PASSING)); } @Test public void shouldUseFailingPendingStepStrategyWhenConfiguredToDoSo() { System.setProperty(PropertyBasedConfiguration.FAIL_ON_PENDING, "true"); - ensureThat(new PropertyBasedConfiguration().forPendingSteps(), is(PendingStepStrategy.FAILING)); + ensureThat(new PropertyBasedConfiguration().forPendingSteps(), is(PendingErrorStrategy.FAILING)); } @Test
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java (905 => 906)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java 2008-08-30 07:53:24 UTC (rev 906) @@ -10,9 +10,9 @@ import org.jbehave.scenario.definition.Blurb; import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.errors.ErrorStrategy; +import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.parser.ScenarioDefiner; import org.jbehave.scenario.reporters.ScenarioReporter; -import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.StepCreator; import org.jbehave.scenario.steps.Steps; import org.junit.Test; @@ -58,7 +58,7 @@ public ErrorStrategy forHandlingErrors() { return null; } - public PendingStepStrategy forPendingSteps() { return null; } + public PendingErrorStrategy forPendingSteps() { return null; } public ScenarioReporter forReportingScenarios() { return null; }
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java (905 => 906)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java 2008-08-30 07:53:24 UTC (rev 906) @@ -12,9 +12,9 @@ import org.jbehave.scenario.definition.Blurb; import org.jbehave.scenario.errors.ErrorStrategy; import org.jbehave.scenario.errors.ErrorStrategyInWhichWeTrustTheReporter; +import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.reporters.ScenarioReporter; import org.jbehave.scenario.steps.CandidateStep; -import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.Step; import org.jbehave.scenario.steps.StepCreator; import org.jbehave.scenario.steps.StepResult; @@ -190,7 +190,7 @@ StepResult pendingResult = StepResult.pending("My step isn't defined!"); stub(pendingStep.perform()).toReturn(pendingResult); - PendingStepStrategy strategy = mock(PendingStepStrategy.class); + PendingErrorStrategy strategy = mock(PendingErrorStrategy.class); StepCreator creator = mock(StepCreator.class); Steps mySteps = mock(Steps.class); @@ -205,7 +205,7 @@ private Configuration configurationWithPendingStrategy(StepCreator creator, - ScenarioReporter reporter, PendingStepStrategy strategy) { + ScenarioReporter reporter, PendingErrorStrategy strategy) { return configurationWith(reporter, creator, new ErrorStrategyInWhichWeTrustTheReporter(), strategy); } @@ -216,14 +216,14 @@ private Configuration configurationWith(final ScenarioReporter reporter, final StepCreator creator, final ErrorStrategy errorStrategy) { - return configurationWith(reporter, creator, errorStrategy, PendingStepStrategy.PASSING); + return configurationWith(reporter, creator, errorStrategy, PendingErrorStrategy.PASSING); } private Configuration configurationWith( final ScenarioReporter reporter, final StepCreator creator, final ErrorStrategy errorStrategy, - final PendingStepStrategy pendingStrategy) { + final PendingErrorStrategy pendingStrategy) { return new PropertyBasedConfiguration() { @Override @@ -233,7 +233,7 @@ @Override public ErrorStrategy forHandlingErrors() { return errorStrategy; } @Override - public PendingStepStrategy forPendingSteps() { return pendingStrategy; } + public PendingErrorStrategy forPendingSteps() { return pendingStrategy; } }; }
Added: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ParameterConvertersBehaviour.java (0 => 906)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ParameterConvertersBehaviour.java (rev 0) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/ParameterConvertersBehaviour.java 2008-08-30 07:53:24 UTC (rev 906) @@ -0,0 +1,33 @@ +package org.jbehave.scenario.steps; + +import static org.jbehave.Ensure.ensureThat; +import static org.hamcrest.CoreMatchers.equalTo; + +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Test; + +public class ParameterConvertersBehaviour { + + @Test + public void shouldConvertStringsToNumbers() { + ParameterConverters converters = new ParameterConverters(); + ensureThat((Integer)converters.convert("3", int.class), equalTo(3)); + } + +// @SuppressWarnings("unchecked") +// @Test +// public void shouldConvertCommaSeparatedValuesToListsOfNumbers() throws ParseException { +// ParameterConverters converters = new ParameterConverters(); +// List<Number> list = (List<Number>)converters.convert("3, 5, 6, 8.00", Arrays.asList(new Number[]{}).getClass()); +// ensureThat(list.get(0), equalTo(NumberFormat.getInstance().parse("3"))); +// ensureThat(list.get(1), equalTo(NumberFormat.getInstance().parse("5"))); +// ensureThat(list.get(2), equalTo(NumberFormat.getInstance().parse("6"))); +// ensureThat(list.get(3), equalTo(NumberFormat.getInstance().parse("8.00"))); +// } +}
Modified: trunk/jbehave-core/src/java/org/jbehave/Configuration.java (905 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/Configuration.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/java/org/jbehave/Configuration.java 2008-08-30 07:53:24 UTC (rev 906) @@ -2,9 +2,9 @@ import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.errors.ErrorStrategy; +import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.parser.ScenarioDefiner; import org.jbehave.scenario.reporters.ScenarioReporter; -import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.StepCreator; /** @@ -27,7 +27,7 @@ ScenarioReporter forReportingScenarios(); - PendingStepStrategy forPendingSteps(); + PendingErrorStrategy forPendingSteps(); StepCreator forCreatingSteps();
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/MostUsefulConfiguration.java (905 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/MostUsefulConfiguration.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/MostUsefulConfiguration.java 2008-08-30 07:53:24 UTC (rev 906) @@ -4,13 +4,13 @@ import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.definition.ScenarioGivenWhenThenAnd; import org.jbehave.scenario.errors.ErrorStrategy; +import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.parser.PatternScenarioParser; import org.jbehave.scenario.parser.ScenarioDefiner; import org.jbehave.scenario.parser.ScenarioFileLoader; import org.jbehave.scenario.reporters.PassSilentlyDecorator; import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; import org.jbehave.scenario.reporters.ScenarioReporter; -import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.StepCreator; import org.jbehave.scenario.steps.UnmatchedToPendingStepCreator; @@ -59,8 +59,8 @@ * PropertyBasedConfiguration which provides a mechanism for * altering this behaviour in different environments. */ - public PendingStepStrategy forPendingSteps() { - return PendingStepStrategy.PASSING; + public PendingErrorStrategy forPendingSteps() { + return PendingErrorStrategy.PASSING; } /**
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java (905 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java 2008-08-30 07:53:24 UTC (rev 906) @@ -3,10 +3,10 @@ import org.jbehave.Configuration; import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.errors.ErrorStrategy; +import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.parser.ScenarioDefiner; import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; import org.jbehave.scenario.reporters.ScenarioReporter; -import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.StepCreator; /** @@ -61,11 +61,11 @@ * so you can see if any steps don't match or are * still to be implemented. */ - public PendingStepStrategy forPendingSteps() { + public PendingErrorStrategy forPendingSteps() { if (System.getProperty(FAIL_ON_PENDING) == null) { return defaults.forPendingSteps(); } - return PendingStepStrategy.FAILING; + return PendingErrorStrategy.FAILING; } /**
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java (905 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java 2008-08-30 07:53:24 UTC (rev 906) @@ -3,8 +3,8 @@ import org.jbehave.Configuration; import org.jbehave.scenario.errors.ErrorStrategy; import org.jbehave.scenario.errors.PendingError; +import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.reporters.ScenarioReporter; -import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.Step; import org.jbehave.scenario.steps.StepResult; import org.jbehave.scenario.steps.Steps; @@ -19,7 +19,7 @@ private State state = new FineSoFar(); private ErrorStrategy currentStrategy; - private PendingStepStrategy pendingStepStrategy; + private PendingErrorStrategy pendingStepStrategy; private ScenarioReporter reporter; private ErrorStrategy errorStrategy; private Throwable throwable;
Copied: trunk/jbehave-core/src/java/org/jbehave/scenario/errors/PendingErrorStrategy.java (from rev 901, trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java) (0 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/errors/PendingErrorStrategy.java (rev 0) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/errors/PendingErrorStrategy.java 2008-08-30 07:53:24 UTC (rev 906) @@ -0,0 +1,15 @@ +package org.jbehave.scenario.errors; + + +public interface PendingErrorStrategy extends ErrorStrategy { + + PendingErrorStrategy PASSING = new PendingErrorStrategy() { + public void handleError(Throwable throwable) {} + }; + + PendingErrorStrategy FAILING = new PendingErrorStrategy() { + public void handleError(Throwable throwable) throws Throwable { + throw throwable; + } + }; +}
Property changes: trunk/jbehave-core/src/java/org/jbehave/scenario/errors/PendingErrorStrategy.java
Name: svn:mergeinfo
+
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java (905 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ParameterConverters.java 2008-08-30 07:53:24 UTC (rev 906) @@ -7,6 +7,7 @@ import java.text.NumberFormat; import java.text.ParseException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -68,11 +69,14 @@ } private static class NumberConverter implements ParameterConverter { - + private static List<Class> acceptedClasses = Arrays.asList(new Class[] { + Integer.class, int.class, Long.class, long.class, + Double.class, double.class, Float.class, float.class + }); + public boolean accept(Type type) { if (type instanceof Class) { - return (type == Integer.class || type == int.class || type == Long.class || type == long.class - || type == Double.class || type == double.class || type == Float.class || type == float.class); + return acceptedClasses.contains(type); } return false; }
Deleted: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java (905 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java 2008-08-30 07:53:24 UTC (rev 906) @@ -1,16 +0,0 @@ -package org.jbehave.scenario.steps; - -import org.jbehave.scenario.errors.ErrorStrategy; - -public interface PendingStepStrategy extends ErrorStrategy { - - PendingStepStrategy PASSING = new PendingStepStrategy() { - public void handleError(Throwable throwable) {} - }; - - PendingStepStrategy FAILING = new PendingStepStrategy() { - public void handleError(Throwable throwable) throws Throwable { - throw throwable; - } - }; -}
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java (905 => 906)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2008-08-29 16:59:28 UTC (rev 905) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/Steps.java 2008-08-30 07:53:24 UTC (rev 906) @@ -9,6 +9,38 @@ import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder; import org.jbehave.scenario.parser.StepPatternBuilder; +/** + * Extend this class to provide the definition of steps that + * match the scenario you want to run. + * + * <p>You can define the methods that should be run when each step + * is performed by annotating them with @Given, @When or @Then, + * and providing a value for each annotation that matches the + * step. By default, the match is performed using a '$' prefix + * to pick up parameters. + * + * <p>For instance, you could define a method as: + * + * <p><code lang="java"> + * @When(" I log in as $username with password: $password") + * public void logIn(String username, String password) { + * //... + * } + * </code> + * + * <p>and this would match the step: + * + * <p><code>When I log in as Liz with password: Pa55word</code> + * + * <p>When the step is perfomed, the two parameters in the scenario definition + * will be passed to the class, so in this case the effect will be + * + * <p><code>mySteps.logIn("Liz", "Pa55word");</code> + * + * <p>ParameterConverters can be used to convert parameters from any String format + * to another class. Custom converters can be provided here in addition to the + * defaults. + */ public class Steps { private final StepPatternBuilder patternBuilder; @@ -25,6 +57,12 @@ this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(), new ParameterConverters(), startingWords); } + /** + * @param patternBuilder how we build patterns from annotations which will match the steps in the scenarios + * @param stepMonitor how we monitor the matching of the patterns + * @param parameterConverters how we convert parameters from Strings to other objects + * @param startingWords the words with which we expect steps in the scenarios to start + */ public Steps(StepPatternBuilder patternBuilder, StepMonitor stepMonitor, ParameterConverters parameterConverters, String... startingWords) { this.patternBuilder = patternBuilder; @@ -34,7 +72,7 @@ } /** - * Returns all the steps that can be performed by this class. + * @return all the steps that can be performed by this class */ public CandidateStep[] getSteps() { ArrayList<CandidateStep> steps = new ArrayList<CandidateStep>();
To unsubscribe from this list please visit:
