View Javadoc
1   package org.apache.maven.plugin.surefire.runorder;
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 java.util.StringTokenizer;
23  import org.apache.maven.surefire.report.ReportEntry;
24  
25  /**
26   * @author Kristian Rosenvold
27   */
28  public class RunEntryStatistics
29  {
30      private final int runTime;
31  
32      private final int successfulBuilds;
33  
34      private final String testName;
35  
36      private RunEntryStatistics( int runTime, int successfulBuilds, String testName )
37      {
38          this.runTime = runTime;
39          this.successfulBuilds = successfulBuilds;
40          this.testName = testName;
41      }
42  
43      public static RunEntryStatistics fromReportEntry( ReportEntry previous )
44      {
45          final Integer elapsed = previous.getElapsed();
46          return new RunEntryStatistics( elapsed != null ? elapsed : 0, 0, previous.getName() );
47      }
48  
49      public static RunEntryStatistics fromValues( int runTime, int successfulBuilds, Class clazz, String testName )
50      {
51          return new RunEntryStatistics( runTime, successfulBuilds, testName + "(" + clazz.getName() + ")" );
52      }
53  
54      public RunEntryStatistics nextGeneration( int runTime )
55      {
56          return new RunEntryStatistics( runTime, this.successfulBuilds + 1, this.testName );
57      }
58  
59      public RunEntryStatistics nextGenerationFailure( int runTime )
60      {
61          return new RunEntryStatistics( runTime, 0, this.testName );
62      }
63  
64      public String getTestName()
65      {
66          return testName;
67      }
68  
69      public int getRunTime()
70      {
71          return runTime;
72      }
73  
74  
75      public int getSuccessfulBuilds()
76      {
77          return successfulBuilds;
78      }
79  
80      public static RunEntryStatistics fromString( String line )
81      {
82          StringTokenizer tok = new StringTokenizer( line, "," );
83          int successfulBuilds = Integer.parseInt( tok.nextToken() );
84          int runTime = Integer.parseInt( tok.nextToken() );
85          String className = tok.nextToken();
86          return new RunEntryStatistics( runTime, successfulBuilds, className );
87      }
88  
89      public String getAsString()
90      {
91          StringBuilder stringBuffer = new StringBuilder();
92          stringBuffer.append( successfulBuilds );
93          stringBuffer.append( "," );
94          stringBuffer.append( runTime );
95          stringBuffer.append( "," );
96          stringBuffer.append( testName );
97          return stringBuffer.toString();
98      }
99  
100 }