Coverage Report - org.apache.maven.surefire.report.AbstractReporter
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractReporter
0%
0/46
0%
0/10
1.316
 
 1  
 package org.apache.maven.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.io.File;
 23  
 import java.text.NumberFormat;
 24  
 import java.util.Locale;
 25  
 
 26  
 /**
 27  
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
 28  
  * @version $Id: AbstractReporter.java 1098345 2011-05-01 14:56:14Z krosenvold $
 29  
  */
 30  
 public abstract class AbstractReporter
 31  
     implements Reporter
 32  
 {
 33  
     int completedCount;
 34  
 
 35  
     int errors;
 36  
 
 37  
     int failures;
 38  
 
 39  
     private long startTime;
 40  
 
 41  
     private long endTime;
 42  
 
 43  0
     private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH );
 44  
 
 45  0
     static final String NL = System.getProperty( "line.separator" );
 46  
 
 47  
     private static final int MS_PER_SEC = 1000;
 48  
 
 49  
     long testSetStartTime;
 50  
 
 51  
     int skipped;
 52  
 
 53  
     private final boolean trimStackTrace;
 54  
 
 55  
     // ----------------------------------------------------------------------
 56  
     // Report interface
 57  
     // ----------------------------------------------------------------------
 58  
 
 59  
 
 60  
     protected AbstractReporter( boolean trimStackTrace )
 61  0
     {
 62  0
         this.trimStackTrace = trimStackTrace;
 63  0
     }
 64  
 
 65  
 
 66  
     public void writeMessage( byte[] b, int off, int len )
 67  
     {
 68  
         // Keep quiet about console output
 69  
         // Reporting is itching for a cleanup
 70  0
     }
 71  
 
 72  
 
 73  
     public void testSetStarting( ReportEntry report )
 74  
         throws ReporterException
 75  
     {
 76  0
         testSetStartTime = System.currentTimeMillis();
 77  0
     }
 78  
 
 79  
     public void testSetCompleted( ReportEntry report )
 80  
         throws ReporterException
 81  
     {
 82  0
     }
 83  
 
 84  
     // ----------------------------------------------------------------------
 85  
     // Test
 86  
     // ----------------------------------------------------------------------
 87  
 
 88  
     public void testStarting( ReportEntry report )
 89  
     {
 90  0
         startTime = System.currentTimeMillis();
 91  0
     }
 92  
 
 93  
     public void testSucceeded( ReportEntry report )
 94  
     {
 95  0
         endTest();
 96  0
     }
 97  
 
 98  
     public void testSkipped( ReportEntry report )
 99  
     {
 100  0
         ++skipped;
 101  
 
 102  0
         endTest();
 103  0
     }
 104  
 
 105  
     public void testError( ReportEntry report, String stdOut, String stdErr )
 106  
     {
 107  0
         ++errors;
 108  0
         endTest();
 109  0
     }
 110  
 
 111  
     public void testFailed( ReportEntry report, String stdOut, String stdErr )
 112  
     {
 113  0
         ++failures;
 114  0
         endTest();
 115  0
     }
 116  
 
 117  
     private void endTest()
 118  
     {
 119  0
         ++completedCount;
 120  
 
 121  0
         endTime = System.currentTimeMillis();
 122  
         // SUREFIRE-398 skipped tests call endTest without calling testStarting
 123  
         // if startTime = 0, set it to endTime, so the diff will be 0
 124  0
         if ( startTime == 0 )
 125  
         {
 126  0
             startTime = endTime;
 127  
         }
 128  0
     }
 129  
 
 130  
     // ----------------------------------------------------------------------
 131  
     // Counters
 132  
     // ----------------------------------------------------------------------
 133  
 
 134  
     int getNumErrors()
 135  
     {
 136  0
         return errors;
 137  
     }
 138  
 
 139  
     int getNumSkipped()
 140  
     {
 141  0
         return skipped;
 142  
     }
 143  
 
 144  
     int getNumFailures()
 145  
     {
 146  0
         return failures;
 147  
     }
 148  
 
 149  
     int getNumTests()
 150  
     {
 151  0
         return completedCount;
 152  
     }
 153  
 
 154  
     // ----------------------------------------------------------------------
 155  
     //
 156  
     // ----------------------------------------------------------------------
 157  
 
 158  
     public void reset()
 159  
     {
 160  0
         errors = 0;
 161  
 
 162  0
         skipped = 0;
 163  
 
 164  0
         failures = 0;
 165  
 
 166  0
         completedCount = 0;
 167  
 
 168  0
     }
 169  
 
 170  
     // ----------------------------------------------------------------------
 171  
     //
 172  
     // ----------------------------------------------------------------------
 173  
 
 174  
     String elapsedTimeAsString( long runTime )
 175  
     {
 176  0
         return numberFormat.format( (double) runTime / MS_PER_SEC );
 177  
     }
 178  
 
 179  
     /**
 180  
      * Returns stacktrace as String.
 181  
      *
 182  
      * @param report ReportEntry object.
 183  
      * @return stacktrace as string.
 184  
      */
 185  
     String getStackTrace( ReportEntry report )
 186  
     {
 187  0
         StackTraceWriter writer = report.getStackTraceWriter();
 188  0
         if ( writer == null )
 189  
         {
 190  0
             return null;
 191  
         }
 192  0
         return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
 193  
     }
 194  
 
 195  
     long getActualRunTime( ReportEntry reportEntry )
 196  
     {
 197  0
         final Integer clientSpecifiedElapsed = reportEntry.getElapsed();
 198  0
         return clientSpecifiedElapsed != null ? clientSpecifiedElapsed.intValue() : endTime - startTime;
 199  
     }
 200  
 
 201  
     void deleteIfExisting( File reportFile )
 202  
     {
 203  0
         if ( reportFile.exists() )
 204  
         {
 205  
             //noinspection ResultOfMethodCallIgnored
 206  0
             reportFile.delete();
 207  
         }
 208  0
     }
 209  
 }