Title: [waffle-scm] [272] trunk/core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java: trace exceptions unit test
Revision
272
Author
fabio.kung
Date
2007-07-18 07:12:09 -0500 (Wed, 18 Jul 2007)

Log Message

trace exceptions unit test

Modified Paths


Diff

Modified: trunk/core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java (271 => 272)

--- trunk/core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java	2007-07-18 11:53:40 UTC (rev 271)
+++ trunk/core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java	2007-07-18 12:12:09 UTC (rev 272)
@@ -18,11 +18,12 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.util.Set;
 
 /**
- * 
  * @author Mauro Talevi
  */
 @RunWith(JMock.class)
@@ -54,6 +55,34 @@
         assertEquals(5, sb.toString().split("\n").length);
     }
 
+    @Test
+    public void canTraceExceptions() {
+        final StringWriter monitorWriter = new StringWriter();
+        final AbstractWritingMonitor monitor = new AbstractWritingMonitor() {
+            @Override
+            protected void write(MonitorLevel level, String message) {
+                // will not be tested here
+            }
+
+            @Override
+            protected void trace(Exception exception) {
+                exception.printStackTrace(new PrintWriter(monitorWriter));
+            }
+        };
+        Exception exception = new Exception();
+        StackTraceElement[] elements = {
+                new StackTraceElement("MyController", "myPrivateMethod", "package.MyController.java", 10),
+                new StackTraceElement("MyController", "myActionMethod", "package.MyController.java", 1),
+        };
+        exception.setStackTrace(elements);
+        monitor.trace(exception);
+
+        StringWriter expectedMessageWriter = new StringWriter();
+        exception.printStackTrace(new PrintWriter(expectedMessageWriter));
+
+        assertEquals(expectedMessageWriter.toString(), monitorWriter.toString());
+    }
+
     private MethodDefinition mockMethodDefinition() {
         try {
             Method method = Object.class.getMethod("toString", (Class[]) null);


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to