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 private static final int SUCCESS = 0;
44
45 public static final int FAILURE = 255;
46
47 public 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 getBooterCode()
87 {
88 return isErrrorFree() ? SUCCESS : FAILURE;
89 }
90
91 public int getForkedProcessCode()
92 {
93 return completedCount == 0 ? NO_TESTS : isErrrorFree() ? SUCCESS : FAILURE;
94 }
95
96 public boolean isErrrorFree()
97 {
98 return getFailures() == 0 && getErrors() == 0;
99 }
100
101 public String getAsString()
102 {
103 return getCompletedCount() + "," + getErrors() + "," + getFailures() + "," + getSkipped() + "," + isFailure()
104 + "," + isTimeout();
105 }
106
107 public static RunResult fromString( String string )
108 {
109 StringTokenizer strTok = new StringTokenizer( string, "," );
110 int completed = Integer.parseInt( strTok.nextToken() );
111 int errors = Integer.parseInt( strTok.nextToken() );
112 int failures = Integer.parseInt( strTok.nextToken() );
113 int skipped = Integer.parseInt( strTok.nextToken() );
114 boolean isFailure = Boolean.parseBoolean( strTok.nextToken() );
115 boolean isTimeout = Boolean.parseBoolean( strTok.nextToken() );
116 return new RunResult( completed, errors, failures, skipped, isFailure, isTimeout );
117 }
118
119 public boolean isFailureOrTimeout()
120 {
121 return this.timeout || this.failure;
122 }
123
124 public boolean isFailure()
125 {
126 return failure;
127 }
128
129 public boolean isTimeout()
130 {
131 return timeout;
132 }
133
134 public RunResult aggregate( RunResult other )
135 {
136 boolean failure = isFailure() || other.isFailure();
137 boolean timeout = isTimeout() || other.isTimeout();
138 int completed = getCompletedCount() + other.getCompletedCount();
139 int fail = getFailures() + other.getFailures();
140 int ign = getSkipped() + other.getSkipped();
141 int err = getErrors() + other.getErrors();
142 return new RunResult( completed, err, fail, ign, failure, timeout );
143 }
144 }