View Javadoc

1   package org.apache.maven.surefire.suite;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.StringTokenizer;
23  
24  /**
25   * Represents a test-run-result; this may be from a single test run or an aggregated result.
26   *
27   * @author Kristian Rosenvold
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 }