<commit_before>package org.soitoolkit.tools.generator.plugin.model;

import static org.junit.Assert.*;
import static org.junit.Assert.fail;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import groovy.lang.GroovyClassLoader;

import org.codehaus.groovy.control.CompilationFailedException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

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

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

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testDefaultModelImpl() {
		IModel model = ModelFactory.newModel("groupId", "artifactId", "version", "service", null);
		assertEquals("artifactId", model.getServiceProject());
		assertEquals("artifactId-web", model.getWebProject());
	}

	@Test
	public void testCustomModelImpl() throws InstantiationException, IllegalAccessException {
		ModelFactory.setModelClass(CustomizedModelImpl.class);
		IModel model = ModelFactory.newModel("groupId", "artifactId", "version", "service", null);
		assertEquals("artifactId-intsvc", model.getServiceProject());
		assertEquals("artifactId-web", model.getWebProject());
	}
	
	@Test
	public void testGroovyModelImpl() throws CompilationFailedException, IOException {
		
		URL url = new URL("file:test/org/soitoolkit/tools/generator/plugin/model/GroovyModelImpl.groovy");	
		assertNotNull("Groovy class not found", url);

		ModelFactory.setModelGroovyClass(url);
		IModel model = ModelFactory.newModel("groupId", "artifactId", "version", "service", null);
		assertEquals("artifactId-svc", model.getServiceProject());
		assertEquals("composites/artifactId-svc", model.getServiceProjectFilepath());
		assertEquals("modules/artifactId-web", model.getWebProjectFilepath());
		assertEquals("modules/artifactId-teststub-web", model.getTeststubWebProjectFilepath());
	}

	@Test
	public void testCustomModelImpl_error() throws InstantiationException, IllegalAccessException {
		try {
			ModelFactory.setModelClass(String.class);
			fail("Expected IllegalArgumentException to be throwed");
		} catch (IllegalArgumentException e) {
			// Expected exception catched!
		}
	}	
}<commit_msg>Now resets the model-class in ModelFactory to avoide side-effects after the tests are run<commit_after>package org.soitoolkit.tools.generator.plugin.model;

import static org.junit.Assert.*;
import static org.junit.Assert.fail;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import groovy.lang.GroovyClassLoader;

import org.codehaus.groovy.control.CompilationFailedException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

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

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

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testDefaultModelImpl() {
		IModel model = ModelFactory.newModel("groupId", "artifactId", "version", "service", null);
		assertEquals("artifactId", model.getServiceProject());
		assertEquals("artifactId-web", model.getWebProject());
	}

	@Test
	public void testCustomModelImpl() throws InstantiationException, IllegalAccessException {
		try {
			ModelFactory.setModelClass(CustomizedModelImpl.class);
			IModel model = ModelFactory.newModel("groupId", "artifactId", "version", "service", null);
			assertEquals("artifactId-intsvc", model.getServiceProject());
			assertEquals("artifactId-web", model.getWebProject());
		} finally {
			ModelFactory.resetModelClass();
		}
	}
	
	@Test
	public void testGroovyModelImpl() throws CompilationFailedException, IOException {

		try {
//			URL url = new URL("http://soi-toolkit.googlecode.com/svn/trunk/tools/soitoolkit-generator/soitoolkit-generator-plugin/test/org/soitoolkit/tools/generator/plugin/model/GroovyModelImpl.groovy");
			URL url = new URL("file:test/org/soitoolkit/tools/generator/plugin/model/GroovyModelImpl.groovy");	
			assertNotNull("Groovy class not found", url);

			ModelFactory.setModelGroovyClass(url);
			IModel model = ModelFactory.newModel("groupId", "artifactId", "version", "service", null);
			assertEquals("artifactId-svc", model.getServiceProject());
			assertEquals("composites/artifactId-svc", model.getServiceProjectFilepath());
			assertEquals("modules/artifactId-web", model.getWebProjectFilepath());
			assertEquals("modules/artifactId-teststub-web", model.getTeststubWebProjectFilepath());
		} finally {
			ModelFactory.resetModelClass();
		}
	}

	@Test
	public void testCustomModelImpl_error() throws InstantiationException, IllegalAccessException {
		try {
			ModelFactory.setModelClass(String.class);
			fail("Expected IllegalArgumentException to be throwed");
		} catch (IllegalArgumentException e) {
			// Expected exception catched!
		}
	}	
}
{'fraction_non_alphanumeric': 0.11675412293853074, 'fraction_numerical': 0.0, 'mean_word_length': 5.877577319587629, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1470727', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1516, 'n_words': 321}