Coverage Report - org.apache.maven.plugin.surefire.SurefireHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
SurefireHelper
0%
0/26
0%
0/22
7.667
 
 1  
 package org.apache.maven.plugin.surefire;
 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.plugin.MojoFailureException;
 23  
 import org.apache.maven.plugin.logging.Log;
 24  
 import org.apache.maven.surefire.booter.ProviderConfiguration;
 25  
 import org.apache.maven.surefire.suite.RunResult;
 26  
 
 27  
 /**
 28  
  * Helper class for surefire plugins
 29  
  */
 30  
 public final class SurefireHelper
 31  
 {
 32  
 
 33  
     /**
 34  
      * Do not instantiate.
 35  
      */
 36  
     private SurefireHelper()
 37  0
     {
 38  0
         throw new IllegalAccessError( "Utility class" );
 39  
     }
 40  
 
 41  
     // Todo: Fix the duplication, probably by making failsafe relate to a "RunResult" too.
 42  
 
 43  
     public static void reportExecution( SurefireReportParameters reportParameters, RunResult result, Log log )
 44  
         throws MojoFailureException
 45  
     {
 46  
 
 47  
         String msg;
 48  
 
 49  
 //        System.out.println( "");
 50  
 //        System.out.println( result.getTestSetSummary() );
 51  
 
 52  0
         if ( result.getCompletedCount() == 0 )
 53  
         {
 54  0
             if ( ( reportParameters.getFailIfNoTests() == null )
 55  
                 || !reportParameters.getFailIfNoTests().booleanValue() )
 56  
             {
 57  0
                 return;
 58  
             }
 59  
             // TODO: i18n
 60  0
             throw new MojoFailureException(
 61  
                 "No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)" );
 62  
         }
 63  
 
 64  0
         if ( result.isErrrorFree() )
 65  
         {
 66  0
             return;
 67  
         }
 68  
 
 69  0
         if ( result.isFailureOrTimeout() )
 70  
         {
 71  0
             msg = "There was a timeout or other error in the fork";
 72  
         }
 73  
         else
 74  
         {
 75  
             // TODO: i18n
 76  0
             msg = "There are test failures.\n\nPlease refer to " + reportParameters.getReportsDirectory()
 77  
                 + " for the individual test results.";
 78  
 
 79  
         }
 80  
 
 81  0
         if ( reportParameters.isTestFailureIgnore() )
 82  
         {
 83  0
             log.error( msg );
 84  
         }
 85  
         else
 86  
         {
 87  0
             throw new MojoFailureException( msg );
 88  
         }
 89  0
     }
 90  
 
 91  
     public static void reportExecution( SurefireReportParameters reportParameters, int result, Log log )
 92  
         throws MojoFailureException
 93  
     {
 94  0
         if ( result == 0 )
 95  
         {
 96  0
             return;
 97  
         }
 98  
 
 99  
         String msg;
 100  
 
 101  0
         if ( result == ProviderConfiguration.NO_TESTS_EXIT_CODE )
 102  
         {
 103  0
             if ( ( reportParameters.getFailIfNoTests() == null )
 104  
                 || !reportParameters.getFailIfNoTests().booleanValue() )
 105  
             {
 106  0
                 return;
 107  
             }
 108  
             // TODO: i18n
 109  0
             throw new MojoFailureException(
 110  
                 "No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)" );
 111  
         }
 112  
         else
 113  
         {
 114  
             // TODO: i18n
 115  0
             msg = "There are test failures.\n\nPlease refer to " + reportParameters.getReportsDirectory()
 116  
                 + " for the individual test results.";
 117  
 
 118  
         }
 119  
 
 120  0
         if ( reportParameters.isTestFailureIgnore() )
 121  
         {
 122  0
             log.error( msg );
 123  
         }
 124  
         else
 125  
         {
 126  0
             throw new MojoFailureException( msg );
 127  
         }
 128  0
     }
 129  
 
 130  
 }