- Revision
- 790
- Author
- mauro
- Date
- 2007-09-06 04:35:09 -0500 (Thu, 06 Sep 2007)
Log Message
Deprecated StoryRunner run methods with OutputStream in favour of ones with BehaviourListener. Pulled up to BehaviourListener interface two methods from PlainTextListener.
Modified Paths
- trunk/core/src/behaviour/org/jbehave/core/story/StoryRunnerBehaviour.java
- trunk/core/src/java/org/jbehave/core/behaviour/BehaviourVerifier.java
- trunk/core/src/java/org/jbehave/core/listener/BehaviourListener.java
- trunk/core/src/java/org/jbehave/core/listener/PlainTextListener.java
- trunk/core/src/java/org/jbehave/core/listener/ValidatingListener.java
- trunk/core/src/java/org/jbehave/core/story/StoryRunner.java
- trunk/core/src/java/org/jbehave/core/story/listener/PlainTextScenarioListener.java
- trunk/extensions/junit/src/java/org/jbehave/junit/JUnitMethodAdapter.java
Diff
Modified: trunk/core/src/behaviour/org/jbehave/core/story/StoryRunnerBehaviour.java (789 => 790)
--- trunk/core/src/behaviour/org/jbehave/core/story/StoryRunnerBehaviour.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/core/src/behaviour/org/jbehave/core/story/StoryRunnerBehaviour.java 2007-09-06 09:35:09 UTC (rev 790) @@ -1,6 +1,7 @@ package org.jbehave.core.story; import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; import java.io.PrintStream; import org.jbehave.core.Block; @@ -17,12 +18,10 @@ public class StoryRunnerBehaviour extends UsingMiniMock { public void shouldSpecifyAndRunStoryAndOutputResults() throws Exception { - final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + BehaviourListener listener = new PlainTextScenarioListener(new OutputStreamWriter(new PrintStream(buffer))); + new StoryRunner().run(SimpleStory.class.getName(), listener); - PrintStream stream = new PrintStream(buffer); - - new StoryRunner().run(SimpleStory.class.getName(), stream); - Ensure.that(buffer.toString(), contains("..")); Ensure.that(buffer.toString(), contains("Total: 2.")); @@ -31,11 +30,11 @@ public void shouldOutputPendingExeptionsWithoutFailingTheStory() throws Exception { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - final PrintStream stream = new PrintStream(buffer); + final BehaviourListener listener = new PlainTextScenarioListener(new OutputStreamWriter(new PrintStream(buffer))); Exception exception = runAndCatch(Exception.class, new Block() { public void run() throws Exception { - new StoryRunner().run(PendingStory.class.getName(), stream); + new StoryRunner().run(PendingStory.class.getName(), listener); } });
Modified: trunk/core/src/java/org/jbehave/core/behaviour/BehaviourVerifier.java (789 => 790)
--- trunk/core/src/java/org/jbehave/core/behaviour/BehaviourVerifier.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/core/src/java/org/jbehave/core/behaviour/BehaviourVerifier.java 2007-09-06 09:35:09 UTC (rev 790) @@ -40,4 +40,12 @@ public void after(Behaviour behaviour) { listener.after(behaviour); } + + public void printReport() { + listener.printReport(); + } + + public boolean hasBehaviourFailures() { + return listener.hasBehaviourFailures(); + } }
Modified: trunk/core/src/java/org/jbehave/core/listener/BehaviourListener.java (789 => 790)
--- trunk/core/src/java/org/jbehave/core/listener/BehaviourListener.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/core/src/java/org/jbehave/core/listener/BehaviourListener.java 2007-09-06 09:35:09 UTC (rev 790) @@ -12,17 +12,23 @@ /** * @author <a href="" PROTECTED]">Dan North</a> + * @author Mauro Talevi */ public interface BehaviourListener { void before(Behaviour behaviour); void gotResult(Result result); void after(Behaviour behaviour); - + void printReport(); + boolean hasBehaviourFailures(); + /** Null object implementation for [EMAIL PROTECTED] BehaviourListener} */ BehaviourListener NULL = new BehaviourListener() { public void before(Behaviour behaviour) {} public void gotResult(Result result) {} public void after(Behaviour behaviour) {} - + public void printReport() {} + public boolean hasBehaviourFailures() { + return false; + } }; }
Modified: trunk/core/src/java/org/jbehave/core/listener/PlainTextListener.java (789 => 790)
--- trunk/core/src/java/org/jbehave/core/listener/PlainTextListener.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/core/src/java/org/jbehave/core/listener/PlainTextListener.java 2007-09-06 09:35:09 UTC (rev 790) @@ -1,9 +1,6 @@ /* - * Created on 23-Nov-2004 - * - * (c) 2003-2004 ThoughtWorks Ltd - * - * See license.txt for license details + * Created on 23-Nov-2004 (c) 2003-2004 ThoughtWorks Ltd See license.txt for + * license details */ package org.jbehave.core.listener; @@ -18,8 +15,6 @@ import org.jbehave.core.util.CamelCaseConverter; import org.jbehave.core.util.Timer; - - /** * @author <a href="" PROTECTED]">Dan North</a> */ @@ -42,8 +37,7 @@ methodsVerified++; if (result.failed()) { failures.add(result); - } - else if (result.isPending()) { + } else if (result.isPending()) { pending.add(result); } out.print(result.status().symbol()); @@ -59,8 +53,8 @@ out.flush(); } - private void printElapsedTime() { - out.println("Time: " + timer.elapsedTimeMillis()/1000.0 + "s\n"); + void printElapsedTime() { + out.println("Time: " + timer.elapsedTimeMillis() / 1000.0 + "s\n"); } protected void printDetails() { @@ -88,7 +82,7 @@ out.println(); int count = 1; for (Iterator i = pending.iterator(); i.hasNext(); count++) { - Result result = (Result) i.next(); + Result result = (Result) i.next(); printResult(count, result); out.println("\t" + result.cause().getMessage()); StackTraceElement element = findFirstNonJBehaveStackElement(result.cause()); @@ -122,15 +116,14 @@ return null; } - private void printSummaryCounts() { + void printSummaryCounts() { out.print("Total: " + methodsVerified + "."); if (pending.size() > 0) { out.print(" Pending: " + pending.size() + "."); } if (failures.size() > 0) { out.print(" Failures: " + failures.size() + "."); - } - else { + } else { out.print(" Success!"); } out.println();
Modified: trunk/core/src/java/org/jbehave/core/listener/ValidatingListener.java (789 => 790)
--- trunk/core/src/java/org/jbehave/core/listener/ValidatingListener.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/core/src/java/org/jbehave/core/listener/ValidatingListener.java 2007-09-06 09:35:09 UTC (rev 790) @@ -10,7 +10,7 @@ /** - * A decorator of a listener to allows to check if the verification succeded or failed. + * A listener decorating another listener to check if the verification succeded or failed. * * @author <a href="" PROTECTED]">Damian Guy</a> * @author Mauro Talevi @@ -42,4 +42,12 @@ delegate.before(behaviour); } + public void printReport() { + delegate.printReport(); + } + + public boolean hasBehaviourFailures() { + return delegate.hasBehaviourFailures(); + } + }
Modified: trunk/core/src/java/org/jbehave/core/story/StoryRunner.java (789 => 790)
--- trunk/core/src/java/org/jbehave/core/story/StoryRunner.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/core/src/java/org/jbehave/core/story/StoryRunner.java 2007-09-06 09:35:09 UTC (rev 790) @@ -8,6 +8,7 @@ import java.io.OutputStreamWriter; import org.jbehave.core.exception.PendingException; +import org.jbehave.core.listener.BehaviourListener; import org.jbehave.core.result.Result; import org.jbehave.core.story.codegen.parser.TextStoryParser; import org.jbehave.core.story.domain.Story; @@ -39,18 +40,39 @@ this.storyLoader = storyLoader; } + public void run(String storyClassName) { + Story story = storyLoader.loadStoryClass(storyClassName); + story.specify(); + run(story); + } + public void run(Story story) { - run(story, System.out); + run(story, new PlainTextScenarioListener()); } + /** + * @deprecated Use #run(String,BehaviourListener) instead + */ public void run(String storyClassName, OutputStream outputStream) { Story story = storyLoader.loadStoryClass(storyClassName); story.specify(); run(story, outputStream); } + /** + * @deprecated Use #run(Story,BehaviourListener) instead + */ public void run(Story story, OutputStream outputStream) { - PlainTextScenarioListener listener = new PlainTextScenarioListener(new OutputStreamWriter(outputStream)); + run(story, new PlainTextScenarioListener(new OutputStreamWriter(outputStream))); + } + + public void run(String storyClassName, BehaviourListener listener) { + Story story = storyLoader.loadStoryClass(storyClassName); + story.specify(); + run(story, listener); + } + + public void run(Story story, BehaviourListener listener) { story.addListener(listener); try { story.run(); @@ -60,15 +82,16 @@ listener.printReport(); succeeded = succeeded && !listener.hasBehaviourFailures(); } - + private boolean succeeded() { return succeeded; } public static void main(String[] args) { StoryRunner runner = new StoryRunner(); + BehaviourListener listener = new PlainTextScenarioListener(); for (int i = 0; i < args.length; i++) { - runner.run(args[i], System.out); + runner.run(args[i]); } System.exit(runner.succeeded() ? 0 : 1); }
Modified: trunk/core/src/java/org/jbehave/core/story/listener/PlainTextScenarioListener.java (789 => 790)
--- trunk/core/src/java/org/jbehave/core/story/listener/PlainTextScenarioListener.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/core/src/java/org/jbehave/core/story/listener/PlainTextScenarioListener.java 2007-09-06 09:35:09 UTC (rev 790) @@ -7,6 +7,7 @@ */ package org.jbehave.core.story.listener; +import java.io.OutputStreamWriter; import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; @@ -27,6 +28,10 @@ public class PlainTextScenarioListener extends PlainTextListener implements BehaviourListener { private final List usedMocks = new ArrayList(); + public PlainTextScenarioListener() { + this(new OutputStreamWriter(System.out)); + } + public PlainTextScenarioListener(Writer writer) { super(writer, new Timer()); } @@ -71,4 +76,5 @@ out.println(); } } + }
Modified: trunk/extensions/junit/src/java/org/jbehave/junit/JUnitMethodAdapter.java (789 => 790)
--- trunk/extensions/junit/src/java/org/jbehave/junit/JUnitMethodAdapter.java 2007-09-05 14:37:49 UTC (rev 789) +++ trunk/extensions/junit/src/java/org/jbehave/junit/JUnitMethodAdapter.java 2007-09-06 09:35:09 UTC (rev 790) @@ -19,7 +19,7 @@ import org.jbehave.core.util.CamelCaseConverter; /** - * Adapter wrapping a BehaviourMethod as a JUnit Test + * Adapter decorating a BehaviourMethod as a JUnit Test * * @author Dan North * @author Mauro Talevi @@ -92,6 +92,17 @@ // no-op } + public void printReport() { + // no-op + } + + public boolean hasBehaviourFailures() { + if (result != null) { + return !result.succeeded(); + } + return false; + } + public String toString() { return new CamelCaseConverter(behaviourMethod.method().getName()).toPhrase(); }
To unsubscribe from this list please visit:
