<commit_before>/*
 * IzPack - Copyright 2001-2012 <NAME>, All Rights Reserved.
 *
 * http://izpack.org/
 * http://izpack.codehaus.org/
 *
 * Copyright 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.izforge.izpack.panels.target;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import org.junit.Test;

import com.izforge.izpack.api.data.AutomatedInstallData;
import com.izforge.izpack.api.data.InstallData;
import com.izforge.izpack.api.data.Pack;
import com.izforge.izpack.api.data.Variables;
import com.izforge.izpack.core.data.DefaultVariables;
import com.izforge.izpack.util.Platforms;
import com.izforge.izpack.util.file.FileUtils;


/**
 * Tests the {@link TargetPanelHelper} class.
 *
 * @author <NAME>
 */
public class TargetPanelHelperTest
{

    /**
     * Tests the {@link TargetPanelHelper#getPath(InstallData)} method.
     */
    @Test
    public void testGetPath()
    {
        Variables variables = new DefaultVariables();
        InstallData installData = new AutomatedInstallData(variables, Platforms.WINDOWS_7);

        // verify that the user dir is returned if no other variable is set
        System.setProperty("user.dir", "userdir");
        assertEquals("userdir", TargetPanelHelper.getPath(installData));

        // verify that the DEFAULT_INSTALL_PATH overrides SYSTEM_user_dir
        variables.set("DEFAULT_INSTALL_PATH", "default");
        assertEquals("default", TargetPanelHelper.getPath(installData));

        // verify that the TargetPanel.dir overrides DEFAULT_INSTALL_PATH
        variables.set("TargetPanel.dir", "override");
        assertEquals("override", TargetPanelHelper.getPath(installData));
    }
<commit_msg>Added @Before and @After that restores the 'user.dir' after every test.<commit_after>/*
 * IzPack - Copyright 2001-2012 <NAME>, All Rights Reserved.
 *
 * http://izpack.org/
 * http://izpack.codehaus.org/
 *
 * Copyright 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.izforge.izpack.panels.target;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.izforge.izpack.api.data.AutomatedInstallData;
import com.izforge.izpack.api.data.InstallData;
import com.izforge.izpack.api.data.Pack;
import com.izforge.izpack.api.data.Variables;
import com.izforge.izpack.core.data.DefaultVariables;
import com.izforge.izpack.util.Platforms;
import com.izforge.izpack.util.file.FileUtils;


/**
 * Tests the {@link TargetPanelHelper} class.
 *
 * @author <NAME>
 */
public class TargetPanelHelperTest
{
	private String orgUserDir;
	
	@Before
	public void initialize() {
		orgUserDir = System.getProperty("user.dir");
	}
	
	@After
	public void cleanup() {
		System.setProperty("user.dir", orgUserDir);
	}
	
    /**
     * Tests the {@link TargetPanelHelper#getPath(InstallData)} method.
     */
    @Test
    public void testGetPath()
    {
        Variables variables = new DefaultVariables();
        InstallData installData = new AutomatedInstallData(variables, Platforms.WINDOWS_7);

        // verify that the user dir is returned if no other variable is set
        System.setProperty("user.dir", "userdir");
        assertEquals("userdir", TargetPanelHelper.getPath(installData));

        // verify that the DEFAULT_INSTALL_PATH overrides SYSTEM_user_dir
        variables.set("DEFAULT_INSTALL_PATH", "default");
        assertEquals("default", TargetPanelHelper.getPath(installData));

        // verify that the TargetPanel.dir overrides DEFAULT_INSTALL_PATH
        variables.set("TargetPanel.dir", "override");
        assertEquals("override", TargetPanelHelper.getPath(installData));
    }

{'fraction_non_alphanumeric': 0.10470292239210373, 'fraction_numerical': 0.006580220630927037, 'mean_word_length': 3.9549376797698947, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4048919', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1431, 'n_words': 415}