1 | |
package org.apache.maven.surefire.suite; |
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 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class RunResult |
30 | |
{ |
31 | |
private final int completedCount; |
32 | |
|
33 | |
private final int errors; |
34 | |
|
35 | |
private final int failures; |
36 | |
|
37 | |
private final int skipped; |
38 | |
|
39 | |
private final boolean failure; |
40 | |
|
41 | |
private final boolean timeout; |
42 | |
|
43 | |
public static final int SUCCESS = 0; |
44 | |
|
45 | |
private static final int FAILURE = 255; |
46 | |
|
47 | |
private static final int NO_TESTS = 254; |
48 | |
|
49 | 0 | public static final RunResult Timeout = new RunResult( 0, 0, 0, 0, false, true ); |
50 | |
|
51 | |
public RunResult( int completedCount, int errors, int failures, int skipped ) |
52 | |
{ |
53 | 0 | this( completedCount, errors, failures, skipped, false, false ); |
54 | 0 | } |
55 | |
|
56 | |
public RunResult( int completedCount, int errors, int failures, int skipped, boolean failure, boolean timeout ) |
57 | 0 | { |
58 | 0 | this.completedCount = completedCount; |
59 | 0 | this.errors = errors; |
60 | 0 | this.failures = failures; |
61 | 0 | this.skipped = skipped; |
62 | 0 | this.failure = failure; |
63 | 0 | this.timeout = timeout; |
64 | 0 | } |
65 | |
|
66 | |
public int getCompletedCount() |
67 | |
{ |
68 | 0 | return completedCount; |
69 | |
} |
70 | |
|
71 | |
public int getErrors() |
72 | |
{ |
73 | 0 | return errors; |
74 | |
} |
75 | |
|
76 | |
public int getFailures() |
77 | |
{ |
78 | 0 | return failures; |
79 | |
} |
80 | |
|
81 | |
public int getSkipped() |
82 | |
{ |
83 | 0 | return skipped; |
84 | |
} |
85 | |
|
86 | |
public int getForkedProcessCode() |
87 | |
{ |
88 | 0 | return completedCount == 0 ? NO_TESTS : isErrrorFree() ? SUCCESS : FAILURE; |
89 | |
} |
90 | |
|
91 | |
public boolean isErrrorFree() |
92 | |
{ |
93 | 0 | return getFailures() == 0 && getErrors() == 0; |
94 | |
} |
95 | |
|
96 | |
public String getAsString() |
97 | |
{ |
98 | 0 | return getCompletedCount() + "," + getErrors() + "," + getFailures() + "," + getSkipped() + "," + isFailure() |
99 | |
+ "," + isTimeout(); |
100 | |
} |
101 | |
|
102 | |
public static RunResult fromString( String string ) |
103 | |
{ |
104 | 0 | StringTokenizer strTok = new StringTokenizer( string, "," ); |
105 | 0 | int completed = Integer.parseInt( strTok.nextToken() ); |
106 | 0 | int errors = Integer.parseInt( strTok.nextToken() ); |
107 | 0 | int failures = Integer.parseInt( strTok.nextToken() ); |
108 | 0 | int skipped = Integer.parseInt( strTok.nextToken() ); |
109 | 0 | boolean isFailure = Boolean.parseBoolean( strTok.nextToken() ); |
110 | 0 | boolean isTimeout = Boolean.parseBoolean( strTok.nextToken() ); |
111 | 0 | return new RunResult( completed, errors, failures, skipped, isFailure, isTimeout ); |
112 | |
} |
113 | |
|
114 | |
public boolean isFailureOrTimeout() |
115 | |
{ |
116 | 0 | return this.timeout || this.failure; |
117 | |
} |
118 | |
|
119 | |
public boolean isFailure() |
120 | |
{ |
121 | 0 | return failure; |
122 | |
} |
123 | |
|
124 | |
public boolean isTimeout() |
125 | |
{ |
126 | 0 | return timeout; |
127 | |
} |
128 | |
|
129 | |
|
130 | |
public RunResult aggregate( RunResult other ) |
131 | |
{ |
132 | 0 | boolean failure = isFailure() || other.isFailure(); |
133 | 0 | boolean timeout = isTimeout() || other.isTimeout(); |
134 | 0 | int completed = getCompletedCount() + other.getCompletedCount(); |
135 | 0 | int fail = getFailures() + other.getFailures(); |
136 | 0 | int ign = getSkipped() + other.getSkipped(); |
137 | 0 | int err = getErrors() + other.getErrors(); |
138 | 0 | return new RunResult( completed, err, fail, ign, failure, timeout ); |
139 | |
} |
140 | |
} |