- Revision
- 705
- Author
- sirenian
- Date
- 2007-03-20 11:25:34 -0500 (Tue, 20 Mar 2007)
Log Message
[EK] Fixed bug which caused StoryRunnerTask to always fail the build (doh!). Made World able to take Object keys. Added ability to run in a custom World per scenario, using given(World). Added a CustomWorld class which can be overridden to do this.
Modified Paths
- trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java
- trunk/core/src/java/org/jbehave/core/story/StoryRunner.java
- trunk/core/src/java/org/jbehave/core/story/domain/HashMapWorld.java
- trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java
- trunk/core/src/java/org/jbehave/core/story/domain/World.java
- trunk/extensions/ant/src/behaviour/org/jbehave/ant/StoryRunnerTaskBehaviour.java
Added Paths
Diff
Modified: trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java (704 => 705)
--- trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java 2007-03-14 11:51:31 UTC (rev 704) +++ trunk/core/src/behaviour/org/jbehave/core/story/domain/MultiStepScenarioBehaviour.java 2007-03-20 16:25:34 UTC (rev 705) @@ -422,4 +422,32 @@ 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/java/org/jbehave/core/story/StoryRunner.java (704 => 705)
--- trunk/core/src/java/org/jbehave/core/story/StoryRunner.java 2007-03-14 11:51:31 UTC (rev 704) +++ trunk/core/src/java/org/jbehave/core/story/StoryRunner.java 2007-03-20 16:25:34 UTC (rev 705) @@ -22,7 +22,7 @@ public class StoryRunner { private ClassLoader classLoader; - private boolean succeeded; + private boolean succeeded = true; public StoryRunner(){ this(Thread.currentThread().getContextClassLoader());
Added: trunk/core/src/java/org/jbehave/core/story/domain/CustomWorld.java (0 => 705)
--- trunk/core/src/java/org/jbehave/core/story/domain/CustomWorld.java (rev 0) +++ trunk/core/src/java/org/jbehave/core/story/domain/CustomWorld.java 2007-03-20 16:25:34 UTC (rev 705) @@ -0,0 +1,33 @@ +package org.jbehave.core.story.domain; + +/** + * 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 + * 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. + */ +public abstract class CustomWorld implements World { + + public void clear() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + public Object get(Object key, Object defaultValue) throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + public Object get(Object key) throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + public void put(Object key, Object value) throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + +}
Modified: trunk/core/src/java/org/jbehave/core/story/domain/HashMapWorld.java (704 => 705)
--- trunk/core/src/java/org/jbehave/core/story/domain/HashMapWorld.java 2007-03-14 11:51:31 UTC (rev 704) +++ trunk/core/src/java/org/jbehave/core/story/domain/HashMapWorld.java 2007-03-20 16:25:34 UTC (rev 705) @@ -16,18 +16,18 @@ public class HashMapWorld implements World { private final Map map = new HashMap(); - public Object get(String key, Object defaultValue) { + public Object get(Object key, Object defaultValue) { if (!map.containsKey(key)) { put(key, defaultValue); } return map.get(key); } - public Object get(String key) { + public Object get(Object key) { return map.get(key); } - public void put(String key, Object value) { + public void put(Object key, Object value) { map.put(key, value); }
Modified: trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java (704 => 705)
--- trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java 2007-03-14 11:51:31 UTC (rev 704) +++ trunk/core/src/java/org/jbehave/core/story/domain/MultiStepScenario.java 2007-03-20 16:25:34 UTC (rev 705) @@ -65,6 +65,7 @@ private List steps = new ArrayList(); private String state; + private World world; public MultiStepScenario() { state = UNSPECIFIED; @@ -83,7 +84,7 @@ try { for (Iterator i = steps.iterator(); i.hasNext();) { Step step = (Step) i.next(); - step.perform(world); + step.perform(this.world == null ? world : this.world); } } finally { state = RUN; @@ -97,7 +98,7 @@ public void cleanUp(World world) { if (shouldCleanUp()) { for (ListIterator i = steps.listIterator(steps.size()); i.hasPrevious();) { - ((AbstractStep) i.previous()).cleanUp(world); + ((AbstractStep) i.previous()).cleanUp(this.world == null ? world : this.world); } } state = CLEANED; @@ -129,6 +130,11 @@ } + + 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/World.java (704 => 705)
--- trunk/core/src/java/org/jbehave/core/story/domain/World.java 2007-03-14 11:51:31 UTC (rev 704) +++ trunk/core/src/java/org/jbehave/core/story/domain/World.java 2007-03-20 16:25:34 UTC (rev 705) @@ -9,22 +9,23 @@ /** * @author <a href="" PROTECTED]">Dan North</a> + * @see HashMapWorld, CustomWorld */ public interface World { /** * Get a value out of the world. If it doesn't exist, store the default value. */ - Object get(String key, Object defaultValue); + Object get(Object key, Object defaultValue); /** * Get a value out of the world. If it doesn't exist, return null. */ - Object get(String key); + Object get(Object key); /** * Put a value into the world, replacing any existing value. */ - void put(String key, Object value); + void put(Object key, Object value); /** * Reset the world to its default state
Modified: trunk/extensions/ant/src/behaviour/org/jbehave/ant/StoryRunnerTaskBehaviour.java (704 => 705)
--- trunk/extensions/ant/src/behaviour/org/jbehave/ant/StoryRunnerTaskBehaviour.java 2007-03-14 11:51:31 UTC (rev 704) +++ trunk/extensions/ant/src/behaviour/org/jbehave/ant/StoryRunnerTaskBehaviour.java 2007-03-20 16:25:34 UTC (rev 705) @@ -75,7 +75,7 @@ } }); ensureThat(exception, isNotNull()); - } + } private static class StubCommandRunner implements CommandRunner { private int valueToReturn;
To unsubscribe from this list please visit:
