<commit_before>package net.ssehub.kernel_haven;

import java.io.File;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import net.ssehub.kernel_haven.util.Logger;
import net.ssehub.kernel_haven.util.Logger.Level;
import net.ssehub.kernel_haven.util.Util;

/**
 * Abstract superclass for all scenario tests. This sets up the proper test environment and executes the pipeline.
 * Subclasses can override the check*() methods for assertions on the output.
 *
 * @author Adam
 */
@SuppressWarnings("null")
public abstract class AbstractScenarioTest {

    private File resDir;
    
    private File cacheDir;
    
    private File outputDir;
    
    private File pluginsDir;
    
    private File logDir;
    
    private File srcTree;
    
    /**
     * We need to initialize the logger, since we use the Util class.
     */
    @BeforeClass
    public static void initLogger() {
        Logger.init();
        Logger.get().setLevel(Level.DEBUG);
    }
    
    /**
     * Creates the necessary temporary directories.
     * 
     * @throws IOException unwanted.
     */
    @Before
    public void setUp() throws IOException {
        resDir = new File("testdata", getClass().getSimpleName() + ".res");
        cacheDir = new File("testdata", getClass().getSimpleName() + ".cache");
        outputDir = new File("testdata", getClass().getSimpleName() + ".output");
        logDir = new File("testdata", getClass().getSimpleName() + ".log");
        pluginsDir = new File("testdata", getClass().getSimpleName() + ".plugins");
        srcTree = new File("testdata", getClass().getSimpleName() + ".src");

        Util.deleteFolder(resDir);
        Util.deleteFolder(cacheDir);
        Util.deleteFolder(outputDir);
        Util.deleteFolder(logDir);
        Util.deleteFolder(pluginsDir);
        Util.deleteFolder(srcTree);
        
        resDir.mkdir();
        cacheDir.mkdir();
        outputDir.mkdir();
        logDir.mkdir();
        pluginsDir.mkdir();
        copyFolder(getSourceTree(), srcTree);
    }
    
    /**
     * Deep-copies a folder to a destination.
     * 
     * @param src The source to copy.
     * @param dst The destination to copy to.
     * 
     * @throws IOException If copying fails.
     */
    private void copyFolder(File src, File dst) throws IOException {
        if (src.isDirectory()) {
            dst.mkdir();
            for (File file : src.listFiles()) {
                copyFolder(file, new File(dst, file.getName()));
            }
            
        } else {
            Util.copyFile(src, dst);
        }
    }
    
    /**
     * Main test method. Executes KernelHaven and calls the check*() methods.<commit_msg>Don't try to delete non-existing folders<commit_after>package net.ssehub.kernel_haven;

import java.io.File;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import net.ssehub.kernel_haven.util.Logger;
import net.ssehub.kernel_haven.util.Logger.Level;
import net.ssehub.kernel_haven.util.Util;

/**
 * Abstract superclass for all scenario tests. This sets up the proper test environment and executes the pipeline.
 * Subclasses can override the check*() methods for assertions on the output.
 *
 * @author Adam
 */
@SuppressWarnings("null")
public abstract class AbstractScenarioTest {

    private File resDir;
    
    private File cacheDir;
    
    private File outputDir;
    
    private File pluginsDir;
    
    private File logDir;
    
    private File srcTree;
    
    /**
     * We need to initialize the logger, since we use the Util class.
     */
    @BeforeClass
    public static void initLogger() {
        Logger.init();
        Logger.get().setLevel(Level.DEBUG);
    }
    
    /**
     * Creates the necessary temporary directories.
     * 
     * @throws IOException unwanted.
     */
    @Before
    public void setUp() throws IOException {
        resDir = new File("testdata", getClass().getSimpleName() + ".res");
        cacheDir = new File("testdata", getClass().getSimpleName() + ".cache");
        outputDir = new File("testdata", getClass().getSimpleName() + ".output");
        logDir = new File("testdata", getClass().getSimpleName() + ".log");
        pluginsDir = new File("testdata", getClass().getSimpleName() + ".plugins");
        srcTree = new File("testdata", getClass().getSimpleName() + ".src");

        if (resDir.exists()) {
            Util.deleteFolder(resDir);
        }
        if (cacheDir.exists()) {
            Util.deleteFolder(cacheDir);
        }
        if (outputDir.exists()) {
            Util.deleteFolder(outputDir);
        }
        if (logDir.exists()) {
            Util.deleteFolder(logDir);
        }
        if (pluginsDir.exists()) {
            Util.deleteFolder(pluginsDir);
        }
        if (srcTree.exists()) {
            Util.deleteFolder(srcTree);
        }
        
        resDir.mkdir();
        cacheDir.mkdir();
        outputDir.mkdir();
        logDir.mkdir();
        pluginsDir.mkdir();
        copyFolder(getSourceTree(), srcTree);
    }
    
    /**
     * Deep-copies a folder to a destination.
     * 
     * @param src The source to copy.
     * @param dst The destination to copy to.
     * 
     * @throws IOException If copying fails.
     */
    private void copyFolder(File src, File dst) throws IOException {
        if (src.isDirectory()) {
            dst.mkdir();
            for (File file : src.listFiles()) {
                copyFolder(file, new File(dst, file.getName()));
            }
            
        } else {
            Util.copyFile(src, dst);
        }
    }
    
    /**
     * Main test method. Executes KernelHaven and calls the check*() methods.
{'fraction_non_alphanumeric': 0.11924866448388764, 'fraction_numerical': 0.0, 'mean_word_length': 2.2809496890898813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3517965', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1611, 'n_words': 426}