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