Coverage Report - org.apache.maven.surefire.report.AbstractReporter
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractReporter
0 %
0/54
0 %
0/10
1,16
 
 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 1081527 2011-03-14 19:31:34Z 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  
     private final ReporterConfiguration reporterConfiguration;
 56  
 
 57  
     // ----------------------------------------------------------------------
 58  
     // Report interface
 59  
     // ----------------------------------------------------------------------
 60  
 
 61  
 
 62  
     AbstractReporter( ReporterConfiguration reporterConfiguration )
 63  0
     {
 64  0
         this.reporterConfiguration = reporterConfiguration;
 65  0
         this.trimStackTrace = reporterConfiguration.isTrimStackTrace().booleanValue();
 66  0
     }
 67  
 
 68  
     boolean isTimedOut()
 69  
     {
 70  0
         return reporterConfiguration.isTimedOut();
 71  
     }
 72  
 
 73  
     public void writeFooter( String footer )
 74  
     {
 75  0
         writeMessage( footer );
 76  0
     }
 77  
 
 78  
     public void runStarting()
 79  
     {
 80  0
     }
 81  
 
 82  
     public void runCompleted()
 83  
     {
 84  0
     }
 85  
 
 86  
     public void testSetStarting( ReportEntry report )
 87  
         throws ReporterException
 88  
     {
 89  0
         testSetStartTime = System.currentTimeMillis();
 90  0
     }
 91  
 
 92  
     public void testSetCompleted( ReportEntry report )
 93  
         throws ReporterException
 94  
     {
 95  0
     }
 96  
 
 97  
     // ----------------------------------------------------------------------
 98  
     // Test
 99  
     // ----------------------------------------------------------------------
 100  
 
 101  
     public void testStarting( ReportEntry report )
 102  
     {
 103  0
         startTime = System.currentTimeMillis();
 104  0
     }
 105  
 
 106  
     public void testSucceeded( ReportEntry report )
 107  
     {
 108  0
         endTest();
 109  0
     }
 110  
 
 111  
     public void testSkipped( ReportEntry report )
 112  
     {
 113  0
         ++skipped;
 114  
 
 115  0
         endTest();
 116  0
     }
 117  
 
 118  
     public void testError( ReportEntry report, String stdOut, String stdErr )
 119  
     {
 120  0
         ++errors;
 121  0
         endTest();
 122  0
     }
 123  
 
 124  
     public void testFailed( ReportEntry report, String stdOut, String stdErr )
 125  
     {
 126  0
         ++failures;
 127  0
         endTest();
 128  0
     }
 129  
 
 130  
     private void endTest()
 131  
     {
 132  0
         ++completedCount;
 133  
 
 134  0
         endTime = System.currentTimeMillis();
 135  
         // SUREFIRE-398 skipped tests call endTest without calling testStarting
 136  
         // if startTime = 0, set it to endTime, so the diff will be 0
 137  0
         if ( startTime == 0 )
 138  
         {
 139  0
             startTime = endTime;
 140  
         }
 141  0
     }
 142  
 
 143  
     // ----------------------------------------------------------------------
 144  
     // Counters
 145  
     // ----------------------------------------------------------------------
 146  
 
 147  
     int getNumErrors()
 148  
     {
 149  0
         return errors;
 150  
     }
 151  
 
 152  
     int getNumSkipped()
 153  
     {
 154  0
         return skipped;
 155  
     }
 156  
 
 157  
     int getNumFailures()
 158  
     {
 159  0
         return failures;
 160  
     }
 161  
 
 162  
     int getNumTests()
 163  
     {
 164  0
         return completedCount;
 165  
     }
 166  
 
 167  
     // ----------------------------------------------------------------------
 168  
     //
 169  
     // ----------------------------------------------------------------------
 170  
 
 171  
     public void reset()
 172  
     {
 173  0
         errors = 0;
 174  
 
 175  0
         skipped = 0;
 176  
 
 177  0
         failures = 0;
 178  
 
 179  0
         completedCount = 0;
 180  
 
 181  0
     }
 182  
 
 183  
     // ----------------------------------------------------------------------
 184  
     //
 185  
     // ----------------------------------------------------------------------
 186  
 
 187  
     String elapsedTimeAsString( long runTime )
 188  
     {
 189  0
         return numberFormat.format( (double) runTime / MS_PER_SEC );
 190  
     }
 191  
 
 192  
     /**
 193  
      * Returns stacktrace as String.
 194  
      *
 195  
      * @param report ReportEntry object.
 196  
      * @return stacktrace as string.
 197  
      */
 198  
     String getStackTrace( ReportEntry report )
 199  
     {
 200  0
         StackTraceWriter writer = report.getStackTraceWriter();
 201  0
         if ( writer == null )
 202  
         {
 203  0
             return null;
 204  
         }
 205  0
         return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
 206  
     }
 207  
 
 208  
     long getActualRunTime( ReportEntry reportEntry )
 209  
     {
 210  0
         final Integer clientSpecifiedElapsed = reportEntry.getElapsed();
 211  0
         return clientSpecifiedElapsed != null ? clientSpecifiedElapsed.intValue() : endTime - startTime;
 212  
     }
 213  
 
 214  
     // @deprecated dont use.  TODO remove for 2.7.2
 215  
     public void testError( ReportEntry report )
 216  
     {
 217  0
     }
 218  
 
 219  
     // @deprecated dont use.  TODO remove for 2.7.2
 220  
     public void testFailed( ReportEntry report )
 221  
     {
 222  0
     }
 223  
 
 224  
     // @deprecated dont use.  TODO remove for 2.7.2
 225  
     public void testAssumptionFailure( ReportEntry report )
 226  
     {
 227  0
     }
 228  
 
 229  
     void deleteIfExisting( File reportFile )
 230  
     {
 231  0
         if ( reportFile.exists() )
 232  
         {
 233  
             //noinspection ResultOfMethodCallIgnored
 234  0
             reportFile.delete();
 235  
         }
 236  0
     }
 237  
 }