Coverage Report - org.apache.maven.plugin.surefire.report.DefaultReporterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultReporterFactory
33%
14/42
0%
0/12
1,667
 
 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.ArrayList;
 23  
 import java.util.Collections;
 24  
 import java.util.List;
 25  
 import org.apache.maven.plugin.surefire.StartupReportConfiguration;
 26  
 import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
 27  
 import org.apache.maven.surefire.report.DefaultDirectConsoleReporter;
 28  
 import org.apache.maven.surefire.report.ReporterFactory;
 29  
 import org.apache.maven.surefire.report.RunListener;
 30  
 import org.apache.maven.surefire.report.RunStatistics;
 31  
 import org.apache.maven.surefire.suite.RunResult;
 32  
 
 33  
 /**
 34  
  * Provides reporting modules on the plugin side.
 35  
  * <p/>
 36  
  * Keeps a centralized count of test run results.
 37  
  *
 38  
  * @author Kristian Rosenvold
 39  
  */
 40  
 public class DefaultReporterFactory
 41  
     implements ReporterFactory
 42  
 {
 43  
 
 44  16
     private final RunStatistics globalStats = new RunStatistics();
 45  
 
 46  
     private final StartupReportConfiguration reportConfiguration;
 47  
 
 48  
     private final StatisticsReporter statisticsReporter;
 49  
 
 50  16
     private final List<TestSetRunListener> listeners =
 51  
         Collections.synchronizedList( new ArrayList<TestSetRunListener>() );
 52  
 
 53  
     public DefaultReporterFactory( StartupReportConfiguration reportConfiguration )
 54  16
     {
 55  16
         this.reportConfiguration = reportConfiguration;
 56  16
         this.statisticsReporter = reportConfiguration.instantiateStatisticsReporter();
 57  16
         runStarting();
 58  16
     }
 59  
 
 60  
     public RunListener createReporter()
 61  
     {
 62  0
         return createTestSetRunListener();
 63  
     }
 64  
 
 65  
     public RunListener createTestSetRunListener()
 66  
     {
 67  0
         TestSetRunListener testSetRunListener =
 68  
             new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(),
 69  
                                     reportConfiguration.instantiateFileReporter(),
 70  
                                     reportConfiguration.instantiateStatelessXmlReporter(),
 71  
                                     reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter,
 72  
                                     globalStats, reportConfiguration.isTrimStackTrace(),
 73  
                                     ConsoleReporter.PLAIN.equals( reportConfiguration.getReportFormat() ),
 74  
                                     reportConfiguration.isBriefOrPlainFormat() );
 75  0
         listeners.add( testSetRunListener );
 76  0
         return testSetRunListener;
 77  
     }
 78  
 
 79  
     public RunResult close()
 80  
     {
 81  0
         runCompleted();
 82  0
         for ( TestSetRunListener listener : listeners )
 83  
         {
 84  0
             listener.close();
 85  
         }
 86  0
         return globalStats.getRunResult();
 87  
     }
 88  
 
 89  
     private DefaultDirectConsoleReporter createConsoleLogger()
 90  
     {
 91  16
         return new DefaultDirectConsoleReporter( reportConfiguration.getOriginalSystemOut() );
 92  
     }
 93  
 
 94  
     public void runStarting()
 95  
     {
 96  16
         final DefaultDirectConsoleReporter consoleReporter = createConsoleLogger();
 97  16
         consoleReporter.info( "" );
 98  16
         consoleReporter.info( "-------------------------------------------------------" );
 99  16
         consoleReporter.info( " T E S T S" );
 100  16
         consoleReporter.info( "-------------------------------------------------------" );
 101  16
     }
 102  
 
 103  
     private void runCompleted()
 104  
     {
 105  0
         final DefaultDirectConsoleReporter logger = createConsoleLogger();
 106  0
         if ( reportConfiguration.isPrintSummary() )
 107  
         {
 108  0
             logger.info( "" );
 109  0
             logger.info( "Results :" );
 110  0
             logger.info( "" );
 111  
         }
 112  0
         if ( globalStats.hadFailures() )
 113  
         {
 114  0
             logger.info( "Failed tests: " );
 115  0
             for ( Object o : this.globalStats.getFailureSources() )
 116  
             {
 117  0
                 logger.info( "  " + o );
 118  
             }
 119  0
             logger.info( "" );
 120  
         }
 121  0
         if ( globalStats.hadErrors() )
 122  
         {
 123  0
             logger.info( "Tests in error: " );
 124  0
             for ( Object o : this.globalStats.getErrorSources() )
 125  
             {
 126  0
                 logger.info( "  " + o );
 127  
             }
 128  0
             logger.info( "" );
 129  
         }
 130  0
         logger.info( globalStats.getSummary() );
 131  0
         logger.info( "" );
 132  0
     }
 133  
 
 134  
     public RunStatistics getGlobalRunStatistics()
 135  
     {
 136  0
         return globalStats;
 137  
     }
 138  
 
 139  
     public static DefaultReporterFactory defaultNoXml()
 140  
     {
 141  0
         return new DefaultReporterFactory( StartupReportConfiguration.defaultNoXml() );
 142  
     }
 143  
 }