Coverage Report - org.apache.maven.surefire.junitcore.LogicalStream
 
Classes in this File Line Coverage Branch Coverage Complexity
LogicalStream
100%
11/11
75%
3/4
1,333
LogicalStream$Entry
100%
10/10
N/A
1,333
 
 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.util.internal.ByteBuffer;
 26  
 
 27  
 /**
 28  
  * A stream-like object that preserves ordering between stdout/stderr
 29  
  */
 30  1
 public class LogicalStream
 31  
 {
 32  1
     private final List<Entry> output = new ArrayList<Entry>();
 33  
 
 34  1
     class Entry
 35  
     {
 36  
         final boolean stdout;
 37  
 
 38  
         final byte[] b;
 39  
 
 40  
         final int off;
 41  
 
 42  
         final int len;
 43  
 
 44  
         Entry( boolean stdout, byte[] b, int off, int len )
 45  1002
         {
 46  1002
             this.stdout = stdout;
 47  1002
             this.b = ByteBuffer.copy( b, off, len );
 48  1002
             this.off = 0;
 49  1002
             this.len = len;
 50  1002
         }
 51  
 
 52  
 
 53  
         public void writeDetails( ConsoleOutputReceiver outputReceiver )
 54  
         {
 55  103
             outputReceiver.writeTestOutput( b, off, len, stdout );
 56  103
         }
 57  
 
 58  
         @Override
 59  
         public String toString()
 60  
         {
 61  1002
             return new String( b, off, len );
 62  
         }
 63  
 
 64  
         public boolean isBlankLine()
 65  
         {
 66  1002
             return "\n".equals( toString() );
 67  
         }
 68  
     }
 69  
 
 70  
     public synchronized void write( boolean stdout, byte b[], int off, int len )
 71  
     {
 72  1002
         Entry entry = new Entry( stdout, b, off, len );
 73  1002
         if ( !entry.isBlankLine() )
 74  
         {
 75  1002
             output.add( entry );
 76  
         }
 77  1002
     }
 78  
 
 79  
     public synchronized void writeDetails( ConsoleOutputReceiver outputReceiver )
 80  
     {
 81  1
         for ( Entry entry : output )
 82  
         {
 83  103
             entry.writeDetails( outputReceiver );
 84  103
         }
 85  1
     }
 86  
 
 87  
 
 88  
 }