Title: [jbehave] [614] trunk/core/src/java/jbehave/core/story/domain: Removed Scenarios - merged functionality in ScenarioDrivenStory.

Diff

Modified: trunk/core/src/behaviour/jbehave/core/story/domain/ScenarioDrivenStoryBehaviour.java (613 => 614)

--- trunk/core/src/behaviour/jbehave/core/story/domain/ScenarioDrivenStoryBehaviour.java	2006-12-05 12:30:33 UTC (rev 613)
+++ trunk/core/src/behaviour/jbehave/core/story/domain/ScenarioDrivenStoryBehaviour.java	2006-12-05 13:05:03 UTC (rev 614)
@@ -7,6 +7,8 @@
  */
 package jbehave.core.story.domain;
 
+import jbehave.core.exception.NestedVerificationException;
+import jbehave.core.exception.VerificationException;
 import jbehave.core.listener.BehaviourListener;
 import jbehave.core.minimock.UsingMiniMock;
 import jbehave.core.mock.Expectation;
@@ -60,6 +62,70 @@
         verifyMocks();
     }
     
+    public void shouldInformListenersOfScenarioUsingMocks() {
+        World world = (World) stub(World.class);
+        Narrative narrative = new Narrative("","","");
+        AStory story = new AStory(narrative);
+        
+        Mock listener = mock(BehaviourListener.class);
+        AScenario scenario = new AScenario();
+        ScenarioResult result = new ScenarioResult("a scenario", "a story", ScenarioResult.USED_MOCKS);
+
+        scenario.expects("run").with(world);
+        scenario.expects("containsMocks").will(returnValue(true));
+        listener.expects("gotResult").with(eq(result));
+        
+        story.addScenario((Scenario)scenario);
+        story.addListener((BehaviourListener)listener);
+        
+        story.run(world);
+        
+        verifyMocks();
+    }
+
+    public void shouldInformListenersOfScenarioFailure() {
+        World world = (World) stub(World.class);
+        Narrative narrative = new Narrative("","","");
+        AStory story = new AStory(narrative);
+        
+        Mock listener = mock(BehaviourListener.class);
+        AScenario scenario = new AScenario();
+        NestedVerificationException nve = new NestedVerificationException(new RuntimeException());
+        ScenarioResult result = new ScenarioResult("a scenario", "a story", nve);
+        scenario.expects("run").with(world).will(throwException(nve));
+        listener.expects("gotResult").with(eq(result));
+        
+        story.addScenario((Scenario)scenario);
+        story.addListener((BehaviourListener)listener);
+        
+        story.run(world);
+        
+        verifyMocks();
+    }
+
+    public void shouldCleanUpScenariosEvenIfVerificationFails() {
+        World world = (World) stub(World.class);
+        Narrative narrative = new Narrative("","","");
+        AStory story = new AStory(narrative);
+        
+        Mock listener = mock(BehaviourListener.class);
+        AScenario scenario = new AScenario();
+        VerificationException ve = new VerificationException("Thrown by an outcome when an ensureThat fails");
+        ScenarioResult result = new ScenarioResult("a scenario", "a story", ve);
+        scenario.expects("run").with(world).will(throwException(ve));
+        scenario.expects("cleanUp").with(world);
+        
+        story.addScenario((Scenario)scenario);
+        
+        try {
+            story.run(world);
+        } catch (VerificationException e) {
+            // Expected, but AFTER cleanUp.
+        }
+        
+        verifyMocks();
+    }
+        
     private class AStory extends ScenarioDrivenStory {
         // just used to provide the story name
 

Deleted: trunk/core/src/behaviour/jbehave/core/story/domain/ScenariosBehaviour.java (613 => 614)

--- trunk/core/src/behaviour/jbehave/core/story/domain/ScenariosBehaviour.java	2006-12-05 12:30:33 UTC (rev 613)
+++ trunk/core/src/behaviour/jbehave/core/story/domain/ScenariosBehaviour.java	2006-12-05 13:05:03 UTC (rev 614)
@@ -1,137 +0,0 @@
-package jbehave.core.story.domain;
-
-import jbehave.core.exception.NestedVerificationException;
-import jbehave.core.exception.VerificationException;
-import jbehave.core.listener.BehaviourListener;
-import jbehave.core.minimock.UsingMiniMock;
-import jbehave.core.mock.Expectation;
-import jbehave.core.mock.Mock;
-import jbehave.core.story.renderer.Renderer;
-import jbehave.core.story.result.ScenarioResult;
-
-public class ScenariosBehaviour extends UsingMiniMock {
-
-	public void shouldRunAndTidyUpScenariosInOrder() {
-        AScenario scenarioA = new AScenario();
-        AScenario scenarioB = new AScenario();
-        World world = (World) stub(World.class);
-		
-		Scenarios scenarios = new Scenarios();
-		
-		scenarioA.expects("run").with(world);
-        scenarioA.expects("tidyUp").with(world);
-        scenarioB.expects("run").with(world).after(scenarioA.mockDelegate, "tidyUp");
-        scenarioB.expects("tidyUp").with(world).after(scenarioB.mockDelegate, "run");
-		
-		scenarios.addScenario((Scenario) scenarioA);
-		scenarios.addScenario((Scenario) scenarioB);
-		scenarios.run(world, AStory.class, new BehaviourListener[0]);
-        
-        verifyMocks();
-	}
-    
-    public void shouldInformListenersOfScenarioSuccess() {
-        AScenario scenario = new AScenario();
-        Mock listener = mock(BehaviourListener.class);
-        World world = (World) stub(World.class);
-        
-        Scenarios scenarios = new Scenarios();
-        scenarios.addScenario((Scenario)scenario);
-        
-        scenario.expects("run").with(world);
-        scenario.expects("containsMocks").will(returnValue(false));
-        listener.expects("gotResult").with(eq(new ScenarioResult("a scenario", "a story", ScenarioResult.SUCCEEDED)));
-        
-        scenarios.run(world, AStory.class, new BehaviourListener[] {(BehaviourListener) listener});
-        
-        verifyMocks();
-    }
-    
-    public void shouldInformListenersOfScenarioUsingMocks() {
-        AScenario scenario = new AScenario();
-        Mock listener = mock(BehaviourListener.class);
-        World world = (World) stub(World.class);
-        
-        Scenarios scenarios = new Scenarios();
-        scenarios.addScenario((Scenario)scenario);
-        
-        scenario.expects("run").with(world);
-        scenario.expects("containsMocks").will(returnValue(true));
-        listener.expects("gotResult").with(eq(new ScenarioResult("a scenario", "a story", ScenarioResult.USED_MOCKS)));
-        
-        scenarios.run(world, AStory.class, new BehaviourListener[] {(BehaviourListener) listener});
-        
-        verifyMocks();
-    }
-    
-    public void shouldInformListenersOfScenarioFailure() {
-        AScenario scenario = new AScenario();
-        Mock listener = mock(BehaviourListener.class);
-        World world = (World) stub(World.class);
-        
-        Scenarios scenarios = new Scenarios();
-        scenarios.addScenario((Scenario)scenario);
-        
-        NestedVerificationException nve = new NestedVerificationException(new RuntimeException());
-        scenario.expects("run").with(world).will(throwException(nve));
-        listener.expects("gotResult").with(eq(new ScenarioResult("a scenario", "a story", nve)));
-        
-        scenarios.run(world, AStory.class, new BehaviourListener[] {(BehaviourListener) listener});
-        
-        verifyMocks();
-    }
-    
-    public void shouldTidyUpScenariosEvenIfVerificationFails() {
-        AScenario scenario = new AScenario();
-        World world = (World) stub(World.class);
-        
-        Scenarios scenarios = new Scenarios();
-        scenarios.addScenario((Scenario) scenario);
-        
-        scenario.expects("run").with(world).will(throwException(new VerificationException("Thrown by an outcome when an ensureThat fails")));
-        scenario.expects("tidyUp").with(world);
-
-        try {
-            scenarios.run(world, AStory.class, new BehaviourListener[0]);
-        } catch (VerificationException e) {
-            // Expected, but AFTER tidyUp.
-        }
-        
-        verifyMocks();
-    }
-    
-    private class AStory {
-        // just used to provide the story name
-    }
-    
-    private class AScenario implements Scenario {
-        // also required to get the right name
-        
-        Mock mockDelegate = mock(Scenario.class);
-        Scenario delegate = (Scenario) mockDelegate;
-        
-        public Expectation expects(String method) {
-            return mockDelegate.expects(method);
-        }
-        
-        public boolean containsMocks() {
-            return delegate.containsMocks();
-        }
-
-        public void run(World world) {
-            delegate.run(world);
-        }
-
-        public void cleanUp(World world) {
-            delegate.cleanUp(world);
-        }
-
-        public void narrateTo(Renderer renderer) {
-            delegate.narrateTo(renderer);
-        }
-        
-        public void assemble() {
-            delegate.assemble();
-        }
-    }
-}

Modified: trunk/core/src/java/jbehave/core/story/domain/ScenarioDrivenStory.java (613 => 614)

--- trunk/core/src/java/jbehave/core/story/domain/ScenarioDrivenStory.java	2006-12-05 12:30:33 UTC (rev 613)
+++ trunk/core/src/java/jbehave/core/story/domain/ScenarioDrivenStory.java	2006-12-05 13:05:03 UTC (rev 614)
@@ -8,10 +8,14 @@
 package jbehave.core.story.domain;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
+import jbehave.core.exception.NestedVerificationException;
 import jbehave.core.listener.BehaviourListener;
 import jbehave.core.story.renderer.Renderer;
+import jbehave.core.story.result.ScenarioResult;
+import jbehave.core.util.CamelCaseConverter;
 
 /**
  * <p>A ScenarioDrivenStory is an executable description of a value 
@@ -31,21 +35,21 @@
  */
 public class ScenarioDrivenStory implements Story {
     private final Narrative narrative;
-    private final Scenarios scenarios;
+    private final List scenarios;
     private final List listeners;
 
     public ScenarioDrivenStory(Narrative narrative) {
         this.narrative = narrative;
-        this.scenarios = new Scenarios();
-        listeners = new ArrayList();
+        this.scenarios = new ArrayList();
+        this.listeners = new ArrayList();
     }
 
     public void addScenario(Scenario scenario) {
-        scenarios.addScenario(scenario);
+        scenarios.add(scenario);
     }
 
     public List scenarios() {
-        return scenarios.scenarios();
+        return scenarios;
     }
     
     public Narrative narrative() {
@@ -53,9 +57,35 @@
     }
 
     public void run(World world) {
-        scenarios.run(world, this.getClass(), (BehaviourListener[]) listeners.toArray(new BehaviourListener[listeners.size()]));
+        for (Iterator i = scenarios.iterator(); i.hasNext();) {
+            Scenario scenario = (Scenario) i.next();
+            informListeners(runScenario(world, this.getClass(), scenario));
+        }
     }
     
+    private ScenarioResult runScenario(World world, Class storyClass, Scenario scenario) {
+        ScenarioResult result;
+        String storyDescription = new CamelCaseConverter(storyClass).toPhrase();
+        String description = new CamelCaseConverter(scenario).toPhrase();
+        
+        try {                
+            scenario.run(world);
+            result = new ScenarioResult(description, storyDescription, 
+                    scenario.containsMocks() ? ScenarioResult.USED_MOCKS : ScenarioResult.SUCCEEDED);
+        } catch (NestedVerificationException nve) {
+            result = new ScenarioResult(description, storyDescription, nve);
+        } finally {
+            scenario.cleanUp(world);
+        }        
+        return result;
+    }
+        
+    private void informListeners(ScenarioResult result) {
+        for ( Iterator i = listeners.iterator(); i.hasNext(); ){
+            ((BehaviourListener) i.next()).gotResult(result);
+        }
+    }
+    
     public void addListener(BehaviourListener listener) {
         listeners.add(listener);       
     }
@@ -63,8 +93,10 @@
     public void narrateTo(Renderer renderer) {
         renderer.renderStory(this);
         narrative.narrateTo(renderer);
-        scenarios.narrateTo(renderer);
-    }
+        for ( Iterator i = scenarios.iterator(); i.hasNext(); ){
+            ((Scenario) i.next()).narrateTo(renderer);
+        }
+    }    
 
     public String toString() {
         StringBuffer buffer = new StringBuffer();

Deleted: trunk/core/src/java/jbehave/core/story/domain/Scenarios.java (613 => 614)

--- trunk/core/src/java/jbehave/core/story/domain/Scenarios.java	2006-12-05 12:30:33 UTC (rev 613)
+++ trunk/core/src/java/jbehave/core/story/domain/Scenarios.java	2006-12-05 13:05:03 UTC (rev 614)
@@ -1,86 +0,0 @@
-/*
- * Created on 28-Sep-2004
- * 
- * (c) 2003-2004 ThoughtWorks Ltd
- *
- * See license.txt for license details
- */
-package jbehave.core.story.domain;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import jbehave.core.exception.NestedVerificationException;
-import jbehave.core.listener.BehaviourListener;
-import jbehave.core.story.renderer.Renderable;
-import jbehave.core.story.renderer.Renderer;
-import jbehave.core.story.result.ScenarioResult;
-import jbehave.core.util.CamelCaseConverter;
-
-
-/**
- * @author <a href="" PROTECTED]">Dan North</a>
- */
-public class Scenarios implements Renderable {
-	private final List scenarios = new ArrayList();
-
-	public List scenarios() {
-        return scenarios;
-    }
-
-	public void run(World world, Class storyClass, BehaviourListener[] listeners) {
-        for (Iterator i = scenarios.iterator(); i.hasNext();) {
-            Scenario scenario = (Scenario) i.next();
-            informListeners(listeners, runScenario(world, storyClass, scenario));
-        }
-	}
-
-    private void informListeners(BehaviourListener[] listeners, ScenarioResult result) {
-        for (int i = 0; i < listeners.length; i++) {
-            listeners[i].gotResult(result);
-        }
-    }
-
-    private ScenarioResult runScenario(World world, Class storyClass, Scenario scenario) {
-        ScenarioResult result;
-        String storyDescription = new CamelCaseConverter(storyClass).toPhrase();
-        String description = new CamelCaseConverter(scenario).toPhrase();
-        
-        try {                
-            scenario.run(world);
-            result = new ScenarioResult(description, storyDescription, 
-                    scenario.containsMocks() ? ScenarioResult.USED_MOCKS : ScenarioResult.SUCCEEDED);
-        } catch (NestedVerificationException nve) {
-            result = new ScenarioResult(description, storyDescription, nve);
-        } finally {
-            scenario.cleanUp(world);
-        }
-        
-        return result;
-    }
-    
-    public void addScenario(Scenario scenario) {
-		scenarios.add(scenario);
-	}
-
-    public void narrateTo(Renderer renderer) {
-        for ( Iterator i = scenarios.iterator(); i.hasNext(); ){
-            ((Scenario) i.next()).narrateTo(renderer);
-        }
-    }
-    
-    public String toString() {
-        StringBuffer buffer = new StringBuffer();
-        buffer.append("[");
-        buffer.append("\n");
-        for ( Iterator i = scenarios.iterator(); i.hasNext(); ){
-            Scenario scenario = (Scenario)i.next();
-            buffer.append(scenario);
-            buffer.append("\n");
-        }
-        buffer.append("]");
-        return buffer.toString();
-    }
-
-}

Modified: trunk/core/src/java/jbehave/core/story/renderer/PlainTextRenderer.java (613 => 614)

--- trunk/core/src/java/jbehave/core/story/renderer/PlainTextRenderer.java	2006-12-05 12:30:33 UTC (rev 613)
+++ trunk/core/src/java/jbehave/core/story/renderer/PlainTextRenderer.java	2006-12-05 13:05:03 UTC (rev 614)
@@ -17,7 +17,6 @@
 import jbehave.core.story.domain.Outcome;
 import jbehave.core.story.domain.Scenario;
 import jbehave.core.story.domain.ScenarioComponent;
-import jbehave.core.story.domain.Scenarios;
 import jbehave.core.story.domain.Story;
 import jbehave.core.util.CamelCaseConverter;
 
@@ -89,10 +88,6 @@
         return previousComponent != null && clazz.isAssignableFrom(previousComponent.getClass());
     }    
     
-    public void renderScenarios(Scenarios criteria) {
-        // Do nothing
-    }
-
     public void gotResult(Result result) {
     }
 

Modified: trunk/core/src/java/jbehave/core/story/renderer/Renderer.java (613 => 614)

--- trunk/core/src/java/jbehave/core/story/renderer/Renderer.java	2006-12-05 12:30:33 UTC (rev 613)
+++ trunk/core/src/java/jbehave/core/story/renderer/Renderer.java	2006-12-05 13:05:03 UTC (rev 614)
@@ -5,7 +5,6 @@
  */
 package jbehave.core.story.renderer;
 
-import jbehave.core.story.domain.Scenarios;
 import jbehave.core.story.domain.Event;
 import jbehave.core.story.domain.Given;
 import jbehave.core.story.domain.Narrative;
@@ -19,7 +18,6 @@
 public interface Renderer {
 	void renderStory(Story story);
 	void renderNarrative(Narrative narrative);
-	void renderScenarios(Scenarios criteria);
 	void renderScenario(Scenario scenario);
 	void renderGiven(Given given);
 	void renderOutcome(Outcome outcome);


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to