<commit_before>package jcommon.extract;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import jcommon.Arch;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import jcommon.OSFamily;
import jcommon.Path;
import jcommon.Sys;
import jcommon.extract.processors.FileProcessor;
import jcommon.extract.processors.LibraryProcessor;
import static org.junit.Assert.*;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class ResourcesTest {
	//<editor-fold defaultstate="collapsed" desc="Setup">
	public ResourcesTest() {
	}

	@BeforeClass
	public static void setUpClass() throws Exception {
	}

	@AfterClass
	public static void tearDownClass() throws Exception {
	}

	@Before
	public void setUp() {
		//assertTrue("These unit tests require Windows to complete", Sys.isOSFamily(OSFamily.Windows));
	}

	@After
	public void tearDown() {
	}
	//</editor-fold>

	@Test
	public void testVariables() {
		String tmpDir = Path.tempDirectory;
		String homeDir = Path.homeDirectory;

		IVariableProcessor varproc = VariableProcessorFactory.newInstance();
		assertEquals("/" + tmpDir + "/tmp/" + tmpDir + "/" + homeDir + "/tmp", varproc.process("/${tmp}/tmp/${tmp}/${home}/tmp"));

		assertEquals("/home/", varproc.process("/home/"));
		assertEquals(tmpDir + "/", varproc.process("${tmp}/"));
		assertEquals("/" + tmpDir + "/", varproc.process("/${tmp}/"));
		assertEquals(homeDir + "/", varproc.process("${home}/"));
		assertEquals("/" + homeDir + "/", varproc.process("/${home}/"));
	}

	@Test
	public void testResourceProcessorFactory() {
		assertFalse(ResourceProcessorFactory.getDefaultProcessors().isEmpty());

		final ResourceProcessorFactory factory = ResourceProcessorFactory.newInstance();
		assertNotNull(factory);

		assertFalse(factory.addProcessors(ResourcesTest.class));
	}

	@Test
	public void testRead() {
		Resources r1 = Resources.newInstance(
        Sys.createPlatformPackageResourcePrefix("resources.extraction") + "test.xml"
    );
		assertNotNull(r1);

		assertEquals(1, r1.getTotalPackageCount());
		assertEquals(7, r1.getTotalResourceCount());

		Resources r2 = Resources.newInstance(
			Package.newInstance("test", ".")
		);
		assertEquals(1, r2.getTotalPackageCount());
		assertEquals(0, r2.getTotalResourceCount());

		Resources r3 = Resources.newInstance(
			Package.newInstance("test", "."),
			Package.newInstance("test", ".")
		);
		assertEquals(2, r3.getTotalPackageCount());
		assertEquals(0, r3.getTotalResourceCount());

		Resources r4 = Resources.newInstance(<commit_msg>Minor fix to test case.<commit_after>package jcommon.extract;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import jcommon.Arch;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import jcommon.OSFamily;
import jcommon.Path;
import jcommon.Sys;
import jcommon.extract.processors.FileProcessor;
import jcommon.extract.processors.LibraryProcessor;
import static org.junit.Assert.*;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class ResourcesTest {
	//<editor-fold defaultstate="collapsed" desc="Setup">
	public ResourcesTest() {
	}

	@BeforeClass
	public static void setUpClass() throws Exception {
	}

	@AfterClass
	public static void tearDownClass() throws Exception {
	}

	@Before
	public void setUp() {
		//assertTrue("These unit tests require Windows to complete", Sys.isOSFamily(OSFamily.Windows));
	}

	@After
	public void tearDown() {
	}
	//</editor-fold>

	@Test
	public void testVariables() {
		String tmpDir = Path.tempDirectory;
		String homeDir = Path.homeDirectory;

		IVariableProcessor varproc = VariableProcessorFactory.newInstance();
		assertEquals("/" + tmpDir + "/tmp/" + tmpDir + "/" + homeDir + "/tmp", varproc.process("/${tmp}/tmp/${tmp}/${home}/tmp"));

		assertEquals("/home/", varproc.process("/home/"));
		assertEquals(tmpDir + "/", varproc.process("${tmp}/"));
		assertEquals("/" + tmpDir + "/", varproc.process("/${tmp}/"));
		assertEquals(homeDir + "/", varproc.process("${home}/"));
		assertEquals("/" + homeDir + "/", varproc.process("/${home}/"));
	}

	@Test
	public void testResourceProcessorFactory() {
		assertFalse(ResourceProcessorFactory.getDefaultProcessors().isEmpty());

		final ResourceProcessorFactory factory = ResourceProcessorFactory.newInstance();
		assertNotNull(factory);

		assertFalse(factory.addProcessors(ResourcesTest.class));
	}

	@Test
	public void testRead() {
    if (OSFamily.getSystemOSFamily() != OSFamily.Windows)
      return;

		Resources r1 = Resources.newInstance(
        Sys.createPlatformPackageResourcePrefix("resources.extraction") + "test.xml"
    );
		assertNotNull(r1);

		assertEquals(1, r1.getTotalPackageCount());
		assertEquals(7, r1.getTotalResourceCount());

		Resources r2 = Resources.newInstance(
			Package.newInstance("test", ".")
		);
		assertEquals(1, r2.getTotalPackageCount());
		assertEquals(0, r2.getTotalResourceCount());

		Resources r3 = Resources.newInstance(
			Package.newInstance("test", "."),
			Package.newInstance("test", ".")
		);
		assertEquals(2, r3.getTotalPackageCount());
		assertEquals(0, r3.getTotalResourceCount());

		Resources r4 = Resources.newInstance(
{'fraction_non_alphanumeric': 0.15378802191573776, 'fraction_numerical': 0.006423578310976762, 'mean_word_length': 5.085057471264368, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6953501', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1556, 'n_words': 307}