1 package org.apache.maven.surefire.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.io.PrintWriter;
24 import java.io.StringWriter;
25
26
27
28
29
30
31 public class PojoStackTraceWriter
32 implements StackTraceWriter
33 {
34 private final Throwable t;
35
36 protected final String testClass;
37
38 protected final String testMethod;
39
40 public PojoStackTraceWriter( String testClass, String testMethod, Throwable t )
41 {
42 this.testClass = testClass;
43 this.testMethod = testMethod;
44 this.t = t;
45 }
46
47 public String writeTraceToString()
48 {
49 StringWriter w = new StringWriter();
50 if ( t != null )
51 {
52 t.printStackTrace( new PrintWriter( w ) );
53 w.flush();
54 }
55 return w.toString();
56 }
57
58 public String smartTrimmedStackTrace()
59 {
60 if ( t == null )
61 {
62 return "";
63 }
64
65 SmartStackTraceParser parser = new SmartStackTraceParser( testClass, t, testMethod );
66 return parser.getString();
67 }
68
69 public String writeTrimmedTraceToString()
70 {
71 if ( t == null )
72 {
73 return "";
74 }
75
76 return SmartStackTraceParser.innerMostWithFocusOnClass( t, testClass );
77 }
78
79 public SafeThrowable getThrowable()
80 {
81 if ( t == null )
82 {
83 return null;
84 }
85
86 return new SafeThrowable( t );
87 }
88 }