View Javadoc

1   package org.apache.maven.plugin.surefire.runorder;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import java.util.StringTokenizer;
22  import org.apache.maven.surefire.report.ReportEntry;
23  
24  /**
25   * @author Kristian Rosenvold
26   */
27  public class RunEntryStatistics
28  {
29      private final int runTime;
30  
31      private final int successfulBuilds;
32  
33      private final String testName;
34  
35      private RunEntryStatistics( int runTime, int successfulBuilds, String testName )
36      {
37          this.runTime = runTime;
38          this.successfulBuilds = successfulBuilds;
39          this.testName = testName;
40      }
41  
42      public static RunEntryStatistics fromReportEntry( ReportEntry previous )
43      {
44          final Integer elapsed = previous.getElapsed();
45          return new RunEntryStatistics( elapsed != null ? elapsed : 0, 0, previous.getName() );
46      }
47  
48      public static RunEntryStatistics fromValues( int runTime, int successfulBuilds, Class clazz, String testName )
49      {
50          return new RunEntryStatistics( runTime, successfulBuilds, testName + "(" + clazz.getName() + ")" );
51      }
52  
53      public RunEntryStatistics nextGeneration( int runTime )
54      {
55          return new RunEntryStatistics( runTime, this.successfulBuilds + 1, this.testName );
56      }
57  
58      public RunEntryStatistics nextGenerationFailure( int runTime )
59      {
60          return new RunEntryStatistics( runTime, 0, this.testName );
61      }
62  
63      public String getTestName()
64      {
65          return testName;
66      }
67  
68      public int getRunTime()
69      {
70          return runTime;
71      }
72  
73  
74      public int getSuccessfulBuilds()
75      {
76          return successfulBuilds;
77      }
78  
79      public static RunEntryStatistics fromString( String line )
80      {
81          StringTokenizer tok = new StringTokenizer( line, "," );
82          int successfulBuilds = Integer.parseInt( tok.nextToken() );
83          int runTime = Integer.parseInt( tok.nextToken() );
84          String className = tok.nextToken();
85          return new RunEntryStatistics( runTime, successfulBuilds, className );
86      }
87  
88      public String getAsString()
89      {
90          StringBuilder stringBuffer = new StringBuilder();
91          stringBuffer.append( successfulBuilds );
92          stringBuffer.append( "," );
93          stringBuffer.append( runTime );
94          stringBuffer.append( "," );
95          stringBuffer.append( testName );
96          return stringBuffer.toString();
97      }
98  
99  }