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