Coverage Report - org.apache.maven.surefire.booter.output.PrintWriterOutputConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
PrintWriterOutputConsumer
100%
21/21
N/A
1
 
 1  
 package org.apache.maven.surefire.booter.output;
 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 org.apache.maven.surefire.report.ReportEntry;
 23  
 
 24  
 import java.io.PrintWriter;
 25  
 import java.io.Writer;
 26  
 
 27  
 /**
 28  
  * Surefire output consumer that writes everything to a {@link Writer}
 29  
  *
 30  
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
 31  
  * @version $Id: PrintWriterOutputConsumer.java 510866 2007-02-23 08:13:49Z brett $
 32  
  * @since 2.1
 33  
  */
 34  
 public class PrintWriterOutputConsumer
 35  
     implements OutputConsumer
 36  
 {
 37  
 
 38  
     private PrintWriter printWriter;
 39  
 
 40  
     /**
 41  
      * Create a consumer uninitialized, {@link #setPrintWriter(PrintWriter)} must be called before using it
 42  
      */
 43  
     public PrintWriterOutputConsumer()
 44  24
     {
 45  24
     }
 46  
 
 47  
     /**
 48  
      * Create a consumer that will write to the specified {@link Writer}
 49  
      *
 50  
      * @param writer where to write to
 51  
      */
 52  
     public PrintWriterOutputConsumer( Writer writer )
 53  24
     {
 54  24
         this.setPrintWriter( new PrintWriter( writer ) );
 55  24
     }
 56  
 
 57  
     /**
 58  
      * Set the {@link PrintWriter} used by this object
 59  
      *
 60  
      * @param writer
 61  
      */
 62  
     public void setPrintWriter( PrintWriter writer )
 63  
     {
 64  48
         this.printWriter = writer;
 65  48
     }
 66  
 
 67  
     /**
 68  
      * Get the {@link PrintWriter} used by this object
 69  
      */
 70  
     public PrintWriter getPrintWriter()
 71  
     {
 72  64
         return printWriter;
 73  
     }
 74  
 
 75  
     public void consumeHeaderLine( String line )
 76  
     {
 77  8
         write( line );
 78  8
     }
 79  
 
 80  
     public void consumeMessageLine( String line )
 81  
     {
 82  8
         write( line );
 83  8
     }
 84  
 
 85  
     public void consumeFooterLine( String line )
 86  
     {
 87  8
         write( line );
 88  8
     }
 89  
 
 90  
     public void consumeOutputLine( String line )
 91  
     {
 92  8
         write( line );
 93  8
     }
 94  
 
 95  
     /**
 96  
      * Do nothing
 97  
      */
 98  
     public void testSetStarting( ReportEntry reportEntry )
 99  
     {
 100  
         // do nothing
 101  48
     }
 102  
 
 103  
     /**
 104  
      * Do nothing
 105  
      */
 106  
     public void testSetCompleted()
 107  
     {
 108  
         // do nothing
 109  40
     }
 110  
 
 111  
     /**
 112  
      * Write a line and flush
 113  
      *
 114  
      * @param line
 115  
      */
 116  
     private void write( String line )
 117  
     {
 118  32
         getPrintWriter().println( line );
 119  32
         getPrintWriter().flush();
 120  32
     }
 121  
 
 122  
 }