Coverage Report - org.apache.maven.surefire.report.ConsoleOutputFileReporter
 
Classes in this File Line Coverage Branch Coverage Complexity
ConsoleOutputFileReporter
0%
0/30
0%
0/6
1.417
 
 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.io.BufferedWriter;
 23  
 import java.io.File;
 24  
 import java.io.FileWriter;
 25  
 import java.io.IOException;
 26  
 import java.io.PrintWriter;
 27  
 
 28  
 import org.apache.maven.surefire.util.NestedRuntimeException;
 29  
 
 30  
 /**
 31  
  * Surefire output consumer proxy that writes test output to a {@link java.io.File} for each test suite.
 32  
  * <p/>
 33  
  * This class is not threadsafe, but can be encapsulated with a SynchronizedOutputConsumer. It may still be
 34  
  * accessed from different threads (serially).
 35  
  *
 36  
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
 37  
  * @version $Id: ConsoleOutputFileReporter.java 1204688 2011-11-21 20:25:19Z krosenvold $
 38  
  * @since 2.1
 39  
  */
 40  
 public class ConsoleOutputFileReporter
 41  
     implements Reporter
 42  
 {
 43  
     private final File reportsDirectory;
 44  
 
 45  0
     private PrintWriter printWriter = null;
 46  
 
 47  
     private String reportEntryName;
 48  
 
 49  
     private final String reportNameSuffix;
 50  
 
 51  
     public ConsoleOutputFileReporter( File reportsDirectory )
 52  
     {
 53  0
         this( reportsDirectory, null );
 54  0
     }
 55  
 
 56  
     public ConsoleOutputFileReporter( File reportsDirectory, String reportNameSuffix )
 57  0
     {
 58  0
         this.reportsDirectory = reportsDirectory;
 59  0
         this.reportNameSuffix = reportNameSuffix;
 60  0
     }
 61  
 
 62  
     public void testSetStarting( ReportEntry reportEntry )
 63  
     {
 64  0
         this.reportEntryName = reportEntry.getName();
 65  0
     }
 66  
 
 67  
     public void testSetCompleted( ReportEntry report )
 68  
         throws ReporterException
 69  
     {
 70  0
         if ( printWriter != null )
 71  
         {
 72  0
             printWriter.close();
 73  0
             printWriter = null;
 74  
         }
 75  0
     }
 76  
 
 77  
     public void writeMessage( byte[] b, int off, int len )
 78  
     {
 79  
         try
 80  
         {
 81  0
             if ( printWriter == null )
 82  
             {
 83  0
                 if ( !reportsDirectory.exists() )
 84  
                 {
 85  
                     //noinspection ResultOfMethodCallIgnored
 86  0
                     reportsDirectory.mkdirs();
 87  
                 }
 88  0
                 File file = AbstractFileReporter.getReportFile( reportsDirectory, reportEntryName, reportNameSuffix, "-output.txt" );
 89  0
                 printWriter = new PrintWriter( new BufferedWriter( new FileWriter( file ) ) );
 90  
             }
 91  0
             printWriter.write( new String( b, off, len ) );
 92  
         }
 93  0
         catch ( IOException e )
 94  
         {
 95  0
             throw new NestedRuntimeException( e );
 96  0
         }
 97  0
     }
 98  
 
 99  
 
 100  
     public void testStarting( ReportEntry report )
 101  
     {
 102  0
     }
 103  
 
 104  
     public void testSucceeded( ReportEntry report )
 105  
     {
 106  0
     }
 107  
 
 108  
     public void testSkipped( ReportEntry report )
 109  
     {
 110  0
     }
 111  
 
 112  
     public void testError( ReportEntry report, String stdOut, String stdErr )
 113  
     {
 114  0
     }
 115  
 
 116  
     public void testFailed( ReportEntry report, String stdOut, String stdErr )
 117  
     {
 118  0
     }
 119  
 
 120  
     public void writeMessage( String message )
 121  
     {
 122  0
     }
 123  
 
 124  
     public void reset()
 125  
     {
 126  0
     }
 127  
 }