View Javadoc
1   package org.apache.maven.surefire.report;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Collections;
23  import java.util.Map;
24  import java.util.Objects;
25  
26  /**
27   * @author Kristian Rosenvold
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 }