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 | |
import java.util.ArrayList; |
23 | |
import java.util.Collection; |
24 | |
import java.util.Collections; |
25 | |
import org.apache.maven.plugin.surefire.report.TestSetStats; |
26 | |
import org.apache.maven.surefire.suite.RunResult; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 22 | public class RunStatistics |
32 | |
{ |
33 | |
|
34 | |
|
35 | |
|
36 | 22 | private final Sources errorSources = new Sources(); |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 22 | private final Sources failureSources = new Sources(); |
42 | |
|
43 | |
private int completedCount; |
44 | |
|
45 | |
private int errors; |
46 | |
|
47 | |
private int failures; |
48 | |
|
49 | |
private int skipped; |
50 | |
|
51 | |
|
52 | |
public void addErrorSource( StackTraceWriter stackTraceWriter ) |
53 | |
{ |
54 | 3 | if ( stackTraceWriter == null ) |
55 | |
{ |
56 | 0 | throw new IllegalArgumentException( "Cant be null" ); |
57 | |
} |
58 | 3 | errorSources.addSource( stackTraceWriter ); |
59 | 3 | } |
60 | |
|
61 | |
public void addFailureSource( StackTraceWriter stackTraceWriter ) |
62 | |
{ |
63 | 3 | if ( stackTraceWriter == null ) |
64 | |
{ |
65 | 0 | throw new IllegalArgumentException( "Cant be null" ); |
66 | |
} |
67 | 3 | failureSources.addSource( stackTraceWriter ); |
68 | 3 | } |
69 | |
|
70 | |
public Collection<String> getErrorSources() |
71 | |
{ |
72 | 3 | return errorSources.getListOfSources(); |
73 | |
} |
74 | |
|
75 | |
public Collection<String> getFailureSources() |
76 | |
{ |
77 | 3 | return failureSources.getListOfSources(); |
78 | |
} |
79 | |
|
80 | |
public synchronized boolean hadFailures() |
81 | |
{ |
82 | 0 | return failures > 0; |
83 | |
} |
84 | |
|
85 | |
public synchronized boolean hadErrors() |
86 | |
{ |
87 | 0 | return errors > 0; |
88 | |
} |
89 | |
|
90 | |
public synchronized int getCompletedCount() |
91 | |
{ |
92 | 0 | return completedCount; |
93 | |
} |
94 | |
|
95 | |
public synchronized int getSkipped() |
96 | |
{ |
97 | 0 | return skipped; |
98 | |
} |
99 | |
|
100 | |
public synchronized void add( TestSetStats testSetStats ) |
101 | |
{ |
102 | 0 | this.completedCount += testSetStats.getCompletedCount(); |
103 | 0 | this.errors += testSetStats.getErrors(); |
104 | 0 | this.failures += testSetStats.getFailures(); |
105 | 0 | this.skipped += testSetStats.getSkipped(); |
106 | 0 | } |
107 | |
|
108 | |
public synchronized RunResult getRunResult() |
109 | |
{ |
110 | 0 | return new RunResult( completedCount, errors, failures, skipped ); |
111 | |
} |
112 | |
|
113 | |
public synchronized String getSummary() |
114 | |
{ |
115 | 0 | return "Tests run: " + completedCount + ", Failures: " + failures + ", Errors: " + errors + ", Skipped: " |
116 | |
+ skipped; |
117 | |
} |
118 | |
|
119 | |
|
120 | 22 | private static class Sources |
121 | |
{ |
122 | 44 | private final Collection<String> listOfSources = new ArrayList<String>(); |
123 | |
|
124 | |
void addSource( String source ) |
125 | |
{ |
126 | 6 | synchronized ( listOfSources ) |
127 | |
{ |
128 | 6 | listOfSources.add( source ); |
129 | 6 | } |
130 | 6 | } |
131 | |
|
132 | |
void addSource( StackTraceWriter stackTraceWriter ) |
133 | |
{ |
134 | 6 | addSource( stackTraceWriter.smartTrimmedStackTrace() ); |
135 | 6 | } |
136 | |
|
137 | |
Collection<String> getListOfSources() |
138 | |
{ |
139 | 6 | synchronized ( listOfSources ) |
140 | |
{ |
141 | 6 | return Collections.unmodifiableCollection( listOfSources ); |
142 | 0 | } |
143 | |
} |
144 | |
} |
145 | |
} |