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  
25  /**
26   * @author Kristian Rosenvold
27   */
28  public class CategorizedReportEntry
29      extends SimpleReportEntry
30      implements ReportEntry
31  {
32      private 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, name, 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, name, group, stackTraceWriter, elapsed, message, Collections.<String, String>emptyMap() );
54      }
55  
56      public CategorizedReportEntry( String source, String name, String group, StackTraceWriter stackTraceWriter,
57                                     Integer elapsed, String message, Map<String, String> systemProperties )
58      {
59          super( source, name, stackTraceWriter, elapsed, message, systemProperties );
60          this.group = group;
61      }
62  
63      public static TestSetReportEntry reportEntry( String source, String name, String group,
64                                                    StackTraceWriter stackTraceWriter, Integer elapsed, String message,
65                                                    Map<String, String> systemProperties )
66      {
67          return group != null
68              ? new CategorizedReportEntry( source, name, group, stackTraceWriter, elapsed, message, systemProperties )
69              : new SimpleReportEntry( source, name, stackTraceWriter, elapsed, message, systemProperties );
70      }
71  
72      @Override
73      public String getGroup()
74      {
75          return group;
76      }
77  
78      @Override
79      public String getNameWithGroup()
80      {
81          return isNameWithGroup() ? getName() + GROUP_PREFIX + getGroup() + GROUP_SUFIX : getName();
82      }
83  
84      @Override
85      public boolean equals( Object o )
86      {
87          if ( this == o )
88          {
89              return true;
90          }
91          if ( o == null || getClass() != o.getClass() )
92          {
93              return false;
94          }
95          if ( !super.equals( o ) )
96          {
97              return false;
98          }
99  
100         CategorizedReportEntry that = (CategorizedReportEntry) o;
101 
102         return !( group != null ? !group.equals( that.group ) : that.group != null );
103 
104     }
105 
106     @Override
107     public int hashCode()
108     {
109         int result = super.hashCode();
110         result = 31 * result + ( group != null ? group.hashCode() : 0 );
111         return result;
112     }
113 
114     private boolean isNameWithGroup()
115     {
116         return getGroup() != null && !getGroup().equals( getName() );
117     }
118 }