View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.surefire.report;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   *
26   */
27  public final class ReportTestSuite {
28      private final List<ReportTestCase> testCases = new ArrayList<>();
29  
30      private int numberOfErrors;
31  
32      private int numberOfFailures;
33  
34      private int numberOfSkipped;
35  
36      private int numberOfFlakes;
37  
38      private Integer numberOfTests;
39  
40      private String name;
41  
42      private String fullClassName;
43  
44      private String packageName;
45  
46      private float timeElapsed;
47  
48      public List<ReportTestCase> getTestCases() {
49          return testCases;
50      }
51  
52      public int getNumberOfErrors() {
53          return numberOfErrors;
54      }
55  
56      public ReportTestSuite setNumberOfErrors(int numberOfErrors) {
57          this.numberOfErrors = numberOfErrors;
58          return this;
59      }
60  
61      public ReportTestSuite incrementNumberOfErrors() {
62          ++numberOfErrors;
63          return this;
64      }
65  
66      public int getNumberOfFailures() {
67          return numberOfFailures;
68      }
69  
70      public ReportTestSuite setNumberOfFailures(int numberOfFailures) {
71          this.numberOfFailures = numberOfFailures;
72          return this;
73      }
74  
75      public ReportTestSuite incrementNumberOfFailures() {
76          ++numberOfFailures;
77          return this;
78      }
79  
80      public int getNumberOfSkipped() {
81          return numberOfSkipped;
82      }
83  
84      public ReportTestSuite setNumberOfSkipped(int numberOfSkipped) {
85          this.numberOfSkipped = numberOfSkipped;
86          return this;
87      }
88  
89      public ReportTestSuite incrementNumberOfSkipped() {
90          ++numberOfSkipped;
91          return this;
92      }
93  
94      public int getNumberOfFlakes() {
95          return numberOfFlakes;
96      }
97  
98      public ReportTestSuite setNumberOfFlakes(int numberOfFlakes) {
99          this.numberOfFlakes = numberOfFlakes;
100         return this;
101     }
102 
103     public ReportTestSuite incrementNumberOfFlakes() {
104         ++numberOfFlakes;
105         return this;
106     }
107 
108     public int getNumberOfTests() {
109         return numberOfTests == null ? testCases.size() : numberOfTests;
110     }
111 
112     public ReportTestSuite setNumberOfTests(int numberOfTests) {
113         this.numberOfTests = numberOfTests;
114         return this;
115     }
116 
117     public String getName() {
118         return name;
119     }
120 
121     public ReportTestSuite setName(String name) {
122         this.name = name;
123         return this;
124     }
125 
126     public String getFullClassName() {
127         return fullClassName;
128     }
129 
130     public ReportTestSuite setFullClassName(String fullClassName) {
131         this.fullClassName = fullClassName;
132         int lastDotPosition = fullClassName.lastIndexOf(".");
133         name = fullClassName.substring(lastDotPosition + 1, fullClassName.length());
134         packageName = lastDotPosition == -1 ? "" : fullClassName.substring(0, lastDotPosition);
135         return this;
136     }
137 
138     public String getPackageName() {
139         return packageName;
140     }
141 
142     public ReportTestSuite setPackageName(String packageName) {
143         this.packageName = packageName;
144         return this;
145     }
146 
147     public float getTimeElapsed() {
148         return this.timeElapsed;
149     }
150 
151     public ReportTestSuite setTimeElapsed(float timeElapsed) {
152         this.timeElapsed = timeElapsed;
153         return this;
154     }
155 
156     ReportTestSuite setTestCases(List<ReportTestCase> testCases) {
157         this.testCases.clear();
158         this.testCases.addAll(testCases);
159         return this;
160     }
161 
162     /**
163      * {@inheritDoc}
164      */
165     @Override
166     public String toString() {
167         return fullClassName + " [" + getNumberOfTests() + "/" + getNumberOfFailures() + "/" + getNumberOfErrors() + "/"
168                 + getNumberOfSkipped() + "]";
169     }
170 }