/**
 * Multimud Helper.
 * 
 * Copyright (C) 2009 Benjamin Lerman<br>
 * Copyright (C) 2009 Jacques ???
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.ambre.multimud_helper.config;

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

import org.apache.commons.io.FileUtils;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * A class to setup tests.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/net/ambre/multimud_helper/spring/context.xml" })
public abstract class TestBase {

    /**
     * the logger to use.
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(TestBase.class);

    static {
        try {
            final File homeFile = File.createTempFile("home", "");
            homeFile.delete();
            homeFile.mkdirs();
            System.setProperty("user.home", homeFile.getCanonicalPath());
            Runtime.getRuntime().addShutdownHook(new Thread() {

                /**
                 * {@inheritedDoc}
                 */
                @Override
                public void run() {
                    try {
                        FileUtils.deleteDirectory(homeFile);
                    } catch (IOException e) {
                        LOGGER.error(e.getLocalizedMessage(), e);
                    }
                }

            });
        } catch (IOException e) {
            LOGGER.error(e.getLocalizedMessage(), e);
        }
    }

}
