- Revision
- 706
- Author
- sirenian
- Date
- 2007-03-21 08:55:36 -0500 (Wed, 21 Mar 2007)
Log Message
[EK] The whole given(World) thing leads to some really, really messy code, so I'm taking it out. We can override createWorld in the story and actually that's enough. Added throws Exception to each of the ScenarioComponents, and improved the javadoc on things like World.
Modified Paths
- trunk/core/src/behaviour/org/jbehave/core/story/domain/EventStepBehaviour.java
- trunk/core/src/behaviour/org/jbehave/core/story/domain/GivenStepBehaviour.java
- trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java
- trunk/core/src/behaviour/org/jbehave/core/story/domain/OutcomeStepBehaviour.java
- trunk/core/src/java/org/jbehave/core/story/domain/AbstractStep.java
- trunk/core/src/java/org/jbehave/core/story/domain/CustomWorld.java
- trunk/core/src/java/org/jbehave/core/story/domain/Event.java
- trunk/core/src/java/org/jbehave/core/story/domain/EventStep.java
- trunk/core/src/java/org/jbehave/core/story/domain/Given.java
- trunk/core/src/java/org/jbehave/core/story/domain/GivenStep.java
- trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java
- trunk/core/src/java/org/jbehave/core/story/domain/Outcome.java
- trunk/core/src/java/org/jbehave/core/story/domain/OutcomeStep.java
- trunk/core/src/java/org/jbehave/core/story/domain/Step.java
- trunk/core/src/java/org/jbehave/core/story/domain/World.java
Diff
Modified: trunk/core/src/behaviour/org/jbehave/core/story/domain/EventStepBehaviour.java (705 => 706)
--- trunk/core/src/behaviour/org/jbehave/core/story/domain/EventStepBehaviour.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/behaviour/org/jbehave/core/story/domain/EventStepBehaviour.java 2007-03-21 13:55:36 UTC (rev 706) @@ -4,7 +4,7 @@ import org.jbehave.core.mock.Mock; public class EventStepBehaviour extends UsingMiniMock { - public void shouldTellEventToOccurInWorld() { + public void shouldTellEventToOccurInWorld() throws Exception { // given Mock event = mock(Event.class); EventStep step = new EventStep((Event)event);
Modified: trunk/core/src/behaviour/org/jbehave/core/story/domain/GivenStepBehaviour.java (705 => 706)
--- trunk/core/src/behaviour/org/jbehave/core/story/domain/GivenStepBehaviour.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/behaviour/org/jbehave/core/story/domain/GivenStepBehaviour.java 2007-03-21 13:55:36 UTC (rev 706) @@ -4,7 +4,7 @@ import org.jbehave.core.mock.Mock; public class GivenStepBehaviour extends UsingMiniMock { - public void shouldTellGivenToSetUpWorld() { + public void shouldTellGivenToSetUpWorld() throws Exception { // given Mock given = mock(Given.class); GivenStep step = new GivenStep((Given)given);
Modified: trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java (705 => 706)
--- trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java 2007-03-21 13:55:36 UTC (rev 706) @@ -7,7 +7,11 @@ import org.jbehave.core.story.renderer.Renderer; public class MultiStepScenarioBehaviour extends UsingMiniMock { - + + public interface GivenWithCleanUp extends Given, CleansUpWorld {} + public interface OutcomeWithCleanUp extends Outcome, CleansUpWorld {} + public interface GivenWorld extends Given, CleansUpWorld, World {} + public void shouldPerformGiven() throws Exception { // given final Mock given = mock(Given.class); @@ -98,10 +102,8 @@ // then verifyMocks(); } - - public interface GivenWithCleanUp extends Given, CleansUpWorld {} - public interface OutcomeWithCleanUp extends Outcome, CleansUpWorld {} + public void shouldTellStepsToCleanUpWorldInReverseOrder() throws Exception { // given final Mock given = mock(GivenWithCleanUp.class); @@ -343,6 +345,45 @@ ensureThat(exception, isNotNull()); } + public void shouldRethrowExceptionsInStepsAsVerificationExceptions() throws Exception { + final Mock given = mock(GivenWithCleanUp.class, "given"); + given.expects("setUp").will(throwException(new Exception())); + + final Scenario scenario = new MultiStepScenario(){ + public void specifySteps() { + given((Given) given); + }}; + + Exception exception = runAndCatch(VerificationException.class, new Block() { + public void run() throws Exception { + scenario.specify(); + scenario.run((World)stub(World.class)); + } + }); + + ensureThat(exception, isNotNull()); + } + + public void shouldNotRethrowVerificationExceptionsInSteps() throws Exception { + final Mock given = mock(GivenWithCleanUp.class, "given"); + VerificationException verificationException = new VerificationException("My message"); + given.expects("setUp").will(throwException(verificationException)); + + final Scenario scenario = new MultiStepScenario(){ + public void specifySteps() { + given((Given) given); + }}; + + Exception exception = runAndCatch(VerificationException.class, new Block() { + public void run() throws Exception { + scenario.specify(); + scenario.run((World)stub(World.class)); + } + }); + + ensureThat(exception, is(verificationException)); + } + public void shouldNotCleanUpIfNotRun() throws Exception { // given final Mock given = mock(GivenWithCleanUp.class, "given"); @@ -351,7 +392,6 @@ Scenario scenario = new MultiStepScenario() { public void specifySteps() { given((Given) given); - }}; given.expects("cleanUp").never(); @@ -422,32 +462,5 @@ ensureThat(exception, isNotNull()); } - - public void shouldPerformStepsInSpecifiedWorldIfGivenWorld() { - final Mock world = mock(World.class); - final Mock given = mock(Given.class); - final Mock event = mock(Event.class); - final Mock outcome = mock(Outcome.class); - - Scenario scenario = new MultiStepScenario() { - public void specifySteps() { - given((World)world); - given((Given)given); - when((Event)event); - then((Outcome)outcome); - } - }; - scenario.specify(); - - // expect - given.expects("setUp").with(world); - event.expects("occurIn").with(world).after(given, "setUp"); - outcome.expects("verify").with(world).after(event, "occurIn"); - - // when - scenario.run(new HashMapWorld()); - - // then - verifyMocks(); - } + }
Modified: trunk/core/src/behaviour/org/jbehave/core/story/domain/OutcomeStepBehaviour.java (705 => 706)
--- trunk/core/src/behaviour/org/jbehave/core/story/domain/OutcomeStepBehaviour.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/behaviour/org/jbehave/core/story/domain/OutcomeStepBehaviour.java 2007-03-21 13:55:36 UTC (rev 706) @@ -4,7 +4,7 @@ import org.jbehave.core.mock.Mock; public class OutcomeStepBehaviour extends UsingMiniMock { - public void shouldTellOutcomeToVerifyWorld() { + public void shouldTellOutcomeToVerifyWorld() throws Exception { // given Mock outcome = mock(Outcome.class); AbstractStep step = new OutcomeStep((Outcome)outcome);
Modified: trunk/core/src/java/org/jbehave/core/story/domain/AbstractStep.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/AbstractStep.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/AbstractStep.java 2007-03-21 13:55:36 UTC (rev 706) @@ -6,7 +6,7 @@ protected final ScenarioComponent component; - public abstract void perform(World world); + public abstract void perform(World world) throws Exception; public AbstractStep(ScenarioComponent component) { this.component = component;
Modified: trunk/core/src/java/org/jbehave/core/story/domain/CustomWorld.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/CustomWorld.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/CustomWorld.java 2007-03-21 13:55:36 UTC (rev 706) @@ -2,15 +2,16 @@ /** * This class is provided for convenience for those who would like - * to define their own world with its own accessors. Every - * method throws an UnsupportedOperationException unless explicitly + * to define their own world with its own accessors. World + * methods throws an UnsupportedOperationException unless explicitly * overridden by subclasses (in which case you should probably be * extending HashMapWorld instead). This means that it's easy for you to * create your own world without getting it mixed up with JBehave's * default implementation (the HashMapWorld). * - * It's not as pretty as we'd like, but we'd like to support the - * old ways of doing things too. + * See World for details on how to use this class. + * + * @see World */ public abstract class CustomWorld implements World {
Modified: trunk/core/src/java/org/jbehave/core/story/domain/Event.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/Event.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/Event.java 2007-03-21 13:55:36 UTC (rev 706) @@ -20,5 +20,5 @@ * @see EventUsingMiniMock */ public interface Event extends ScenarioComponent { - void occurIn(World world); + void occurIn(World world) throws Exception; } \ No newline at end of file
Modified: trunk/core/src/java/org/jbehave/core/story/domain/EventStep.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/EventStep.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/EventStep.java 2007-03-21 13:55:36 UTC (rev 706) @@ -6,7 +6,7 @@ super(event); } - public void perform(World world) { + public void perform(World world) throws Exception { ((Event)component).occurIn(world); } }
Modified: trunk/core/src/java/org/jbehave/core/story/domain/Given.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/Given.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/Given.java 2007-03-21 13:55:36 UTC (rev 706) @@ -19,5 +19,5 @@ * @see GivenUsingMiniMock */ public interface Given extends ScenarioComponent { - void setUp(World world); + void setUp(World world) throws Exception; } \ No newline at end of file
Modified: trunk/core/src/java/org/jbehave/core/story/domain/GivenStep.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/GivenStep.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/GivenStep.java 2007-03-21 13:55:36 UTC (rev 706) @@ -7,7 +7,7 @@ super(given); } - public void perform(World world) { + public void perform(World world) throws Exception { given().setUp(world); }
Modified: trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java 2007-03-21 13:55:36 UTC (rev 706) @@ -5,6 +5,7 @@ import java.util.List; import java.util.ListIterator; +import org.jbehave.core.exception.VerificationException; import org.jbehave.core.story.renderer.Renderer; @@ -65,7 +66,6 @@ private List steps = new ArrayList(); private String state; - private World world; public MultiStepScenario() { state = UNSPECIFIED; @@ -84,8 +84,12 @@ try { for (Iterator i = steps.iterator(); i.hasNext();) { Step step = (Step) i.next(); - step.perform(this.world == null ? world : this.world); + step.perform(world); } + } catch (VerificationException e) { + throw e; + } catch (Exception e) { + throw new VerificationException("Exception in Scenario", e); } finally { state = RUN; } @@ -98,7 +102,7 @@ public void cleanUp(World world) { if (shouldCleanUp()) { for (ListIterator i = steps.listIterator(steps.size()); i.hasPrevious();) { - ((AbstractStep) i.previous()).cleanUp(this.world == null ? world : this.world); + ((AbstractStep) i.previous()).cleanUp(world); } } state = CLEANED; @@ -130,11 +134,6 @@ } - - protected void given(World world) { - this.world = world; - } - protected void given(Given given) { steps.add(new GivenStep(given)); }
Modified: trunk/core/src/java/org/jbehave/core/story/domain/Outcome.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/Outcome.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/Outcome.java 2007-03-21 13:55:36 UTC (rev 706) @@ -20,5 +20,5 @@ * @see OutcomeUsingMiniMock */ public interface Outcome extends ScenarioComponent { - void verify(World world); + void verify(World world) throws Exception; } \ No newline at end of file
Modified: trunk/core/src/java/org/jbehave/core/story/domain/OutcomeStep.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/OutcomeStep.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/OutcomeStep.java 2007-03-21 13:55:36 UTC (rev 706) @@ -6,7 +6,7 @@ super(outcome); } - public void perform(World world) { + public void perform(World world) throws Exception { outcome().verify(world); }
Modified: trunk/core/src/java/org/jbehave/core/story/domain/Step.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/Step.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/Step.java 2007-03-21 13:55:36 UTC (rev 706) @@ -1,5 +1,5 @@ package org.jbehave.core.story.domain; public interface Step extends ScenarioComponent { - void perform(World world); + void perform(World world) throws Exception; }
Modified: trunk/core/src/java/org/jbehave/core/story/domain/World.java (705 => 706)
--- trunk/core/src/java/org/jbehave/core/story/domain/World.java 2007-03-20 16:25:34 UTC (rev 705) +++ trunk/core/src/java/org/jbehave/core/story/domain/World.java 2007-03-21 13:55:36 UTC (rev 706) @@ -8,8 +8,17 @@ package org.jbehave.core.story.domain; /** - * @author <a href="" PROTECTED]">Dan North</a> - * @see HashMapWorld, CustomWorld + * By default, a Scenario takes place in a HashMapWorld. + * + * Story.createWorld() can be overridden to provide your own + * custom World. We recommend that if you want to provide your + * own accessors, you should override CustomWorld which allows + * you to ignore the interface below. + * + * The methods on this interface are a legacy of JBehave 1.0. + * We might remove them from the interface at some point. + * + * @see HashMapWorld, CustomWorld, Given, CleansUpWorld */ public interface World { /**
To unsubscribe from this list please visit:
