- Revision
- 883
- Author
- sirenian
- Date
- 2008-08-18 13:34:12 -0500 (Mon, 18 Aug 2008)
Log Message
[Liz] Pending exceptions can now be made to fail the build, and steps can be made partially pending by throwing PendingError
Modified Paths
- trunk/build.xml
- trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/players_can_take_turns
- trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/steps/GridSteps.java
- trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/three_in_a_row_wins
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertCanBeActivated.java
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertIsNeverActivated.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/behaviour/org/jbehave/scenario/parser/scenarios/MyMultipleScenario.java
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/scenarios/MyPendingScenario.java
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepResultBehaviour.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/Scenario.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioReporter.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStep.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepResult.java
Added Paths
- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java
- trunk/jbehave-core/src/java/org/jbehave/Configuration.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ErrorStrategy.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingError.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java
Removed Paths
Diff
Modified: trunk/build.xml (882 => 883)
--- trunk/build.xml 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/build.xml 2008-08-18 18:34:12 UTC (rev 883) @@ -22,7 +22,7 @@ <property name="jbehave.zip" location="${working.dir}/jbehave-${version}.zip" /> <property name="dist.dir" location="${working.dir}/${version}" /> <property name="jbehave.jar" location="${dist.dir}/jbehave-${version}.jar" /> - <property name="jbehave.src.zip" location="${dist.dir}/jbehave-${version}-src.zip" /> + <property name="jbehave.src.jar" location="${dist.dir}/jbehave-${version}-src.jar" /> <property name="website.dist.dir" location="${dist.dir}/website" /> <property name="javadoc.dist.dir" location="${website.dist.dir}/javadoc/${version}" /> @@ -191,6 +191,7 @@ description="Produces a jar file in the distribution directory." depends="jbehave-classes"> <jar basedir="${jbehave.classes}" jarfile="${jbehave.jar}" /> + <jar basedir="${jbehave.source}" jarfile="${jbehave.src.jar}" /> </target> <target name="jbehave-src-zip" description="Assembles the source jar.">
Modified: trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/players_can_take_turns (882 => 883)
--- trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/players_can_take_turns 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/players_can_take_turns 2008-08-18 18:34:12 UTC (rev 883) @@ -17,4 +17,3 @@ Then the grid should look like XO. ... -...
Modified: trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/steps/GridSteps.java (882 => 883)
--- trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/steps/GridSteps.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/steps/GridSteps.java 2008-08-18 18:34:12 UTC (rev 883) @@ -13,6 +13,7 @@ import org.jbehave.scenario.annotations.Given; import org.jbehave.scenario.annotations.Then; import org.jbehave.scenario.annotations.When; +import org.jbehave.scenario.steps.PendingError; import org.jbehave.scenario.steps.Steps; import org.lunivore.tyburn.WindowControl;
Modified: trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/three_in_a_row_wins (882 => 883)
--- trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/three_in_a_row_wins 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/examples/noughtsandcrosses/src/scenario/com/lunivore/noughtsandcrosses/three_in_a_row_wins 2008-08-18 18:34:12 UTC (rev 883) @@ -1,4 +1,4 @@ -Given the grid looks like +Given a grid that looks like OO. XX. X..
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertCanBeActivated.java (882 => 883)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertCanBeActivated.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertCanBeActivated.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,6 +1,6 @@ package org.jbehave.examples.trader.scenarios; -import org.jbehave.OurTechnique; +import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.Scenario; import org.jbehave.scenario.parser.PatternStepParser; import org.jbehave.scenario.parser.ScenarioDefiner; @@ -15,7 +15,7 @@ } public StatusAlertCanBeActivated(final ClassLoader classLoader) { - super(new OurTechnique() { + super(new PropertyBasedConfiguration() { public ScenarioDefiner forDefiningScenarios() { return new ScenarioFileLoader(new UnderscoredCamelCaseResolver(".scenario"), classLoader, new PatternStepParser()); }
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertIsNeverActivated.java (882 => 883)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertIsNeverActivated.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StatusAlertIsNeverActivated.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,6 +1,6 @@ package org.jbehave.examples.trader.scenarios; -import org.jbehave.OurTechnique; +import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.Scenario; import org.jbehave.scenario.parser.PatternStepParser; import org.jbehave.scenario.parser.ScenarioFileLoader; @@ -14,7 +14,7 @@ } public StatusAlertIsNeverActivated(final ClassLoader classLoader) { - super(new OurTechnique() { + super(new PropertyBasedConfiguration() { @Override public ScenarioFileLoader forDefiningScenarios() { return new ScenarioFileLoader(new UnderscoredCamelCaseResolver(".scenario"), classLoader, new PatternStepParser());
Added: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java (0 => 883)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java (rev 0) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/PropertyBasedConfigurationBehaviour.java 2008-08-18 18:34:12 UTC (rev 883) @@ -0,0 +1,40 @@ +package org.jbehave.scenario; + +import static org.hamcrest.CoreMatchers.is; +import static org.jbehave.Ensure.ensureThat; + +import org.jbehave.scenario.steps.PendingStepStrategy; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PropertyBasedConfigurationBehaviour { + + private String originalFailOnPending; + + @Before + public void captureExistingEnvironment() { + originalFailOnPending = System.getProperty(PropertyBasedConfiguration.FAIL_ON_PENDING); + } + + @After + public void resetEnvironment() { + if (originalFailOnPending != null) { + System.setProperty(PropertyBasedConfiguration.FAIL_ON_PENDING, originalFailOnPending); + } else { + System.clearProperty(PropertyBasedConfiguration.FAIL_ON_PENDING); + } + } + + @Test + public void shouldUsePassingPendingStepStrategyByDefault() { + System.clearProperty(PropertyBasedConfiguration.FAIL_ON_PENDING); + ensureThat(new PropertyBasedConfiguration().forPendingSteps(), is(PendingStepStrategy.PASSING)); + } + + @Test + public void shouldUseFailingPendingStepStrategyWhenConfiguredToDoSo() { + System.setProperty(PropertyBasedConfiguration.FAIL_ON_PENDING, "true"); + ensureThat(new PropertyBasedConfiguration().forPendingSteps(), is(PendingStepStrategy.FAILING)); + } +}
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java (882 => 883)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,6 +1,7 @@ package org.jbehave.scenario; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; import static org.jbehave.Ensure.ensureThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -10,7 +11,7 @@ import java.io.PrintStream; import java.util.Arrays; -import org.jbehave.Technique; +import org.jbehave.Configuration; import org.jbehave.scenario.annotations.Given; import org.jbehave.scenario.annotations.Then; import org.jbehave.scenario.annotations.When; @@ -21,7 +22,11 @@ import org.jbehave.scenario.parser.StepParser; import org.jbehave.scenario.parser.scenarios.MyPendingScenario; import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; +import org.jbehave.scenario.steps.PendingError; +import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.Steps; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -32,7 +37,22 @@ public class ScenarioBehaviour { private static final String NL = System.getProperty("line.separator"); + private String originalFailOnPending; + @Before + public void captureExistingEnvironment() { + originalFailOnPending = System.getProperty(PropertyBasedConfiguration.FAIL_ON_PENDING); + } + + @After + public void resetEnvironment() { + if (originalFailOnPending != null) { + System.setProperty(PropertyBasedConfiguration.FAIL_ON_PENDING, originalFailOnPending); + } else { + System.clearProperty(PropertyBasedConfiguration.FAIL_ON_PENDING); + } + } + @Test public void shouldPerformStepsInFileAssociatedWithNameUsingGivenStepsClasses() throws Throwable { @@ -87,6 +107,48 @@ public void shouldPerformStepsUsingScenarioWithDefaults() throws Throwable { new MyPendingScenario().runUsingSteps(); } + + @Test + public void shouldAllowPendingStepsToFailTheBuild() throws Throwable { + System.setProperty(PropertyBasedConfiguration.FAIL_ON_PENDING, "true"); + try { + new MyPendingScenario().runUsingSteps(); + fail("Should not have run successfully"); + } catch (AssertionError e) { + ensureThat(e, is(PendingError.class)); + } + + try { + new MyPendingScenario().runUsingSteps(); + fail("Should not have run successfully"); + } catch (AssertionError e) { + ensureThat(e, is(PendingError.class)); + } + } + + @Test + public void shouldAllowPartlyDefinedStepsToExplicitlyThrowPendingErrors() throws Throwable { + ScenarioDefiner fileLoader = mock(ScenarioDefiner.class); + StepParser stepParser = mock(PatternStepParser.class); + StringBuffer buffer = new StringBuffer(); + ScenarioReporter reporter = new BufferScenarioReporter(buffer); + MySteps steps = new MySteps(); + + stub(fileLoader.loadStepsFor(MyScenario.class)).toReturn(Arrays.asList( + new ScenarioDefinition(stepParser, "my_scenario"))); + stub(stepParser.findSteps("my_scenario")).toReturn(Arrays.asList(new String[] { + "Given I have 2 cows", + "When I put them in a field", + "Then my cows should still be waiting for the spring"})); + + new MyScenario(fileLoader, stepParser, reporter, steps).runUsingSteps(); + + ensureThat(steps.numberOfCows, equalTo(2)); + ensureThat(buffer.toString(), equalTo( + "Given I have 2 cows" + NL + + "When I put them in a field" + NL + + "Then my cows should still be waiting for the spring (PENDING)" + NL)); + } @Test public void shouldRethrowErrorsInTheEventOfAScenarioFailure() throws Throwable { @@ -105,7 +167,6 @@ "Then my cows should not die", "Then I should have 2 cows"})); - try { new MyScenario(scenarioDefiner, stepParser, reporter, steps).runUsingSteps(); fail("Expected the error to be rethrown"); @@ -123,11 +184,13 @@ private static class MyScenario extends Scenario { public MyScenario(final ScenarioDefiner scenarioDefiner, final StepParser stepParser, final ScenarioReporter scenarioReporter, Steps steps) { - super(new Technique() { + super(new Configuration() { public ScenarioDefiner forDefiningScenarios() { return scenarioDefiner; } public ScenarioReporter forReportingScenarios() { return scenarioReporter; } + + public PendingStepStrategy forPendingSteps() { return PendingStepStrategy.PASSING; } }, steps); } @@ -153,10 +216,14 @@ @Then("my cows should not die") public void keepCowsAlive() { - error = new IllegalAccessError("Leave my cows alone!"); throw error; } + + @Then("my cows should still be waiting for the spring") + public void keepCowsWaiting() { + throw new PendingError("Cows are waiting"); + } } public static class BufferScenarioReporter implements ScenarioReporter {
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java (882 => 883)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java 2008-08-18 18:34:12 UTC (rev 883) @@ -4,10 +4,11 @@ import static org.jbehave.Ensure.ensureThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.stub; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.Step; import org.jbehave.scenario.steps.StepResult; import org.junit.Test; @@ -20,8 +21,7 @@ ScenarioReporter reporter = mock(ScenarioReporter.class); Step step = mock(Step.class); StepResult result = mock(StepResult.class); - ScenarioRunner runner = new ScenarioRunner(reporter); - + ScenarioRunner runner = new ScenarioRunner(reporter, PendingStepStrategy.PASSING); stub(step.perform()).toReturn(result); // When @@ -41,21 +41,13 @@ Step thirdStepNormal = mock(Step.class); Step fourthStepAlsoPending = mock(Step.class); - StepResult success = mock(StepResult.class); - StepResult pending = mock(StepResult.class); - StepResult notRun = mock(StepResult.class); - StepResult alsoPending = mock(StepResult.class); + ScenarioRunner runner = new ScenarioRunner(reporter, PendingStepStrategy.PASSING); - stub(success.shouldContinue()).toReturn(true); - stub(pending.shouldContinue()).toReturn(false); + stub(firstStepNormal.perform()).toReturn(StepResult.success("Given I succeed")); + stub(secondStepPending.perform()).toReturn(StepResult.pending("When I am pending")); + stub(thirdStepNormal.doNotPerform()).toReturn(StepResult.notPerformed("Then I should not be performed")); + stub(fourthStepAlsoPending.doNotPerform()).toReturn(StepResult.notPerformed("Then I should not be performed either")); - ScenarioRunner runner = new ScenarioRunner(reporter); - - stub(firstStepNormal.perform()).toReturn(success); - stub(secondStepPending.perform()).toReturn(pending); - stub(thirdStepNormal.doNotPerform()).toReturn(notRun); - stub(fourthStepAlsoPending.doNotPerform()).toReturn(alsoPending); - // When runner.run(firstStepNormal, secondStepPending, thirdStepNormal, fourthStepAlsoPending); @@ -65,10 +57,10 @@ verify(thirdStepNormal).doNotPerform(); verify(fourthStepAlsoPending).doNotPerform(); - verify(success).describeTo(reporter); - verify(pending).describeTo(reporter); - verify(notRun).describeTo(reporter); - verify(alsoPending).describeTo(reporter); + verify(reporter).successful("Given I succeed"); + verify(reporter).pending("When I am pending"); + verify(reporter).notPerformed("Then I should not be performed"); + verify(reporter).notPerformed("Then I should not be performed either"); } @Test @@ -78,31 +70,28 @@ Step firstStepExceptional = mock(Step.class); Step secondStepNotPerformed = mock(Step.class); - StepResult exceptionalResult = mock(StepResult.class); - StepResult notRunResult = mock(StepResult.class); + StepResult failure = StepResult.failure("When I fail", new IllegalStateException()); + StepResult notPerformed = StepResult.notPerformed("Then I should not be performed"); + stub(firstStepExceptional.perform()).toReturn(failure); + stub(secondStepNotPerformed.doNotPerform()).toReturn(notPerformed); - stub(firstStepExceptional.perform()).toReturn(exceptionalResult); - stub(secondStepNotPerformed.doNotPerform()).toReturn(notRunResult); - IllegalStateException exception = new IllegalStateException(); - stub(exceptionalResult.getThrowable()).toReturn(exception); - stub(exceptionalResult.shouldContinue()).toReturn(false); + ScenarioRunner runner = new ScenarioRunner(reporter, PendingStepStrategy.PASSING); - ScenarioRunner runner = new ScenarioRunner(reporter); - // When try { runner.run(firstStepExceptional, secondStepNotPerformed); fail("Should have rethrown exception"); } catch (IllegalStateException e) { - ensureThat(e, equalTo(exception)); + ensureThat(e, equalTo(failure.getThrowable())); } // Then scenario should still have finished verify(firstStepExceptional).perform(); - verify(exceptionalResult).describeTo(reporter); verify(secondStepNotPerformed).doNotPerform(); - verify(notRunResult).describeTo(reporter); - + + // And results should have been described + verify(reporter).failed("When I fail", failure.getThrowable()); + verify(reporter).notPerformed("Then I should not be performed"); } @Test @@ -114,7 +103,7 @@ stub(pendingStep.perform()).toReturn(StepResult.pending("pendingStep")); stub(secondStep.perform()).toReturn(StepResult.success("secondStep")); - ScenarioRunner runner = new ScenarioRunner(reporter); + ScenarioRunner runner = new ScenarioRunner(reporter, PendingStepStrategy.PASSING); runner.run(pendingStep); runner.run(secondStep); // should reset state for this one @@ -124,4 +113,18 @@ verify(secondStep, never()).doNotPerform(); } + @Test + public void shouldHandlePendingStepsAccordingToStrategy() throws Throwable { + ScenarioReporter reporter = mock(ScenarioReporter.class); + Step pendingStep = mock(Step.class); + StepResult pendingResult = StepResult.pending("My step isn't defined!"); + stub(pendingStep.perform()).toReturn(pendingResult); + + PendingStepStrategy strategy = mock(PendingStepStrategy.class); + + new ScenarioRunner(reporter, strategy).run(pendingStep); + + verify(strategy).handleError(pendingResult.getThrowable()); + } + }
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/scenarios/MyMultipleScenario.java (882 => 883)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/scenarios/MyMultipleScenario.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/scenarios/MyMultipleScenario.java 2008-08-18 18:34:12 UTC (rev 883) @@ -3,14 +3,14 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import org.jbehave.OurTechnique; +import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.Scenario; import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; public class MyMultipleScenario extends Scenario { public MyMultipleScenario() { // Making sure this doesn't output to the build while it's running - super(new OurTechnique() { + super(new PropertyBasedConfiguration() { @Override public PrintStreamScenarioReporter forReportingScenarios() { return new PrintStreamScenarioReporter(new PrintStream(new ByteArrayOutputStream()));
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/scenarios/MyPendingScenario.java (882 => 883)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/scenarios/MyPendingScenario.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/parser/scenarios/MyPendingScenario.java 2008-08-18 18:34:12 UTC (rev 883) @@ -3,7 +3,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import org.jbehave.OurTechnique; +import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.Scenario; import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; @@ -11,7 +11,7 @@ public MyPendingScenario() { // Making sure this doesn't output to the build while it's running - super(new OurTechnique() { + super(new PropertyBasedConfiguration() { @Override public PrintStreamScenarioReporter forReportingScenarios() { return new PrintStreamScenarioReporter(new PrintStream(new ByteArrayOutputStream()));
Modified: trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepResultBehaviour.java (882 => 883)
--- trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepResultBehaviour.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/behaviour/org/jbehave/scenario/steps/StepResultBehaviour.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,8 +1,5 @@ package org.jbehave.scenario.steps; -import static org.jbehave.Ensure.ensureThat; -import static org.jbehave.Ensure.not; -import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -11,24 +8,8 @@ public class StepResultBehaviour { - - @Test - public void shouldNotContinueUnlessSuccessful() { - ensureThat(StepResult.success("").shouldContinue()); - ensureThat(not(StepResult.pending("").shouldContinue())); - } @Test - public void shouldDecideWhatYouWantNotPerformedResultsToDoIfYouNeedToAskThemWhetherToContinue() { - try { - StepResult.notPerformed("").shouldContinue(); - fail("What do you want unperformed results to do here? Change the behaviour!"); - } catch (UnsupportedOperationException e) { - // Expected - } - } - - @Test public void shouldDescribeItselfToAReporter() { IllegalStateException exception = new IllegalStateException(); ScenarioReporter reporter = mock(ScenarioReporter.class);
Copied: trunk/jbehave-core/src/java/org/jbehave/Configuration.java (from rev 882, trunk/jbehave-core/src/java/org/jbehave/Technique.java) (0 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/Configuration.java (rev 0) +++ trunk/jbehave-core/src/java/org/jbehave/Configuration.java 2008-08-18 18:34:12 UTC (rev 883) @@ -0,0 +1,20 @@ +package org.jbehave; + +import org.jbehave.scenario.ScenarioReporter; +import org.jbehave.scenario.parser.ScenarioDefiner; +import org.jbehave.scenario.steps.PendingStepStrategy; + +/** + * Provides techniques for defining, parsing and reporting scenarios. + * + * @author Elizabeth Keogh + */ +public interface Configuration { + + ScenarioDefiner forDefiningScenarios(); + + ScenarioReporter forReportingScenarios(); + + PendingStepStrategy forPendingSteps(); + +}
Deleted: trunk/jbehave-core/src/java/org/jbehave/OurTechnique.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/OurTechnique.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/OurTechnique.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,19 +0,0 @@ -package org.jbehave; - -import org.jbehave.scenario.ScenarioReporter; -import org.jbehave.scenario.parser.PatternStepParser; -import org.jbehave.scenario.parser.ScenarioDefiner; -import org.jbehave.scenario.parser.ScenarioFileLoader; -import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver; -import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; - -public class OurTechnique implements Technique { - - public ScenarioReporter forReportingScenarios() { - return new PrintStreamScenarioReporter(); - } - - public ScenarioDefiner forDefiningScenarios() { - return new ScenarioFileLoader(new UnderscoredCamelCaseResolver(), new PatternStepParser()); - } -}
Deleted: trunk/jbehave-core/src/java/org/jbehave/Technique.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/Technique.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/Technique.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,17 +0,0 @@ -package org.jbehave; - -import org.jbehave.scenario.ScenarioReporter; -import org.jbehave.scenario.parser.ScenarioDefiner; - -/** - * Provides techniques for defining, parsing and reporting scenarios. - * - * @author Elizabeth Keogh - */ -public interface Technique { - - ScenarioDefiner forDefiningScenarios(); - - ScenarioReporter forReportingScenarios(); - -}
Added: trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java (0 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java (rev 0) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java 2008-08-18 18:34:12 UTC (rev 883) @@ -0,0 +1,29 @@ +package org.jbehave.scenario; + +import org.jbehave.Configuration; +import org.jbehave.scenario.parser.PatternStepParser; +import org.jbehave.scenario.parser.ScenarioDefiner; +import org.jbehave.scenario.parser.ScenarioFileLoader; +import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver; +import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; +import org.jbehave.scenario.steps.PendingStepStrategy; + +public class PropertyBasedConfiguration implements Configuration { + + public static final String FAIL_ON_PENDING = "org.jbehave.failonpending"; + + public ScenarioReporter forReportingScenarios() { + return new PrintStreamScenarioReporter(); + } + + public ScenarioDefiner forDefiningScenarios() { + return new ScenarioFileLoader(new UnderscoredCamelCaseResolver(), new PatternStepParser()); + } + + public PendingStepStrategy forPendingSteps() { + if (System.getProperty(FAIL_ON_PENDING) == null) { + return PendingStepStrategy.PASSING; + } + return PendingStepStrategy.FAILING; + } +}
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/Scenario.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/Scenario.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/Scenario.java 2008-08-18 18:34:12 UTC (rev 883) @@ -2,8 +2,7 @@ import java.util.List; -import org.jbehave.OurTechnique; -import org.jbehave.Technique; +import org.jbehave.Configuration; import org.jbehave.scenario.parser.ScenarioDefiner; import org.jbehave.scenario.parser.ScenarioDefinition; import org.jbehave.scenario.steps.CandidateStep; @@ -28,13 +27,13 @@ private final ScenarioRunner scenarioRunner; public Scenario(Steps... candidateSteps) { - this(new OurTechnique(), candidateSteps); + this(new PropertyBasedConfiguration(), candidateSteps); } - public Scenario(Technique technique, Steps... candidateSteps) { - this.candidateSteps = candidateSteps; - this.scenarioDefiner = technique.forDefiningScenarios(); - this.scenarioRunner = new ScenarioRunner(technique.forReportingScenarios()); + public Scenario(Configuration configuration, Steps... candidateSteps) { + this.candidateSteps = candidateSteps; + this.scenarioDefiner = configuration.forDefiningScenarios(); + this.scenarioRunner = new ScenarioRunner(configuration.forReportingScenarios(), configuration.forPendingSteps()); } @Test
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioReporter.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioReporter.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioReporter.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,7 +1,7 @@ package org.jbehave.scenario; /** - * Allows to report the state of running scenario steps. + * Allows the runner to report the state of running scenario steps. * * @author Elizabeth Keogh */
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java 2008-08-18 18:34:12 UTC (rev 883) @@ -1,5 +1,8 @@ package org.jbehave.scenario; +import org.jbehave.scenario.steps.ErrorStrategy; +import org.jbehave.scenario.steps.PendingError; +import org.jbehave.scenario.steps.PendingStepStrategy; import org.jbehave.scenario.steps.Step; import org.jbehave.scenario.steps.StepResult; @@ -13,9 +16,19 @@ private State state; private final ScenarioReporter reporter; + private final PendingStepStrategy pendingStepStrategy; + private ErrorStrategy errorStrategy; + private ErrorStrategy currentStrategy; - public ScenarioRunner(ScenarioReporter reporter) { + public ScenarioRunner(ScenarioReporter reporter, PendingStepStrategy pendingStepStrategy) { + this(reporter, pendingStepStrategy, ErrorStrategy.RETHROW); + } + + public ScenarioRunner(ScenarioReporter reporter, PendingStepStrategy pendingStepStrategy, ErrorStrategy errorStrategy) { this.reporter = reporter; + this.pendingStepStrategy = pendingStepStrategy; + this.errorStrategy = errorStrategy; + this.currentStrategy = ErrorStrategy.SILENT; } public void run(Step... steps) throws Throwable { @@ -23,9 +36,7 @@ for (Step step : steps) { state.run(step); } - if (throwable != null) { - throw throwable; - } + currentStrategy.handleError(throwable); } private class SomethingHappened extends State { @@ -40,19 +51,28 @@ public Throwable throwable; private final class FineSoFar extends State { - @Override + + @Override protected void run(Step step) { StepResult result = step.perform(); result.describeTo(reporter); - if (!result.shouldContinue()) { + throwable = result.getThrowable(); + if (throwable != null) { state = new SomethingHappened(); - throwable = result.getThrowable(); + currentStrategy = strategyFor(throwable); } } + + private ErrorStrategy strategyFor(Throwable throwable) { + if (throwable instanceof PendingError) { + return pendingStepStrategy; + } else { + return errorStrategy; + } + } } private abstract class State { protected abstract void run(Step step); }; - }
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/CandidateStep.java 2008-08-18 18:34:12 UTC (rev 883) @@ -64,14 +64,19 @@ try { method.invoke(steps, args); return StepResult.success(stepAsString); - } catch (Throwable t) { + } + catch (Throwable t) { return failureWithOriginalException(stepAsString, t); } } - private StepResult failureWithOriginalException(final String stepAsString, Throwable t) { + private StepResult failureWithOriginalException(final String stepAsString, Throwable t) { if (t instanceof InvocationTargetException && t.getCause() != null) { - return StepResult.failure(stepAsString, t.getCause()); + if (t.getCause() instanceof PendingError) { + return StepResult.pending(stepAsString, (PendingError) t.getCause()); + } else { + return StepResult.failure(stepAsString, t.getCause()); + } } return StepResult.failure(stepAsString, t); }
Added: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ErrorStrategy.java (0 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ErrorStrategy.java (rev 0) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/ErrorStrategy.java 2008-08-18 18:34:12 UTC (rev 883) @@ -0,0 +1,13 @@ +package org.jbehave.scenario.steps; + +public interface ErrorStrategy { + + ErrorStrategy SILENT = new ErrorStrategy(){ public void handleError(Throwable throwable) {}}; + ErrorStrategy RETHROW = new ErrorStrategy() { + public void handleError(Throwable throwable) throws Throwable { + throw throwable; + }}; + + void handleError(Throwable throwable) throws Throwable; + +}
Added: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingError.java (0 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingError.java (rev 0) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingError.java 2008-08-18 18:34:12 UTC (rev 883) @@ -0,0 +1,11 @@ +package org.jbehave.scenario.steps; + +public class PendingError extends AssertionError { + + private static final long serialVersionUID = 9038975723473227215L; + + public PendingError(String description) { + super(description); + } + +}
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStep.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStep.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStep.java 2008-08-18 18:34:12 UTC (rev 883) @@ -9,7 +9,6 @@ this.step = step; } - public StepResult perform() { return StepResult.pending(getDescription()); }
Added: trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java (0 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java (rev 0) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/PendingStepStrategy.java 2008-08-18 18:34:12 UTC (rev 883) @@ -0,0 +1,14 @@ +package org.jbehave.scenario.steps; + +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/StepResult.java (882 => 883)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepResult.java 2008-07-29 12:22:35 UTC (rev 882) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/steps/StepResult.java 2008-08-18 18:34:12 UTC (rev 883) @@ -7,31 +7,16 @@ public static class Failed extends StepResult { - private final Throwable e; - - public Failed(String step, Throwable e) { - super(step); - this.e = e; + public Failed(String step, Throwable throwable) { + super(step, throwable); } @Override public void describeTo(ScenarioReporter reporter) { - reporter.failed(step, e); + reporter.failed(step, throwable); } - - @Override - public boolean shouldContinue() { - return false; - } - - @Override - public Throwable getThrowable() { - return e; - } - } - public static class NotPerformed extends StepResult { public NotPerformed(String step) { @@ -42,36 +27,24 @@ public void describeTo(ScenarioReporter reporter) { reporter.notPerformed(step); } - - - @Override - public boolean shouldContinue() { - throw new UnsupportedOperationException( - "I have no idea whether 'notPerformed' results should continue. ScenarioRunners " + - "should not need to check whether to continue if they've already decided not to continue."); - } - } public static class Pending extends StepResult { - public Pending(String step) { - super(step); + this(step, new PendingError("Pending: " + step)); } + public Pending(String stepAsString, PendingError e) { + super(stepAsString, e); + } + @Override public void describeTo(ScenarioReporter reporter) { reporter.pending(step); } - - @Override - public boolean shouldContinue() { - return false; - } } - public static class Success extends StepResult { public Success(String string) { super(string); @@ -81,17 +54,18 @@ public void describeTo(ScenarioReporter reporter) { reporter.successful(step); } - - @Override - public boolean shouldContinue() { - return true; - } } protected final String step; + protected final Throwable throwable; public StepResult(String step) { + this(step, null); + } + + public StepResult(String step, Throwable throwable) { this.step = step; + this.throwable = throwable; } public static StepResult success(String step) { @@ -102,6 +76,9 @@ return new Pending(step); } + public static StepResult pending(String stepAsString, PendingError e) { + return new Pending(stepAsString, e); + } public static StepResult notPerformed(String step) { return new NotPerformed(step); @@ -113,9 +90,8 @@ public abstract void describeTo(ScenarioReporter reporter); - public abstract boolean shouldContinue(); public Throwable getThrowable() { - return null; + return throwable; } }
To unsubscribe from this list please visit:
