View Javadoc
1   package org.apache.maven.surefire.report;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.surefire.report.TestSetStats;
23  import org.apache.maven.surefire.suite.RunResult;
24  
25  /**
26   * @author Kristian Rosenvold
27   */
28  public class RunStatistics
29  {
30      private int completedCount;
31  
32      private int errors;
33  
34      private int failures;
35  
36      private int skipped;
37  
38      private int flakes;
39  
40      public synchronized boolean hadFailures()
41      {
42          return failures > 0;
43      }
44  
45      public synchronized boolean hadErrors()
46      {
47          return errors > 0;
48      }
49  
50      public synchronized int getCompletedCount()
51      {
52          return completedCount;
53      }
54  
55      public synchronized int getSkipped()
56      {
57          return skipped;
58      }
59  
60      public synchronized int getFailures()
61      {
62          return failures;
63      }
64  
65      public synchronized int getErrors()
66      {
67          return errors;
68      }
69  
70      public synchronized int getFlakes()
71      {
72          return flakes;
73      }
74  
75      public synchronized void add( TestSetStats testSetStats )
76      {
77          this.completedCount += testSetStats.getCompletedCount();
78          this.errors += testSetStats.getErrors();
79          this.failures += testSetStats.getFailures();
80          this.skipped += testSetStats.getSkipped();
81      }
82  
83      public synchronized void set( int completedCount, int errors, int failures, int skipped, int flakes )
84      {
85          this.completedCount = completedCount;
86          this.errors = errors;
87          this.failures = failures;
88          this.skipped = skipped;
89          this.flakes = flakes;
90      }
91  
92      public synchronized RunResult getRunResult()
93      {
94          return new RunResult( completedCount, errors, failures, skipped, flakes );
95      }
96  
97      public synchronized String getSummary()
98      {
99          String summary =
100             "Tests run: " + completedCount + ", Failures: " + failures + ", Errors: " + errors + ", Skipped: "
101                 + skipped;
102         if ( flakes > 0 )
103         {
104             summary += ", Flakes: " + flakes;
105         }
106         return summary;
107     }
108 }