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
29
30
31 public class CategorizedReportEntry
32 extends SimpleReportEntry
33 {
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( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
41 String source, String name, String group )
42 {
43 this( runMode, testRunId, source, name, group, null, null );
44 }
45
46 public CategorizedReportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
47 String source, String name, String group, StackTraceWriter stackTraceWriter,
48 Integer elapsed )
49 {
50 super( runMode, testRunId, source, null, name, null, stackTraceWriter, elapsed );
51 this.group = group;
52 }
53
54 public CategorizedReportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
55 String source, String name, String group, StackTraceWriter stackTraceWriter,
56 Integer elapsed, String message )
57 {
58 this( runMode, testRunId, source, null, name, null,
59 group, stackTraceWriter, elapsed, message, Collections.<String, String>emptyMap() );
60 }
61
62 public CategorizedReportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
63 String source, String sourceText, String name, String nameText,
64 String group, StackTraceWriter stackTraceWriter,
65 Integer elapsed, String message, Map<String, String> systemProperties )
66 {
67 super( runMode, testRunId, source, sourceText, name, nameText, stackTraceWriter, elapsed, message,
68 systemProperties );
69 this.group = group;
70 }
71
72 public static TestSetReportEntry reportEntry( @Nonnull RunMode runMode, @Nonnegative Long testRunId,
73 String source, String sourceText, String name, String nameText,
74 String group,
75 StackTraceWriter stackTraceWriter, Integer elapsed, String message,
76 Map<String, String> systemProperties )
77 {
78 return group != null
79 ? new CategorizedReportEntry( runMode, testRunId, source, sourceText, name, nameText,
80 group, stackTraceWriter, elapsed, message, systemProperties )
81 : new SimpleReportEntry( runMode, testRunId, source, sourceText, name, nameText,
82 stackTraceWriter, elapsed, message, systemProperties );
83 }
84
85 @Override
86 public String getGroup()
87 {
88 return group;
89 }
90
91 @Override
92 public String getNameWithGroup()
93 {
94 return isNameWithGroup() ? getSourceName() + GROUP_PREFIX + getGroup() + GROUP_SUFIX : getSourceName();
95 }
96
97 @Override
98 public String getReportNameWithGroup()
99 {
100 return isNameWithGroup() ? getSourceText() + GROUP_PREFIX + getGroup() + GROUP_SUFIX : getSourceText();
101 }
102
103 @Override
104 public boolean equals( Object o )
105 {
106 if ( this == o )
107 {
108 return true;
109 }
110 if ( o == null || getClass() != o.getClass() )
111 {
112 return false;
113 }
114 if ( !super.equals( o ) )
115 {
116 return false;
117 }
118
119 CategorizedReportEntry that = (CategorizedReportEntry) o;
120
121 return Objects.equals( group, that.group );
122 }
123
124 @Override
125 public int hashCode()
126 {
127 int result = super.hashCode();
128 result = 31 * result + ( group != null ? group.hashCode() : 0 );
129 return result;
130 }
131
132 private boolean isNameWithGroup()
133 {
134 return getGroup() != null && !getGroup().equals( getSourceName() );
135 }
136 }