View Javadoc
1   package org.apache.maven.surefire.api.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 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   * @author Kristian Rosenvold
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 }