Coverage Report - org.apache.maven.surefire.report.ReporterManager
 
Classes in this File Line Coverage Branch Coverage Complexity
ReporterManager
0%
0/64
0%
0/8
1.25
 
 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.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * A reporting front-end for providers.
 27  
  * <p/>
 28  
  * Synchronization/Threading note:
 29  
  * <p/>
 30  
  * This design is really only good for single-threaded test execution. Although it is currently
 31  
  * used by multi-threaded providers too, the design does not really make sense (and is probably buggy).
 32  
  * <p/>
 33  
  * This is because to get correct results, the client basically needs to do something like this:
 34  
  * synchronized( ReporterManger.getClass()){
 35  
  * reporterManager.runStarted()
 36  
  * reporterManager.testSetStarting()
 37  
  * reporterManager.testStarting()
 38  
  * reporterManager.testSucceeded()
 39  
  * reporterManager.testSetCompleted()
 40  
  * reporterManager.runCompleted()
 41  
  * }
 42  
  * <p/>
 43  
  * This is because the underlying providers are singletons and keep state, if you remove the outer synchronized
 44  
  * block, you may get mixups between results from different tests; although the end result (total test count etc)
 45  
  * should probably be correct.
 46  
  * <p/>
 47  
  * The solution to this problem involves making a clearer separation between test-result collection and reporting,
 48  
  * preferably removing singleton state approach out of the reporting interface.
 49  
  * <p/>
 50  
  * Please also note that the synchronization requirements of this interface severely limit the concurrency
 51  
  * potential of all the parallel surefire providers, especially when runnning non-io bound tests,
 52  
  */
 53  
 public class ReporterManager
 54  
 {
 55  
     private final RunStatistics runStatisticsForThis;
 56  
 
 57  
     private final MulticastingReporter multicastingReporter;
 58  
 
 59  0
     private final SystemStreamCapturer consoleCapturer = new SystemStreamCapturer();
 60  
 
 61  
     public ReporterManager( List reports, RunStatistics runStatisticsForThis )
 62  0
     {
 63  0
         multicastingReporter = new MulticastingReporter( reports );
 64  0
         this.runStatisticsForThis = runStatisticsForThis;
 65  0
     }
 66  
 
 67  
     public synchronized void writeMessage( String message )
 68  
     {
 69  0
         multicastingReporter.writeMessage( message );
 70  0
     }
 71  
     
 72  
     public synchronized void writeConsoleMessage( String message )
 73  
     {
 74  0
         multicastingReporter.writeConsoleMessage( message );
 75  0
     }
 76  
 
 77  
     // ----------------------------------------------------------------------
 78  
     // Run
 79  
     // ----------------------------------------------------------------------
 80  
 
 81  
     public synchronized void runStarting()
 82  
     {
 83  0
         multicastingReporter.runStarting();
 84  0
     }
 85  
 
 86  
     public synchronized void runCompleted()
 87  
     {
 88  0
         multicastingReporter.runCompleted();
 89  0
         multicastingReporter.writeFooter( "" );
 90  0
         multicastingReporter.writeFooter( "Results :" );
 91  0
         multicastingReporter.writeFooter( "" );
 92  0
         if ( runStatisticsForThis.hadFailures() )
 93  
         {
 94  0
             multicastingReporter.writeFooter( "Failed tests: " );
 95  0
             for ( Iterator iterator = this.runStatisticsForThis.getFailureSources().iterator(); iterator.hasNext(); )
 96  
             {
 97  0
                 multicastingReporter.writeFooter( "  " + iterator.next() );
 98  
             }
 99  0
             multicastingReporter.writeFooter( "" );
 100  
         }
 101  0
         if ( runStatisticsForThis.hadErrors() )
 102  
         {
 103  0
             writeFooter( "Tests in error: " );
 104  0
             for ( Iterator iterator = this.runStatisticsForThis.getErrorSources().iterator(); iterator.hasNext(); )
 105  
             {
 106  0
                 multicastingReporter.writeFooter( "  " + iterator.next() );
 107  
             }
 108  0
             multicastingReporter.writeFooter( "" );
 109  
         }
 110  0
         multicastingReporter.writeFooter( runStatisticsForThis.getSummary() );
 111  0
         multicastingReporter.writeFooter( "" );
 112  0
         consoleCapturer.restoreStreams();
 113  0
     }
 114  
 
 115  
     public synchronized void writeFooter( String footer )
 116  
     {
 117  0
         multicastingReporter.writeFooter( footer );
 118  0
     }
 119  
 
 120  
 
 121  
     public synchronized void testSetStarting( ReportEntry report )
 122  
         throws ReporterException
 123  
     {
 124  0
         multicastingReporter.testSetStarting( report );
 125  0
     }
 126  
 
 127  
     public synchronized void testSetCompleted( ReportEntry report )
 128  
     {
 129  0
         multicastingReporter.testSetCompleted( report );
 130  0
     }
 131  
 
 132  
     // ----------------------------------------------------------------------
 133  
     // Test
 134  
     // ----------------------------------------------------------------------
 135  
 
 136  
     public synchronized void testStarting( ReportEntry report )
 137  
     {
 138  0
         multicastingReporter.testStarting( report );
 139  0
     }
 140  
 
 141  
     public synchronized void testSucceeded( ReportEntry report )
 142  
     {
 143  0
         consoleCapturer.clearCapturedContent();
 144  0
         runStatisticsForThis.incrementCompletedCount();
 145  0
         multicastingReporter.testSucceeded( report );
 146  0
     }
 147  
 
 148  
     public synchronized void testError( ReportEntry reportEntry )
 149  
     {
 150  0
         testError( reportEntry, consoleCapturer.getStdOutLog(), consoleCapturer.getStdErrLog() );
 151  0
     }
 152  
 
 153  
     public synchronized void testError( ReportEntry reportEntry, String stdOutLog, String stdErrLog )
 154  
     {
 155  0
         multicastingReporter.testError( reportEntry, stdOutLog, stdErrLog );
 156  0
         runStatisticsForThis.incrementErrorsCount();
 157  0
         runStatisticsForThis.incrementCompletedCount();
 158  0
         runStatisticsForThis.addErrorSource( reportEntry.getName() );
 159  0
         consoleCapturer.clearCapturedContent();
 160  0
     }
 161  
 
 162  
     public synchronized void testFailed( ReportEntry reportEntry )
 163  
     {
 164  0
         testFailed( reportEntry, consoleCapturer.getStdOutLog(), consoleCapturer.getStdErrLog() );
 165  0
     }
 166  
 
 167  
 
 168  
     public synchronized void testFailed( ReportEntry reportEntry, String stdOutLog, String stdErrLog )
 169  
     {
 170  0
         multicastingReporter.testFailed( reportEntry, stdOutLog, stdErrLog );
 171  0
         runStatisticsForThis.incrementFailureCount();
 172  0
         runStatisticsForThis.incrementCompletedCount();
 173  0
         runStatisticsForThis.addFailureSource( reportEntry.getName() );
 174  0
         consoleCapturer.clearCapturedContent();
 175  0
     }
 176  
 
 177  
     // ----------------------------------------------------------------------
 178  
     // Counters
 179  
     // ----------------------------------------------------------------------
 180  
 
 181  
     public synchronized void testSkipped( ReportEntry report )
 182  
     {
 183  0
         consoleCapturer.clearCapturedContent();
 184  0
         runStatisticsForThis.incrementSkippedCount();
 185  0
         runStatisticsForThis.incrementCompletedCount();
 186  0
         multicastingReporter.testSkipped( report );
 187  0
     }
 188  
 
 189  
     public synchronized void reset()
 190  
     {
 191  0
         multicastingReporter.reset();
 192  0
     }
 193  
 
 194  
 }