Coverage Report - org.apache.maven.surefire.testng.TestNGStackTraceWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
TestNGStackTraceWriter
0% 
0% 
3
 
 1  
 /*
 2  
  * Copyright 2005-2006 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.maven.surefire.testng;
 18  
 
 19  
 import org.apache.maven.surefire.report.PojoStackTraceWriter;
 20  
 import org.codehaus.plexus.util.StringUtils;
 21  
 import org.testng.ITestResult;
 22  
 
 23  
 /**
 24  
  * Write out stack traces for TestNG.
 25  
  *
 26  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 27  
  */
 28  
 public class TestNGStackTraceWriter
 29  
     extends PojoStackTraceWriter
 30  
 {
 31  
     public TestNGStackTraceWriter( ITestResult result )
 32  
     {
 33  0
         super( result.getTestClass().getRealClass().getName(), result.getMethod().getMethodName(),
 34  
                result.getThrowable() );
 35  0
     }
 36  
 
 37  
     public String writeTrimmedTraceToString()
 38  
     {
 39  0
         String text = writeTraceToString();
 40  
 
 41  0
         String marker = "at " + testClass + "." + testMethod;
 42  
 
 43  0
         String[] lines = StringUtils.split( text, "\n" );
 44  0
         int lastLine = lines.length - 1;
 45  
         // skip first
 46  0
         for ( int i = 1; i < lines.length; i++ )
 47  
         {
 48  0
             if ( lines[i].trim().startsWith( marker ) )
 49  
             {
 50  0
                 lastLine = i;
 51  
             }
 52  
         }
 53  
 
 54  0
         StringBuffer trace = new StringBuffer();
 55  0
         for ( int i = 0; i <= lastLine; i++ )
 56  
         {
 57  
             // if you call assertions from JUnit tests in TestNG, it ends up at the top of the trace
 58  0
             if ( !lines[i].trim().startsWith( "at junit.framework.Assert" ) )
 59  
             {
 60  0
                 trace.append( lines[i] );
 61  0
                 trace.append( "\n" );
 62  
             }
 63  
         }
 64  
 
 65  0
         return trace.toString();
 66  
     }
 67  
 }