Coverage Report - org.apache.maven.surefire.junitcore.LogicalStream
 
Classes in this File Line Coverage Branch Coverage Complexity
LogicalStream
0 %
0/18
0 %
0/10
0
LogicalStream$Entry
0 %
0/17
N/A
0
 
 1  
 package org.apache.maven.surefire.junitcore;
 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.List;
 24  
 import org.apache.maven.surefire.report.ConsoleOutputReceiver;
 25  
 import org.apache.maven.surefire.report.Reporter;
 26  
 import org.apache.maven.surefire.util.internal.ByteBuffer;
 27  
 
 28  
 /**
 29  
  * A stream-like object that preserves ordering between stdout/stderr
 30  
  */
 31  0
 public class LogicalStream
 32  
 {
 33  0
     private final List<Entry> output = new ArrayList<Entry>();
 34  
 
 35  0
     class Entry
 36  
     {
 37  
         final boolean stdout;
 38  
         final byte[] b;
 39  
         final int off;
 40  
         final int len;
 41  
 
 42  
         Entry( boolean stdout, byte[] b, int off, int len )
 43  0
         {
 44  0
             this.stdout = stdout;
 45  0
             this.b = ByteBuffer.copy( b, off, len);
 46  0
             this.off = 0;
 47  0
             this.len = len;
 48  0
         }
 49  
 
 50  
         public boolean isStdout()
 51  
         {
 52  0
             return stdout;
 53  
         }
 54  
 
 55  
         public void writeTo( StringBuilder stringBuilder )
 56  
         {
 57  0
             final String str = new String( b, off, len );
 58  0
             stringBuilder.append( str );
 59  0
         }
 60  
 
 61  
 
 62  
         public void writeDetails( Reporter reporter )
 63  
         {
 64  0
             final String str = new String( b, off, len );
 65  0
             reporter.writeDetailMessage( str );
 66  0
         }
 67  
 
 68  
         public void writeDetails( ConsoleOutputReceiver outputReceiver)
 69  
         {
 70  0
             outputReceiver.writeTestOutput( b, off, len , stdout );
 71  0
         }
 72  
 
 73  
         @Override
 74  
         public String toString()
 75  
         {
 76  0
             return new String( b, off, len );
 77  
         }
 78  
 
 79  
         public boolean isBlankLine()
 80  
         {
 81  0
             return "\n".equals( toString() );
 82  
         }
 83  
     }
 84  
 
 85  
     public synchronized void write( boolean stdout, byte b[], int off, int len )
 86  
     {
 87  0
         Entry entry = new Entry( stdout, b, off, len );
 88  0
         if ( !entry.isBlankLine() )
 89  
         {
 90  0
             output.add( entry );
 91  
         }
 92  0
     }
 93  
 
 94  
     public void writeDetails( Reporter reporter )
 95  
     {
 96  0
         for ( Entry entry : output )
 97  
         {
 98  0
             entry.writeDetails( reporter );
 99  
         }
 100  0
     }
 101  
 
 102  
     public void writeDetails( ConsoleOutputReceiver outputReceiver )
 103  
     {
 104  0
         for ( Entry entry : output )
 105  
         {
 106  0
             entry.writeDetails( outputReceiver );
 107  
         }
 108  0
     }
 109  
 
 110  
 
 111  
     public String getOutput( boolean stdOut )
 112  
     {
 113  0
         StringBuilder stringBuilder = new StringBuilder();
 114  0
         for ( Entry entry : output )
 115  
         {
 116  0
             if ( stdOut == entry.isStdout() )
 117  
             {
 118  0
                 entry.writeTo( stringBuilder );
 119  
             }
 120  
         }
 121  0
         return stringBuilder.toString();
 122  
     }
 123  
 }