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 RunStatistics()
41      {
42      }
43  
44      public synchronized boolean hadFailures()
45      {
46          return failures > 0;
47      }
48  
49      public synchronized boolean hadErrors()
50      {
51          return errors > 0;
52      }
53  
54      public synchronized int getCompletedCount()
55      {
56          return completedCount;
57      }
58  
59      public synchronized int getSkipped()
60      {
61          return skipped;
62      }
63  
64      public synchronized int getFailures()
65      {
66          return failures;
67      }
68  
69      public synchronized int getErrors()
70      {
71          return errors;
72      }
73  
74      public synchronized int getFlakes()
75      {
76          return flakes;
77      }
78  
79      public synchronized void add( TestSetStats testSetStats )
80      {
81          this.completedCount += testSetStats.getCompletedCount();
82          this.errors += testSetStats.getErrors();
83          this.failures += testSetStats.getFailures();
84          this.skipped += testSetStats.getSkipped();
85      }
86  
87      public synchronized void set( int completedCount, int errors, int failures, int skipped, int flakes )
88      {
89          this.completedCount = completedCount;
90          this.errors = errors;
91          this.failures = failures;
92          this.skipped = skipped;
93          this.flakes = flakes;
94      }
95  
96      public synchronized RunResult getRunResult()
97      {
98          return new RunResult( completedCount, errors, failures, skipped, flakes );
99      }
100 
101     public synchronized String getSummary()
102     {
103         String summary =
104             "Tests run: " + completedCount + ", Failures: " + failures + ", Errors: " + errors + ", Skipped: "
105                 + skipped;
106         if ( flakes > 0 )
107         {
108             summary += ", Flakes: " + flakes;
109         }
110         return summary;
111     }
112 }