Coverage Report - org.apache.maven.surefire.report.RunStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
RunStatistics
0%
0/10
N/A
1.4
RunStatistics$1
N/A
N/A
1.4
RunStatistics$Sources
0%
0/17
0%
0/8
1.4
 
 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.util.ArrayList;
 23  
 import java.util.Collection;
 24  
 import java.util.Collections;
 25  
 import org.apache.maven.surefire.util.internal.StringUtils;
 26  
 
 27  
 /**
 28  
  * @author Kristian Rosenvold
 29  
  */
 30  0
 public class RunStatistics
 31  
     extends TestSetStatistics
 32  
 {
 33  
     /**
 34  
      * Holds the source(s) that causes the error(s).
 35  
      */
 36  0
     private final Sources errorSources = new Sources();
 37  
 
 38  
     /**
 39  
      * Holds the source(s) that causes the failure(s).
 40  
      */
 41  0
     private final Sources failureSources = new Sources();
 42  
 
 43  
 
 44  
     public void addErrorSource( String errorSource, StackTraceWriter stackTraceWriter )
 45  
     {
 46  0
         errorSources.addSource( errorSource, stackTraceWriter );
 47  0
     }
 48  
 
 49  
     public void addFailureSource( String failureSource, StackTraceWriter stackTraceWriter )
 50  
     {
 51  0
         failureSources.addSource( failureSource, stackTraceWriter );
 52  0
     }
 53  
 
 54  
     public Collection getErrorSources()
 55  
     {
 56  0
         return errorSources.getListOfSources();
 57  
     }
 58  
 
 59  
     public Collection getFailureSources()
 60  
     {
 61  0
         return failureSources.getListOfSources();
 62  
     }
 63  
 
 64  
 
 65  0
     private static class Sources
 66  
     {
 67  0
         private final Collection listOfSources = new ArrayList();
 68  
 
 69  
         void addSource( String source )
 70  
         {
 71  0
             synchronized ( listOfSources )
 72  
             {
 73  0
                 listOfSources.add( source );
 74  0
             }
 75  0
         }
 76  
 
 77  
         void addSource( String source, StackTraceWriter stackTraceWriter )
 78  
         {
 79  0
             String message = getMessageOfThrowable( stackTraceWriter );
 80  0
             String extendedSource =
 81  
                 StringUtils.isBlank( message ) ? source : source + ": " + trimToSingleLine( message );
 82  0
             addSource( extendedSource );
 83  0
         }
 84  
 
 85  
         private String trimToSingleLine( String str )
 86  
         {
 87  0
             int i = str.indexOf( "\n" );
 88  0
             return i >= 0 ? str.substring( 0, i ) + "(..)" : str;
 89  
         }
 90  
 
 91  
         Collection getListOfSources()
 92  
         {
 93  0
             synchronized ( listOfSources )
 94  
             {
 95  0
                 return Collections.unmodifiableCollection( listOfSources );
 96  0
             }
 97  
         }
 98  
 
 99  
         private String getMessageOfThrowable( StackTraceWriter stackTraceWriter )
 100  
         {
 101  
             //noinspection ThrowableResultOfMethodCallIgnored
 102  0
             return stackTraceWriter != null ? getMessageOfThrowable( stackTraceWriter.getThrowable() ) : "";
 103  
         }
 104  
 
 105  
         private String getMessageOfThrowable( Throwable throwable )
 106  
         {
 107  0
             return throwable != null ? throwable.getLocalizedMessage() : "";
 108  
         }
 109  
     }
 110  
 }