View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.surefire.runorder;
20  
21  import java.io.File;
22  import java.io.IOException;
23  
24  import org.apache.maven.surefire.api.report.ReportEntry;
25  import org.apache.maven.surefire.api.runorder.RunEntryStatisticsMap;
26  
27  import static org.apache.maven.surefire.api.runorder.RunEntryStatisticsMap.fromFile;
28  
29  /**
30   * @author Kristian Rosenvold
31   */
32  public class StatisticsReporter {
33      private final RunEntryStatisticsMap existing;
34  
35      private final RunEntryStatisticsMap newResults;
36  
37      private final File dataFile;
38  
39      public StatisticsReporter(File dataFile) {
40          this(dataFile, fromFile(dataFile), new RunEntryStatisticsMap());
41      }
42  
43      protected StatisticsReporter(File dataFile, RunEntryStatisticsMap existing, RunEntryStatisticsMap newResults) {
44          this.dataFile = dataFile;
45          this.existing = existing;
46          this.newResults = newResults;
47      }
48  
49      public synchronized void testSetCompleted() {
50          try {
51              newResults.serialize(dataFile);
52          } catch (IOException e) {
53              throw new RuntimeException(e);
54          }
55      }
56  
57      public void testSucceeded(ReportEntry report) {
58          newResults.add(existing.createNextGeneration(report));
59      }
60  
61      public void testSkipped(ReportEntry report) {
62          newResults.add(existing.createNextGeneration(report));
63      }
64  
65      public void testError(ReportEntry report) {
66          newResults.add(existing.createNextGenerationFailure(report));
67      }
68  
69      public void testFailed(ReportEntry report) {
70          newResults.add(existing.createNextGenerationFailure(report));
71      }
72  }