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.surefire.suite.RunResult;
23  
24  /**
25   * Run-statistics for a testset
26   *
27   * @author Kristian Rosenvold
28   *         Note; synchronization is questionable. Whiled this class alone is ok, there's a higher level concern about
29   *         synchronization interactions within ReporterManager. See ReporterManager class.
30   */
31  public class TestSetStatistics
32  {
33      private int completedCount;
34  
35      private int errors;
36  
37      private int failures;
38  
39      private int skipped;
40  
41      public synchronized void incrementCompletedCount()
42      {
43          completedCount += 1;
44      }
45  
46      public synchronized void incrementErrorsCount()
47      {
48          errors += 1;
49      }
50  
51      public synchronized void incrementFailureCount()
52      {
53          failures += 1;
54      }
55  
56      public synchronized void incrementSkippedCount()
57      {
58          skipped += 1;
59      }
60  
61      public synchronized boolean hadFailures()
62      {
63          return failures > 0;
64      }
65  
66      public synchronized void reset()
67      {
68          completedCount = 0;
69          errors = 0;
70          failures = 0;
71          skipped = 0;
72      }
73  
74      public synchronized boolean hadErrors()
75      {
76          return errors > 0;
77      }
78  
79      public synchronized int getCompletedCount()
80      {
81          return completedCount;
82      }
83  
84      public int getSkipped()
85      {
86          return skipped;
87      }
88  
89      public synchronized void add( TestSetStatistics testSetStatistics )
90      {
91          this.completedCount += testSetStatistics.completedCount;
92          this.errors += testSetStatistics.errors;
93          this.failures += testSetStatistics.failures;
94          this.skipped += testSetStatistics.skipped;
95      }
96  
97      public synchronized RunResult getRunResult()
98      {
99          return new RunResult( completedCount, errors, failures, skipped );
100     }
101 
102     public synchronized String getSummary()
103     {
104         return "Tests run: " + completedCount + ", Failures: " + failures + ", Errors: " + errors + ", Skipped: "
105             + skipped;
106     }
107 
108 }