View Javadoc
1   package org.apache.maven.plugin.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.List;
23  
24  import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
25  import org.apache.maven.shared.utils.logging.MessageBuilder;
26  import org.apache.maven.surefire.report.ReportEntry;
27  import org.apache.maven.plugin.surefire.log.api.Level;
28  
29  import static org.apache.maven.plugin.surefire.log.api.Level.resolveLevel;
30  import static org.apache.maven.plugin.surefire.report.TestSetStats.concatenateWithTestGroup;
31  import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
32  
33  /**
34   * Base class for console reporters.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   * @author Kristian Rosenvold
38   */
39  public class ConsoleReporter
40  {
41      public static final String BRIEF = "brief";
42  
43      public static final String PLAIN = "plain";
44  
45      private static final String TEST_SET_STARTING_PREFIX = "Running ";
46  
47      private final ConsoleLogger logger;
48  
49      public ConsoleReporter( ConsoleLogger logger )
50      {
51          this.logger = logger;
52      }
53  
54      public ConsoleLogger getConsoleLogger()
55      {
56          return logger;
57      }
58  
59      public void testSetStarting( ReportEntry report )
60      {
61          MessageBuilder builder = buffer();
62          logger.info( concatenateWithTestGroup( builder.a( TEST_SET_STARTING_PREFIX ), report ) );
63      }
64  
65      public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List<String> testResults )
66      {
67          boolean success = testSetStats.getCompletedCount() > 0;
68          boolean failures = testSetStats.getFailures() > 0;
69          boolean errors = testSetStats.getErrors() > 0;
70          boolean skipped = testSetStats.getSkipped() > 0;
71          boolean flakes = testSetStats.getSkipped() > 0;
72          Level level = resolveLevel( success, failures, errors, skipped, flakes );
73  
74          println( testSetStats.getColoredTestSetSummary( report ), level );
75          for ( String testResult : testResults )
76          {
77              println( testResult, level );
78          }
79      }
80  
81      public void reset()
82      {
83      }
84  
85      private void println( String message, Level level )
86      {
87          switch ( level )
88          {
89              case FAILURE:
90                  logger.error( message );
91                  break;
92              case UNSTABLE:
93                  logger.warning( message );
94                  break;
95              default:
96                  logger.info( message );
97          }
98      }
99  }