package file;

import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class FileUtils {
  
  public static void cleanDir(File dir, String endPattern){
    for(String fileName: dir.getParentFile().list()){
      if(fileName.endsWith(endPattern)){
        File fileToDelete = new File(dir.getParentFile()+File.separator+fileName);
        fileToDelete.delete();
      }
    }
  }
  
  
  public static String sha1sum(InputStream file){
    MessageDigest digest = calculateSHA1(file);
    return digestToString(digest);
  }
  
  private static String digestToString(MessageDigest digest) {
    byte[] mdbytes = digest.digest();
    StringBuilder sb = new StringBuilder("");
    for (int i = 0; i < mdbytes.length; i++) {
        sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
    }
    return sb.toString();
  }

  private static MessageDigest calculateSHA1(InputStream inputStream) {
    MessageDigest digest = getSHA1();
    byte[] dataBytes = new byte[1024];     
    try {
      int nread = 0;
      while ((nread = inputStream.read(dataBytes)) != -1) {
        digest.update(dataBytes, 0, nread);
      }
    } catch(NullPointerException e){
     fail("File not found");
    } catch (IOException e) {
      fail(e.getMessage());
    }
    return digest;
  }

  private static MessageDigest getSHA1(){
    MessageDigest digest = null;
    try {
      digest = MessageDigest.getInstance("SHA1");
    } catch (NoSuchAlgorithmException e) {
      fail("No such algorithmException thrown "+ e.getMessage());
    }
    return digest;
  }


}

@@ -231,24 +231,173 @@
 eUtils %7B%0A  %0A
+  private static String suffixTest = %22.test%22;%0A  %0A  public static void setSuffixTest(String suffixTest)%7B%0A    FileUtils.suffixTest = suffixTest; %0A  %7D%0A%0A
   public sta
@@ -647,15 +647,96 @@
 ete.
-delete(
+renameTo(new File(fileToDelete.getAbsolutePath().replaceAll(endPattern, %22-%22+suffixTest))
 );%0A 

Renombra los ficheros de la salida del test con un sufijo definido