Coverage Report - org.apache.maven.surefire.common.junit4.JUnit4StackTraceWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
JUnit4StackTraceWriter
25%
4/16
0%
0/2
1,571
 
 1  
 package org.apache.maven.surefire.common.junit4;
 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.report.SafeThrowable;
 23  
 import org.apache.maven.surefire.report.SmartStackTraceParser;
 24  
 import org.apache.maven.surefire.report.StackTraceWriter;
 25  
 
 26  
 import org.junit.runner.notification.Failure;
 27  
 
 28  
 /**
 29  
  * Writes out a specific {@link org.junit.runner.notification.Failure} for
 30  
  * surefire as a stacktrace.
 31  
  *
 32  
  * @author Karl M. Davis
 33  
  */
 34  
 public class JUnit4StackTraceWriter
 35  
     implements StackTraceWriter
 36  
 {
 37  
     // Member Variables
 38  
     protected final Failure junitFailure;
 39  
 
 40  
     /**
 41  
      * Constructor.
 42  
      *
 43  
      * @param junitFailure the {@link Failure} that this will be operating on
 44  
      */
 45  
     public JUnit4StackTraceWriter( Failure junitFailure )
 46  1
     {
 47  1
         this.junitFailure = junitFailure;
 48  1
     }
 49  
 
 50  
     /*
 51  
       * (non-Javadoc)
 52  
       *
 53  
       * @see org.apache.maven.surefire.report.StackTraceWriter#writeTraceToString()
 54  
       */
 55  
     public String writeTraceToString()
 56  
     {
 57  0
         return junitFailure.getTrace();
 58  
     }
 59  
 
 60  
 
 61  
     protected String getTestClassName()
 62  
     {
 63  0
         return JUnit4RunListener.extractClassName( junitFailure.getDescription() );
 64  
     }
 65  
 
 66  
     protected String getTestMethodName()
 67  
     {
 68  0
         return JUnit4RunListener.extractMethodName( junitFailure.getDescription() );
 69  
     }
 70  
 
 71  
     @SuppressWarnings( "ThrowableResultOfMethodCallIgnored" )
 72  
     public String smartTrimmedStackTrace()
 73  
     {
 74  0
         Throwable exception = junitFailure.getException();
 75  0
         if ( exception != null )
 76  
         {
 77  0
             SmartStackTraceParser smartStackTraceParser = new SmartStackTraceParser( getTestClassName(), exception,
 78  
                                                                                      getTestMethodName() );
 79  0
             return smartStackTraceParser.getString();
 80  
         }
 81  
         else
 82  
         {
 83  0
             return junitFailure.getMessage();
 84  
         }
 85  
     }
 86  
 
 87  
     /**
 88  
      * At the moment, returns the same as {@link #writeTraceToString()}.
 89  
      *
 90  
      * @see org.apache.maven.surefire.report.StackTraceWriter#writeTrimmedTraceToString()
 91  
      */
 92  
     public String writeTrimmedTraceToString()
 93  
     {
 94  0
         String testClass = getTestClassName();
 95  
         try
 96  
         {
 97  0
             return SmartStackTraceParser.innerMostWithFocusOnClass( junitFailure.getException(), testClass );
 98  
         }
 99  0
         catch ( Throwable t )
 100  
         {
 101  0
             return SmartStackTraceParser.innerMostWithFocusOnClass( t, testClass );
 102  
         }
 103  
     }
 104  
 
 105  
     /**
 106  
      * Returns the exception associated with this failure.
 107  
      *
 108  
      * @see org.apache.maven.surefire.report.StackTraceWriter#getThrowable()
 109  
      */
 110  
     public SafeThrowable getThrowable()
 111  
     {
 112  2
         return new SafeThrowable( junitFailure.getException() );
 113  
     }
 114  
 
 115  
 }