Coverage Report - org.apache.maven.surefire.report.RunStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
RunStatistics
48%
12/25
25%
2/8
1,286
RunStatistics$1
N/A
N/A
1,286
RunStatistics$Sources
90%
10/11
N/A
1,286
 
 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.plugin.surefire.report.TestSetStats;
 26  
 import org.apache.maven.surefire.suite.RunResult;
 27  
 
 28  
 /**
 29  
  * @author Kristian Rosenvold
 30  
  */
 31  22
 public class RunStatistics
 32  
 {
 33  
     /**
 34  
      * Holds the source(s) that causes the error(s).
 35  
      */
 36  22
     private final Sources errorSources = new Sources();
 37  
 
 38  
     /**
 39  
      * Holds the source(s) that causes the failure(s).
 40  
      */
 41  22
     private final Sources failureSources = new Sources();
 42  
 
 43  
     private int completedCount;
 44  
 
 45  
     private int errors;
 46  
 
 47  
     private int failures;
 48  
 
 49  
     private int skipped;
 50  
 
 51  
 
 52  
     public void addErrorSource( StackTraceWriter stackTraceWriter )
 53  
     {
 54  3
         if ( stackTraceWriter == null )
 55  
         {
 56  0
             throw new IllegalArgumentException( "Cant be null" );
 57  
         }
 58  3
         errorSources.addSource( stackTraceWriter );
 59  3
     }
 60  
 
 61  
     public void addFailureSource( StackTraceWriter stackTraceWriter )
 62  
     {
 63  3
         if ( stackTraceWriter == null )
 64  
         {
 65  0
             throw new IllegalArgumentException( "Cant be null" );
 66  
         }
 67  3
         failureSources.addSource( stackTraceWriter );
 68  3
     }
 69  
 
 70  
     public Collection<String> getErrorSources()
 71  
     {
 72  3
         return errorSources.getListOfSources();
 73  
     }
 74  
 
 75  
     public Collection<String> getFailureSources()
 76  
     {
 77  3
         return failureSources.getListOfSources();
 78  
     }
 79  
 
 80  
     public synchronized boolean hadFailures()
 81  
     {
 82  0
         return failures > 0;
 83  
     }
 84  
 
 85  
     public synchronized boolean hadErrors()
 86  
     {
 87  0
         return errors > 0;
 88  
     }
 89  
 
 90  
     public synchronized int getCompletedCount()
 91  
     {
 92  0
         return completedCount;
 93  
     }
 94  
 
 95  
     public synchronized int getSkipped()
 96  
     {
 97  0
         return skipped;
 98  
     }
 99  
 
 100  
     public synchronized void add( TestSetStats testSetStats )
 101  
     {
 102  0
         this.completedCount += testSetStats.getCompletedCount();
 103  0
         this.errors += testSetStats.getErrors();
 104  0
         this.failures += testSetStats.getFailures();
 105  0
         this.skipped += testSetStats.getSkipped();
 106  0
     }
 107  
 
 108  
     public synchronized RunResult getRunResult()
 109  
     {
 110  0
         return new RunResult( completedCount, errors, failures, skipped );
 111  
     }
 112  
 
 113  
     public synchronized String getSummary()
 114  
     {
 115  0
         return "Tests run: " + completedCount + ", Failures: " + failures + ", Errors: " + errors + ", Skipped: "
 116  
             + skipped;
 117  
     }
 118  
 
 119  
 
 120  22
     private static class Sources
 121  
     {
 122  44
         private final Collection<String> listOfSources = new ArrayList<String>();
 123  
 
 124  
         void addSource( String source )
 125  
         {
 126  6
             synchronized ( listOfSources )
 127  
             {
 128  6
                 listOfSources.add( source );
 129  6
             }
 130  6
         }
 131  
 
 132  
         void addSource( StackTraceWriter stackTraceWriter )
 133  
         {
 134  6
             addSource( stackTraceWriter.smartTrimmedStackTrace() );
 135  6
         }
 136  
 
 137  
         Collection<String> getListOfSources()
 138  
         {
 139  6
             synchronized ( listOfSources )
 140  
             {
 141  6
                 return Collections.unmodifiableCollection( listOfSources );
 142  0
             }
 143  
         }
 144  
     }
 145  
 }