1 package org.apache.maven.surefire.api.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.annotation.Nonnegative;
23 import javax.annotation.Nonnull;
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
34 extends SimpleReportEntry
35 {
36 public static final String GROUP_PREFIX = " (of ";
37
38 private static final String GROUP_SUFIX = ")";
39
40 private final String group;
41
42 public CategorizedReportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
43 String source, String name, String group )
44 {
45 this( runMode, testRunId, source, name, group, null, null );
46 }
47
48 public CategorizedReportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
49 String source, String name, String group, StackTraceWriter stackTraceWriter,
50 Integer elapsed )
51 {
52 super( runMode, testRunId, source, null, name, null, stackTraceWriter, elapsed );
53 this.group = group;
54 }
55
56 public CategorizedReportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
57 String source, String name, String group, StackTraceWriter stackTraceWriter,
58 Integer elapsed, String message )
59 {
60 this( runMode, testRunId, source, null, name, null,
61 group, stackTraceWriter, elapsed, message, Collections.<String, String>emptyMap() );
62 }
63
64 public CategorizedReportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
65 String source, String sourceText, String name, String nameText,
66 String group, StackTraceWriter stackTraceWriter,
67 Integer elapsed, String message, Map<String, String> systemProperties )
68 {
69 super( runMode, testRunId, source, sourceText, name, nameText, stackTraceWriter, elapsed, message,
70 systemProperties );
71 this.group = group;
72 }
73
74 public static TestSetReportEntry reportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
75 String source, String sourceText, String name, String nameText,
76 String group,
77 StackTraceWriter stackTraceWriter, Integer elapsed, String message,
78 Map<String, String> systemProperties )
79 {
80 return group != null
81 ? new CategorizedReportEntry( runMode, testRunId, source, sourceText, name, nameText,
82 group, stackTraceWriter, elapsed, message, systemProperties )
83 : new SimpleReportEntry( runMode, testRunId, source, sourceText, name, nameText,
84 stackTraceWriter, elapsed, message, systemProperties );
85 }
86
87 @Override
88 public String getGroup()
89 {
90 return group;
91 }
92
93 @Override
94 public String getNameWithGroup()
95 {
96 return isNameWithGroup() ? getSourceName() + GROUP_PREFIX + getGroup() + GROUP_SUFIX : getSourceName();
97 }
98
99 @Override
100 public String getReportNameWithGroup()
101 {
102 String sourceText = getSourceText();
103
104 if ( isBlank ( sourceText ) )
105 {
106 return null;
107 }
108
109 return isNameWithGroup() ? sourceText + GROUP_PREFIX + getGroup() + GROUP_SUFIX : sourceText;
110 }
111
112 @Override
113 public boolean equals( Object o )
114 {
115 if ( this == o )
116 {
117 return true;
118 }
119 if ( o == null || getClass() != o.getClass() )
120 {
121 return false;
122 }
123 if ( !super.equals( o ) )
124 {
125 return false;
126 }
127
128 CategorizedReportEntry that = (CategorizedReportEntry) o;
129
130 return Objects.equals( group, that.group );
131 }
132
133 @Override
134 public int hashCode()
135 {
136 int result = super.hashCode();
137 result = 31 * result + ( group != null ? group.hashCode() : 0 );
138 return result;
139 }
140
141 private boolean isNameWithGroup()
142 {
143 return getGroup() != null && !getGroup().equals( getSourceName() );
144 }
145 }