1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.api.report;
20
21 import javax.annotation.Nonnegative;
22 import javax.annotation.Nonnull;
23
24 import java.util.Collections;
25 import java.util.Map;
26 import java.util.Objects;
27
28 import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;
29
30
31
32
33 public class CategorizedReportEntry extends SimpleReportEntry {
34 public static final String GROUP_PREFIX = " (of ";
35
36 private static final String GROUP_SUFIX = ")";
37
38 private final String group;
39
40 public CategorizedReportEntry(
41 @Nonnull RunMode runMode, @Nonnegative Long testRunId, String source, String name, String group) {
42 this(runMode, testRunId, source, name, group, null, null);
43 }
44
45 public CategorizedReportEntry(
46 @Nonnull RunMode runMode,
47 @Nonnegative Long testRunId,
48 String source,
49 String name,
50 String group,
51 StackTraceWriter stackTraceWriter,
52 Integer elapsed) {
53 super(runMode, testRunId, source, null, name, null, stackTraceWriter, elapsed);
54 this.group = group;
55 }
56
57 public CategorizedReportEntry(
58 @Nonnull RunMode runMode,
59 @Nonnegative Long testRunId,
60 String source,
61 String name,
62 String group,
63 StackTraceWriter stackTraceWriter,
64 Integer elapsed,
65 String message) {
66 this(
67 runMode,
68 testRunId,
69 source,
70 null,
71 name,
72 null,
73 group,
74 stackTraceWriter,
75 elapsed,
76 message,
77 Collections.<String, String>emptyMap());
78 }
79
80 public CategorizedReportEntry(
81 @Nonnull RunMode runMode,
82 @Nonnegative Long testRunId,
83 String source,
84 String sourceText,
85 String name,
86 String nameText,
87 String group,
88 StackTraceWriter stackTraceWriter,
89 Integer elapsed,
90 String message,
91 Map<String, String> systemProperties) {
92 super(
93 runMode,
94 testRunId,
95 source,
96 sourceText,
97 name,
98 nameText,
99 stackTraceWriter,
100 elapsed,
101 message,
102 systemProperties);
103 this.group = group;
104 }
105
106 public static TestSetReportEntry reportEntry(
107 @Nonnull RunMode runMode,
108 @Nonnegative Long testRunId,
109 String source,
110 String sourceText,
111 String name,
112 String nameText,
113 String group,
114 StackTraceWriter stackTraceWriter,
115 Integer elapsed,
116 String message,
117 Map<String, String> systemProperties) {
118 return group != null
119 ? new CategorizedReportEntry(
120 runMode,
121 testRunId,
122 source,
123 sourceText,
124 name,
125 nameText,
126 group,
127 stackTraceWriter,
128 elapsed,
129 message,
130 systemProperties)
131 : new SimpleReportEntry(
132 runMode,
133 testRunId,
134 source,
135 sourceText,
136 name,
137 nameText,
138 stackTraceWriter,
139 elapsed,
140 message,
141 systemProperties);
142 }
143
144 @Override
145 public String getGroup() {
146 return group;
147 }
148
149 @Override
150 public String getNameWithGroup() {
151 return isNameWithGroup() ? getSourceName() + GROUP_PREFIX + getGroup() + GROUP_SUFIX : getSourceName();
152 }
153
154 @Override
155 public String getReportNameWithGroup() {
156 String sourceText = getSourceText();
157
158 if (isBlank(sourceText)) {
159 return null;
160 }
161
162 return isNameWithGroup() ? sourceText + GROUP_PREFIX + getGroup() + GROUP_SUFIX : sourceText;
163 }
164
165 @Override
166 public boolean equals(Object o) {
167 if (this == o) {
168 return true;
169 }
170 if (o == null || getClass() != o.getClass()) {
171 return false;
172 }
173 if (!super.equals(o)) {
174 return false;
175 }
176
177 CategorizedReportEntry that = (CategorizedReportEntry) o;
178
179 return Objects.equals(group, that.group);
180 }
181
182 @Override
183 public int hashCode() {
184 int result = super.hashCode();
185 result = 31 * result + (group != null ? group.hashCode() : 0);
186 return result;
187 }
188
189 private boolean isNameWithGroup() {
190 return getGroup() != null && !getGroup().equals(getSourceName());
191 }
192 }