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