<commit_before>package kuleuven.group2.classloader;

import static org.junit.Assert.*;

import java.lang.reflect.Method;

import kuleuven.group2.compile.EclipseCompiler;
import kuleuven.group2.compile.NameUtils;
import kuleuven.group2.store.MemoryStore;
import kuleuven.group2.store.Store;

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

public class StoreClassLoaderTest {

	protected Store sourceStore;
	protected Store binaryStore;
	protected EclipseCompiler compiler;
	protected ClassLoader classLoader;

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

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

	@Before
	public void setUp() throws Exception {
		sourceStore = new MemoryStore();
		binaryStore = new MemoryStore();
		classLoader = new StoreClassLoader(binaryStore);
		compiler = new EclipseCompiler(sourceStore, binaryStore, classLoader);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testLoadClassSimple() throws ClassNotFoundException {
		String className = "A";
		String source =
				"public class A {\n" +
						"public boolean foo() { return true; }\n" +
						"}";
		
		sourceStore.write(NameUtils.toSourceName(className), source.getBytes());
		
		compiler.compileAll();
	
		Class<?> loadedClass = classLoader.loadClass(className);
		
		assertEquals(className, loadedClass.getName());
	}

	@Test
	public void testLoadClassAnnotations() throws ClassNotFoundException {
		String className = "ATest";
		String source =
				"import org.junit.Test; \n" + 
						"public class " + className + " {\n" +
						"@Test\n" +
						"public void foo() { int i = 0; }\n" +
						"}";
		
		sourceStore.write(NameUtils.toSourceName(className), source.getBytes());
		
		compiler.compileAll();
	
		Class<?> loadedClass = classLoader.loadClass(className);
		
		assertEquals(className, loadedClass.getName());
		
		for(Method method : loadedClass.getMethods()) {
			if (method.getName().equals("foo")) {
				// if this test fails, could also be problem with compiler
				assertNotNull(method.getAnnotation(Test.class));
			}
		}
	}
	
	@Test(expected=ClassNotFoundException.class)
	public void testLoadClassNotInStore() throws ClassNotFoundException {
		classLoader.loadClass("NonExistingClass");
	}

}<commit_msg>findResource test<commit_after>package kuleuven.group2.classloader;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.lang.reflect.Method;

import kuleuven.group2.compile.EclipseCompiler;
import kuleuven.group2.compile.NameUtils;
import kuleuven.group2.store.MemoryStore;
import kuleuven.group2.store.Store;

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

import com.google.common.io.ByteStreams;

public class StoreClassLoaderTest {

	protected Store sourceStore;
	protected Store binaryStore;
	protected EclipseCompiler compiler;
	protected ClassLoader classLoader;

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

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

	@Before
	public void setUp() throws Exception {
		sourceStore = new MemoryStore();
		binaryStore = new MemoryStore();
		classLoader = new StoreClassLoader(binaryStore);
		compiler = new EclipseCompiler(sourceStore, binaryStore, classLoader);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testLoadClassSimple() throws ClassNotFoundException {
		String className = "A";
		String source =
				"public class A {\n" +
						"public boolean foo() { return true; }\n" +
						"}";
		
		sourceStore.write(NameUtils.toSourceName(className), source.getBytes());
		
		compiler.compileAll();
	
		Class<?> loadedClass = classLoader.loadClass(className);
		
		assertEquals(className, loadedClass.getName());
	}

	@Test
	public void testLoadClassAnnotations() throws ClassNotFoundException {
		String className = "ATest";
		String source =
				"import org.junit.Test; \n" + 
						"public class " + className + " {\n" +
						"@Test\n" +
						"public void foo() { int i = 0; }\n" +
						"}";
		
		sourceStore.write(NameUtils.toSourceName(className), source.getBytes());
		
		compiler.compileAll();
	
		Class<?> loadedClass = classLoader.loadClass(className);
		
		assertEquals(className, loadedClass.getName());
		
		for(Method method : loadedClass.getMethods()) {
			if (method.getName().equals("foo")) {
				// if this test fails, could also be problem with compiler
				assertNotNull(method.getAnnotation(Test.class));
			}
		}
	}
	
	@Test
	public void testFindResource() throws IOException {
		String sourceString = "hello world";
		String sourceName = "A";
		binaryStore.write(sourceName, sourceString.getBytes());
		
		InputStream inputStream = classLoader.getResourceAsStream(sourceName);
		
		byte[] bytes = ByteStreams.toByteArray(inputStream);
		String readString = new String(bytes);
		
		assertEquals(sourceString, readString);
	}
	
	@Test(expected=ClassNotFoundException.class)
	public void testLoadClassNotInStore() throws ClassNotFoundException {
		classLoader.loadClass("NonExistingClass");
	}

}
{'fraction_non_alphanumeric': 0.11115269461077844, 'fraction_numerical': 0.002245508982035928, 'mean_word_length': 4.585161964472309, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3109933', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1531, 'n_words': 370}