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
24
25 public class SimpleReportEntry
26 implements ReportEntry
27 {
28 private final String source;
29
30 private final String name;
31
32 private final StackTraceWriter stackTraceWriter;
33
34 private final Integer elapsed;
35
36 private final String message;
37
38 public SimpleReportEntry()
39 {
40 this( null, null );
41 }
42
43 public SimpleReportEntry( String source, String name )
44 {
45 this( source, name, null, null );
46 }
47
48 private SimpleReportEntry( String source, String name, StackTraceWriter stackTraceWriter )
49 {
50 this( source, name, stackTraceWriter, null );
51 }
52
53 public SimpleReportEntry( String source, String name, Integer elapsed )
54 {
55 this( source, name, null, elapsed );
56 }
57
58 protected SimpleReportEntry( String source, String name, StackTraceWriter stackTraceWriter, Integer elapsed,
59 String message )
60 {
61 if ( source == null )
62 {
63 source = "null";
64 }
65 if ( name == null )
66 {
67 name = "null";
68 }
69
70 this.source = source;
71
72 this.name = name;
73
74 this.stackTraceWriter = stackTraceWriter;
75
76 this.message = message;
77
78 this.elapsed = elapsed;
79 }
80
81
82 public SimpleReportEntry( String source, String name, StackTraceWriter stackTraceWriter, Integer elapsed )
83 {
84
85 this( source, name, stackTraceWriter, elapsed, safeGetMessage( stackTraceWriter ) );
86 }
87
88 public static SimpleReportEntry ignored( String source, String name, String message )
89 {
90 return new SimpleReportEntry( source, name, null, null, message );
91 }
92
93 public static SimpleReportEntry withException( String source, String name, StackTraceWriter stackTraceWriter )
94 {
95 return new SimpleReportEntry( source, name, stackTraceWriter );
96 }
97
98 private static String safeGetMessage( StackTraceWriter stackTraceWriter )
99 {
100 try
101 {
102 return ( stackTraceWriter != null && stackTraceWriter.getThrowable() != null )
103 ? stackTraceWriter.getThrowable().getMessage()
104 : null;
105 }
106 catch ( Throwable t )
107 {
108 return t.getMessage();
109 }
110 }
111
112 public String getSourceName()
113 {
114 return source;
115 }
116
117 public String getName()
118 {
119 return name;
120 }
121
122 public String getGroup()
123 {
124 return null;
125 }
126
127 public StackTraceWriter getStackTraceWriter()
128 {
129 return stackTraceWriter;
130 }
131
132 public Integer getElapsed()
133 {
134 return elapsed;
135 }
136
137 public String toString()
138 {
139 return "ReportEntry{" + "source='" + source + '\'' + ", name='" + name + '\'' + ", stackTraceWriter="
140 + stackTraceWriter + ", elapsed=" + elapsed + ",message=" + message + '}';
141 }
142
143 public String getMessage()
144 {
145 return message;
146 }
147
148
149
150
151 public boolean equals( Object o )
152 {
153 if ( this == o )
154 {
155 return true;
156 }
157 if ( o == null || getClass() != o.getClass() )
158 {
159 return false;
160 }
161
162 SimpleReportEntry that = (SimpleReportEntry) o;
163
164 if ( elapsed != null ? !elapsed.equals( that.elapsed ) : that.elapsed != null )
165 {
166 return false;
167 }
168 if ( name != null ? !name.equals( that.name ) : that.name != null )
169 {
170 return false;
171 }
172 if ( source != null ? !source.equals( that.source ) : that.source != null )
173 {
174 return false;
175 }
176 if ( stackTraceWriter != null
177 ? !stackTraceWriter.equals( that.stackTraceWriter )
178 : that.stackTraceWriter != null )
179 {
180 return false;
181 }
182
183 return true;
184 }
185
186 public int hashCode()
187 {
188 int result = source != null ? source.hashCode() : 0;
189 result = 31 * result + ( name != null ? name.hashCode() : 0 );
190 result = 31 * result + ( stackTraceWriter != null ? stackTraceWriter.hashCode() : 0 );
191 result = 31 * result + ( elapsed != null ? elapsed.hashCode() : 0 );
192 return result;
193 }
194
195 public String getNameWithGroup()
196 {
197 return getName();
198 }
199 }