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
22 import java.util.StringTokenizer;
23 import org.apache.maven.surefire.report.ReportEntry;
24
25
26
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 }