Coverage Report - org.apache.maven.shared.tools.easymock.TestUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
TestUtils
0%
0/20
0%
0/4
1.5
 
 1  
 package org.apache.maven.shared.tools.easymock;
 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.io.BufferedReader;
 23  
 import java.io.File;
 24  
 import java.io.FileReader;
 25  
 import java.io.FileWriter;
 26  
 import java.io.IOException;
 27  
 import java.io.PrintWriter;
 28  
 import java.io.StringWriter;
 29  
 
 30  
 import org.codehaus.plexus.util.IOUtil;
 31  
 
 32  
 /**
 33  
  * @version $Id: TestUtils.java 677117 2008-07-16 00:29:56Z vsiveton $
 34  
  */
 35  
 public final class TestUtils
 36  
 {
 37  
     private TestUtils()
 38  0
     {
 39  
         //nop
 40  0
     }
 41  
 
 42  
     /**
 43  
      * @param file
 44  
      * @param testStr
 45  
      * @throws IOException if any
 46  
      */
 47  
     public static void writeToFile( File file, String testStr )
 48  
         throws IOException
 49  
     {
 50  0
         FileWriter fw = null;
 51  
         try
 52  
         {
 53  0
             fw = new FileWriter( file );
 54  0
             fw.write( testStr );
 55  
         }
 56  
         finally
 57  
         {
 58  0
             IOUtil.close( fw );
 59  0
         }
 60  0
     }
 61  
 
 62  
     /**
 63  
      * @param file
 64  
      * @return
 65  
      * @throws IOException if any
 66  
      * @todo maybe used {@link IOUtil#toString(java.io.Reader)}
 67  
      */
 68  
     public static String readFile( File file )
 69  
         throws IOException
 70  
     {
 71  0
         StringBuffer buffer = new StringBuffer();
 72  
 
 73  0
         BufferedReader reader = new BufferedReader( new FileReader( file ) );
 74  
 
 75  0
         String line = null;
 76  
 
 77  0
         while ( ( line = reader.readLine() ) != null )
 78  
         {
 79  0
             if ( buffer.length() > 0 )
 80  
             {
 81  0
                 buffer.append( '\n' );
 82  
             }
 83  
 
 84  0
             buffer.append( line );
 85  
         }
 86  
 
 87  0
         return buffer.toString();
 88  
     }
 89  
 
 90  
     /**
 91  
      * @param error
 92  
      * @return
 93  
      */
 94  
     public static String toString( Throwable error )
 95  
     {
 96  0
         StringWriter sw = new StringWriter();
 97  0
         PrintWriter pw = new PrintWriter( sw );
 98  
 
 99  0
         error.printStackTrace( pw );
 100  
 
 101  0
         return sw.toString();
 102  
     }
 103  
 }