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