Coverage Report - org.apache.maven.plugin.surefire.report.WrappedReportEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
WrappedReportEntry
76%
33/43
27%
5/18
1,333
 
 1  
 package org.apache.maven.plugin.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.text.NumberFormat;
 23  
 import java.util.Locale;
 24  
 
 25  
 import org.apache.maven.surefire.report.ReportEntry;
 26  
 import org.apache.maven.surefire.report.StackTraceWriter;
 27  
 
 28  
 /**
 29  
  * @author Kristian Rosenvold
 30  
  */
 31  
 public class WrappedReportEntry
 32  
     implements ReportEntry
 33  
 {
 34  
     private final ReportEntry original;
 35  
 
 36  
     private final ReportEntryType reportEntryType;
 37  
 
 38  
     private final Integer elapsed;
 39  
 
 40  
     private final Utf8RecodingDeferredFileOutputStream stdout;
 41  
 
 42  
     private final Utf8RecodingDeferredFileOutputStream stdErr;
 43  
 
 44  9
     private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH );
 45  
 
 46  
     private static final int MS_PER_SEC = 1000;
 47  
 
 48  1
     static final String NL = System.getProperty( "line.separator" );
 49  
 
 50  
     public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
 51  
                                Utf8RecodingDeferredFileOutputStream stdout, Utf8RecodingDeferredFileOutputStream stdErr )
 52  9
     {
 53  9
         this.original = original;
 54  9
         this.reportEntryType = reportEntryType;
 55  9
         this.elapsed = estimatedElapsed;
 56  9
         this.stdout = stdout;
 57  9
         this.stdErr = stdErr;
 58  9
     }
 59  
 
 60  
     public Integer getElapsed()
 61  
     {
 62  12
         return elapsed;
 63  
     }
 64  
 
 65  
     public ReportEntryType getReportEntryType()
 66  
     {
 67  4
         return reportEntryType;
 68  
     }
 69  
 
 70  
     public Utf8RecodingDeferredFileOutputStream getStdout()
 71  
     {
 72  1
         return stdout;
 73  
     }
 74  
 
 75  
     public Utf8RecodingDeferredFileOutputStream getStdErr()
 76  
     {
 77  1
         return stdErr;
 78  
     }
 79  
 
 80  
     public String getSourceName()
 81  
     {
 82  6
         return original.getSourceName();
 83  
     }
 84  
 
 85  
     public String getName()
 86  
     {
 87  23
         return original.getName();
 88  
     }
 89  
 
 90  
     public String getGroup()
 91  
     {
 92  5
         return original.getGroup();
 93  
     }
 94  
 
 95  
     public StackTraceWriter getStackTraceWriter()
 96  
     {
 97  2
         return original.getStackTraceWriter();
 98  
     }
 99  
 
 100  
     public String getMessage()
 101  
     {
 102  3
         return original.getMessage();
 103  
     }
 104  
 
 105  
     public String getStackTrace( boolean trimStackTrace )
 106  
     {
 107  1
         StackTraceWriter writer = original.getStackTraceWriter();
 108  1
         if ( writer == null )
 109  
         {
 110  0
             return null;
 111  
         }
 112  1
         return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
 113  
     }
 114  
 
 115  
     public String elapsedTimeAsString()
 116  
     {
 117  6
         return elapsedTimeAsString( getElapsed() );
 118  
     }
 119  
 
 120  
     String elapsedTimeAsString( long runTime )
 121  
     {
 122  6
         return numberFormat.format( (double) runTime / MS_PER_SEC );
 123  
     }
 124  
 
 125  
     public String getReportName()
 126  
     {
 127  8
         final int i = getName().lastIndexOf( "(" );
 128  8
         return i > 0 ? getName().substring( 0, i ) : getName();
 129  
     }
 130  
 
 131  
     public String getReportName( String suffix )
 132  
     {
 133  2
         return suffix != null && suffix.length() > 0 ? getReportName() + "(" + suffix + ")" : getReportName();
 134  
     }
 135  
 
 136  
     public String getOutput( boolean trimStackTrace )
 137  
     {
 138  0
         StringBuilder buf = new StringBuilder();
 139  
 
 140  0
         buf.append( getElapsedTimeSummary() );
 141  
 
 142  0
         buf.append( "  <<< " ).append( getReportEntryType().toString().toUpperCase() ).append( "!" ).append( NL );
 143  
 
 144  0
         buf.append( getStackTrace( trimStackTrace ) );
 145  
 
 146  0
         return buf.toString();
 147  
     }
 148  
 
 149  
     public String getElapsedTimeSummary()
 150  
     {
 151  1
         StringBuilder reportContent = new StringBuilder();
 152  1
         reportContent.append( getName() );
 153  1
         reportContent.append( "  Time elapsed: " );
 154  1
         reportContent.append( elapsedTimeAsString() );
 155  1
         reportContent.append( " sec" );
 156  
 
 157  1
         return reportContent.toString();
 158  
     }
 159  
 
 160  
     public boolean isErrorOrFailure()
 161  
     {
 162  0
         ReportEntryType thisType = getReportEntryType();
 163  0
         return ReportEntryType.failure == thisType || ReportEntryType.error == thisType;
 164  
     }
 165  
 
 166  
     public boolean isSkipped()
 167  
     {
 168  0
         return ReportEntryType.skipped == getReportEntryType();
 169  
     }
 170  
 
 171  
     public boolean isSucceeded()
 172  
     {
 173  0
         return ReportEntryType.success == getReportEntryType();
 174  
     }
 175  
 
 176  
     public String getNameWithGroup()
 177  
     {
 178  2
         return original.getNameWithGroup();
 179  
     }
 180  
 }