1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.report;
20
21 import junit.framework.TestCase;
22
23
24
25
26 public class PojoStackTraceWriterTest extends TestCase {
27
28 public void testTrimmedThrowableReal() {
29 PojoStackTraceWriter w =
30 new PojoStackTraceWriter(ATestClass.AnotherTestClass.class.getName(), "testQuote", getAThrowAble());
31 String out = w.writeTrimmedTraceToString();
32 String expected = "org.apache.maven.surefire.report.PojoStackTraceWriterTest$ATestClass$AnotherTestClass"
33 + ".getAThrowable(PojoStackTraceWriterTest.java";
34 assertTrue(out.contains(expected));
35 }
36
37 public void testMultiLineMessage() {
38 String msg = "assert \"foo\" == \"bar\"\n" + " |\n" + " false";
39 try {
40 throw new RuntimeException(msg);
41 } catch (Throwable t) {
42 PojoStackTraceWriter writer = new PojoStackTraceWriter(null, null, t);
43 String stackTrace = writer.writeTraceToString();
44 assertTrue(stackTrace.startsWith("java.lang.RuntimeException: \n" + msg));
45 }
46 }
47
48 static class ATestClass {
49 static class AnotherTestClass {
50 public static Throwable getAThrowable() {
51 try {
52 throw new Exception("Hey ho, hey ho, a throwable we throw!");
53 } catch (Exception e) {
54 return e;
55 }
56 }
57 }
58 }
59
60 private Throwable getAThrowAble() {
61 return ATestClass.AnotherTestClass.getAThrowable();
62 }
63 }