1 package org.apache.maven.plugin.surefire.runorder;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.StringTokenizer;
22 import org.apache.maven.surefire.report.ReportEntry;
23
24
25
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 }