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