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  /**
23   * @author Kristian Rosenvold
24   */
25  public class CategorizedReportEntry
26      extends SimpleReportEntry
27      implements ReportEntry
28  {
29      private static final String GROUP_PREFIX = " (of ";
30  
31      private static final String GROUP_SUFIX = ")";
32  
33      private final String group;
34  
35      public CategorizedReportEntry( String source, String name, String group )
36      {
37          this( source, name, group, null, null );
38      }
39  
40      public CategorizedReportEntry( String source, String name, String group, StackTraceWriter stackTraceWriter,
41                                     Integer elapsed )
42      {
43          super( source, name, stackTraceWriter, elapsed );
44          this.group = group;
45      }
46  
47      public CategorizedReportEntry( String source, String name, String group, StackTraceWriter stackTraceWriter,
48                                     Integer elapsed, String message )
49      {
50          super( source, name, stackTraceWriter, elapsed, message );
51          this.group = group;
52      }
53  
54      public static ReportEntry reportEntry( String source, String name, String group, StackTraceWriter stackTraceWriter,
55                                             Integer elapsed, String message )
56      {
57          return group != null
58              ? new CategorizedReportEntry( source, name, group, stackTraceWriter, elapsed, message )
59              : new SimpleReportEntry( source, name, stackTraceWriter, elapsed, message );
60      }
61  
62      public String getGroup()
63      {
64          return group;
65      }
66  
67      @Override
68      public String getNameWithGroup()
69      {
70          StringBuilder result = new StringBuilder();
71          result.append( getName() );
72  
73          if ( getGroup() != null && !getName().equals( getGroup() ) )
74          {
75              result.append( GROUP_PREFIX );
76              result.append( getGroup() );
77              result.append( GROUP_SUFIX );
78          }
79  
80          return result.toString();
81      }
82  
83      public boolean equals( Object o )
84      {
85          if ( this == o )
86          {
87              return true;
88          }
89          if ( o == null || getClass() != o.getClass() )
90          {
91              return false;
92          }
93          if ( !super.equals( o ) )
94          {
95              return false;
96          }
97  
98          CategorizedReportEntry that = (CategorizedReportEntry) o;
99  
100         return !( group != null ? !group.equals( that.group ) : that.group != null );
101 
102     }
103 
104     public int hashCode()
105     {
106         int result = super.hashCode();
107         result = 31 * result + ( group != null ? group.hashCode() : 0 );
108         return result;
109     }
110 }