Title: [712] trunk/core/src/behaviour/org/jbehave/core: [EK] Fixed null pointer exception on null Throwable with JBehaveFrameworkError.java; removed automatic stacktrace from one constructor.
Revision
712
Author
sirenian
Date
2007-03-23 09:22:27 -0500 (Fri, 23 Mar 2007)

Log Message

[EK] Fixed null pointer exception on null Throwable with JBehaveFrameworkError.java; removed automatic stacktrace from one constructor.

Modified Paths

Added Paths

Diff

Modified: trunk/core/src/behaviour/org/jbehave/core/AllBehaviours.java (711 => 712)

--- trunk/core/src/behaviour/org/jbehave/core/AllBehaviours.java	2007-03-23 12:16:04 UTC (rev 711)
+++ trunk/core/src/behaviour/org/jbehave/core/AllBehaviours.java	2007-03-23 14:22:27 UTC (rev 712)
@@ -11,6 +11,7 @@
 import org.jbehave.core.behaviour.BehaviourMethodBehaviour;
 import org.jbehave.core.behaviour.BehaviourVerifierBehaviour;
 import org.jbehave.core.behaviour.Behaviours;
+import org.jbehave.core.exception.JBehaveFrameworkErrorBehaviour;
 import org.jbehave.core.listener.PlainTextMethodListenerBehaviour;
 import org.jbehave.core.minimock.MiniMockObjectBehaviour;
 import org.jbehave.core.minimock.UsingMiniMockBehaviour;
@@ -31,7 +32,8 @@
                 UsingMiniMockBehaviour.class,
                 ExpectationBehaviour.class,
                 ResultBehaviour.class,
-                org.jbehave.core.story.AllBehaviours.class
+                org.jbehave.core.story.AllBehaviours.class,
+                JBehaveFrameworkErrorBehaviour.class
         };
     }
 }

Added: trunk/core/src/behaviour/org/jbehave/core/exception/JBehaveFrameworkErrorBehaviour.java (0 => 712)

--- trunk/core/src/behaviour/org/jbehave/core/exception/JBehaveFrameworkErrorBehaviour.java	                        (rev 0)
+++ trunk/core/src/behaviour/org/jbehave/core/exception/JBehaveFrameworkErrorBehaviour.java	2007-03-23 14:22:27 UTC (rev 712)
@@ -0,0 +1,70 @@
+package org.jbehave.core.exception;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import org.jbehave.core.Block;
+import org.jbehave.core.mock.UsingMatchers;
+
+public class JBehaveFrameworkErrorBehaviour extends UsingMatchers {
+    
+
+    public void shouldIncludeTheStackTraceOfCausingError() {
+        ByteArrayOutputStream bufferForError = new ByteArrayOutputStream();
+        PrintStream streamForError = new PrintStream(bufferForError);
+        
+        ByteArrayOutputStream bufferForOther = new ByteArrayOutputStream();
+        PrintStream streamForOther = new PrintStream(bufferForOther);
+        
+        IllegalArgumentException cause = new IllegalArgumentException();
+        JBehaveFrameworkError error = new JBehaveFrameworkError(cause);
+        
+        cause.printStackTrace(streamForOther);
+        error.printStackTrace(streamForError);
+
+        ensureThat(bufferForError, contains(JBehaveFrameworkError.class.getName()));
+        ensureThat(bufferForError.toString(), contains(bufferForOther.toString()));
+    }
+    
+    public void shouldPrintAStackTraceWithoutErrorsIfOnlyMessageProvided() {
+        ByteArrayOutputStream bufferForError = new ByteArrayOutputStream();
+        PrintStream streamForError = new PrintStream(bufferForError);
+        
+        ByteArrayOutputStream bufferForOther = new ByteArrayOutputStream();
+        PrintStream streamForOther = new PrintStream(bufferForOther);
+        
+        Error errorWithExpectedStackTrace = new Error("A message");
+        JBehaveFrameworkError error = new JBehaveFrameworkError("A message");
+        
+        errorWithExpectedStackTrace.printStackTrace(streamForOther);
+        error.printStackTrace(streamForError);
+
+        ensureThat(bufferForError, contains(JBehaveFrameworkError.class.getName()));
+        ensureThat(bufferForError.toString(), contains("A message"));
+    }
+    
+    public void shouldPrintAStackTraceWithoutErrorsOrMessageIfNoneProvided() {
+        ByteArrayOutputStream bufferForError = new ByteArrayOutputStream();
+        PrintStream streamForError = new PrintStream(bufferForError);
+        
+        JBehaveFrameworkError error = new JBehaveFrameworkError();
+        
+        error.printStackTrace(streamForError);
+        
+        ensureThat(bufferForError, contains(JBehaveFrameworkError.class.getName()));
+    }
+    
+    public void shouldCopeWithNullArguments() throws Exception {
+        final PrintStream aStream = new PrintStream(new ByteArrayOutputStream());
+        
+        Exception exception = runAndCatch(Exception.class, new Block() {
+            public void run() throws Exception {
+                new JBehaveFrameworkError(null, null).printStackTrace(aStream);
+                new JBehaveFrameworkError((String)null).printStackTrace(aStream);
+                new JBehaveFrameworkError((Throwable)null).printStackTrace(aStream);
+            }
+        });
+        ensureThat(exception, isNull());
+    }
+
+}

Modified: trunk/core/src/java/org/jbehave/core/exception/JBehaveFrameworkError.java (711 => 712)

--- trunk/core/src/java/org/jbehave/core/exception/JBehaveFrameworkError.java	2007-03-23 12:16:04 UTC (rev 711)
+++ trunk/core/src/java/org/jbehave/core/exception/JBehaveFrameworkError.java	2007-03-23 14:22:27 UTC (rev 712)
@@ -37,7 +37,6 @@
 
     public JBehaveFrameworkError(Throwable nestedException) {
         this(null, nestedException);
-        nestedException.printStackTrace();
     }
     
 	public Throwable getNestedException() {


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to