Coverage Report - org.apache.maven.shared.tools.easymock.TestUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
TestUtils
0%
0/20
0%
0/2
1,5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.maven.shared.tools.easymock;
 20  
 
 21  
 import java.io.BufferedReader;
 22  
 import java.io.File;
 23  
 import java.io.FileReader;
 24  
 import java.io.FileWriter;
 25  
 import java.io.IOException;
 26  
 import java.io.PrintWriter;
 27  
 import java.io.StringWriter;
 28  
 
 29  
 import org.codehaus.plexus.util.IOUtil;
 30  
 
 31  
 public final class TestUtils
 32  
 {
 33  
 
 34  
     private TestUtils()
 35  0
     {
 36  0
     }
 37  
 
 38  
     public static void writeToFile( File file, String testStr )
 39  
         throws IOException
 40  
     {
 41  0
         FileWriter fw = null;
 42  
         try
 43  
         {
 44  0
             fw = new FileWriter( file );
 45  0
             fw.write( testStr );
 46  
         }
 47  
         finally
 48  
         {
 49  0
             IOUtil.close( fw );
 50  0
         }
 51  0
     }
 52  
 
 53  
     public static String readFile( File file )
 54  
         throws IOException
 55  
     {
 56  0
         StringBuffer buffer = new StringBuffer();
 57  
 
 58  0
         BufferedReader reader = new BufferedReader( new FileReader( file ) );
 59  
 
 60  0
         String line = null;
 61  
 
 62  0
         while ( ( line = reader.readLine() ) != null )
 63  
         {
 64  0
             if ( buffer.length() > 0 )
 65  
             {
 66  0
                 buffer.append( '\n' );
 67  
             }
 68  
 
 69  0
             buffer.append( line );
 70  
         }
 71  
 
 72  0
         return buffer.toString();
 73  
     }
 74  
 
 75  
     public static String toString( Throwable error )
 76  
     {
 77  0
         StringWriter sw = new StringWriter();
 78  0
         PrintWriter pw = new PrintWriter( sw );
 79  
 
 80  0
         error.printStackTrace( pw );
 81  
 
 82  0
         return sw.toString();
 83  
     }
 84  
 }