<commit_before>package org.displaytag.test;

import java.net.URL;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.meterware.servletunit.ServletRunner;


/**
 * Base TestCase class for tests.
 * @author <NAME>
 * @version $Revision$ ($Author$)
 */
public abstract class DisplaytagCase extends TestCase
{

    /**
     * logger.
     */
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * HttpUnit ServletRunner.
     */
    protected ServletRunner runner;

    /**
     * Instantiates a new test case.
     * @param name test name
     */
    public DisplaytagCase(String name)
    {
        super(name);
    }

    /**
     * Returns the tested jsp name.
     * @return jsp name
     */
    public abstract String getJspName();

    /**
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        // need to pass a web.xml file to setup servletunit working directory
        ClassLoader classLoader = getClass().getClassLoader();
        URL webXmlUrl = classLoader.getResource("WEB-INF/web.xml");
        String path = webXmlUrl.getFile();

        // start servletRunner
        runner = new ServletRunner(path, "");
        log.debug("ServletRunner setup OK");

        super.setUp();
    }

    /**
     * @see junit.framework.TestCase#tearDown()
     */
    protected void tearDown() throws Exception
    {
        // shutdown servlet engine
        runner.shutDown();
        super.tearDown();
    }

}<commit_msg>delete temp file before run, otherwise jasper wil never recompile the jsp<commit_after>package org.displaytag.test;

import java.io.File;
import java.net.URL;

import junit.framework.TestCase;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.meterware.servletunit.ServletRunner;


/**
 * Base TestCase class for tests.
 * @author <NAME>
 * @version $Revision$ ($Author$)
 */
public abstract class DisplaytagCase extends TestCase
{

    /**
     * logger.
     */
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * HttpUnit ServletRunner.
     */
    protected ServletRunner runner;

    /**
     * Instantiates a new test case.
     * @param name test name
     */
    public DisplaytagCase(String name)
    {
        super(name);
    }

    /**
     * Returns the tested jsp name.
     * @return jsp name
     */
    public abstract String getJspName();

    /**
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        // removed compiled jsp from a previous run.
        cleanupTempFile();

        // need to pass a web.xml file to setup servletunit working directory
        ClassLoader classLoader = getClass().getClassLoader();
        URL webXmlUrl = classLoader.getResource("WEB-INF/web.xml");
        String path = webXmlUrl.getFile();

        // start servletRunner
        runner = new ServletRunner(path, "");
        log.debug("ServletRunner setup OK");

        super.setUp();
    }

    /**
     * @see junit.framework.TestCase#tearDown()
     */
    protected void tearDown() throws Exception
    {
        // shutdown servlet engine
        runner.shutDown();
        super.tearDown();
    }

    /**
     * Clean up temporary files from a previous test.
     */
    private void cleanupTempFile()
    {
        if (SystemUtils.JAVA_IO_TMPDIR != null)
        {
            String path = SystemUtils.JAVA_IO_TMPDIR.substring(0, SystemUtils.JAVA_IO_TMPDIR.length() - 1)
                + getJspName();

            File tempFile = new File(StringUtils.replace(path, ".jsp", "$jsp.java"));
            if (tempFile.exists())
            {
                log.debug("Deleting temporary file " + tempFile.getPath());
                tempFile.delete();
            }
            tempFile = new File(StringUtils.replace(path, ".jsp", "$jsp.class"));
            if (tempFile.exists())
            {
                log.debug("Deleting temporary file " + tempFile.getPath());
                tempFile.delete();
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.11594543744120414, 'fraction_numerical': 0.00047036688617121356, 'mean_word_length': 2.2170953101361572, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '677870', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1197, 'n_words': 294}