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 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 this( completedCount, errors, failures, skipped, false, false );
54 }
55
56 public RunResult( int completedCount, int errors, int failures, int skipped, boolean failure, boolean timeout )
57 {
58 this.completedCount = completedCount;
59 this.errors = errors;
60 this.failures = failures;
61 this.skipped = skipped;
62 this.failure = failure;
63 this.timeout = timeout;
64 }
65
66 public int getCompletedCount()
67 {
68 return completedCount;
69 }
70
71 public int getErrors()
72 {
73 return errors;
74 }
75
76 public int getFailures()
77 {
78 return failures;
79 }
80
81 public int getSkipped()
82 {
83 return skipped;
84 }
85
86 public int getForkedProcessCode()
87 {
88 return completedCount == 0 ? NO_TESTS : isErrrorFree() ? SUCCESS : FAILURE;
89 }
90
91 public boolean isErrrorFree()
92 {
93 return getFailures() == 0 && getErrors() == 0;
94 }
95
96 public String getAsString()
97 {
98 return getCompletedCount() + "," + getErrors() + "," + getFailures() + "," + getSkipped() + "," + isFailure()
99 + "," + isTimeout();
100 }
101
102 public static RunResult fromString( String string )
103 {
104 StringTokenizer strTok = new StringTokenizer( string, "," );
105 int completed = Integer.parseInt( strTok.nextToken() );
106 int errors = Integer.parseInt( strTok.nextToken() );
107 int failures = Integer.parseInt( strTok.nextToken() );
108 int skipped = Integer.parseInt( strTok.nextToken() );
109 boolean isFailure = Boolean.parseBoolean( strTok.nextToken() );
110 boolean isTimeout = Boolean.parseBoolean( strTok.nextToken() );
111 return new RunResult( completed, errors, failures, skipped, isFailure, isTimeout );
112 }
113
114 public boolean isFailureOrTimeout()
115 {
116 return this.timeout || this.failure;
117 }
118
119 public boolean isFailure()
120 {
121 return failure;
122 }
123
124 public boolean isTimeout()
125 {
126 return timeout;
127 }
128
129
130 public RunResult aggregate( RunResult other )
131 {
132 boolean failure = isFailure() || other.isFailure();
133 boolean timeout = isTimeout() || other.isTimeout();
134 int completed = getCompletedCount() + other.getCompletedCount();
135 int fail = getFailures() + other.getFailures();
136 int ign = getSkipped() + other.getSkipped();
137 int err = getErrors() + other.getErrors();
138 return new RunResult( completed, err, fail, ign, failure, timeout );
139 }
140 }