<commit_before>package net.meisen.general.genmisc.exceptions.registry;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

import net.meisen.general.genmisc.exceptions.catalog.DefaultLocalizedExceptionCatalog;
import net.meisen.general.genmisc.exceptions.catalog.IExceptionCatalog;
import net.meisen.general.genmisc.exceptions.catalog.InvalidCatalogEntryException;
import net.meisen.general.genmisc.exceptions.registry.stubs.FullException;
import net.meisen.general.genmisc.exceptions.registry.stubs.OnlyMessageAndThrowableException;
import net.meisen.general.genmisc.exceptions.registry.stubs.OnlyMessageException;
import net.meisen.general.genmisc.exceptions.registry.stubs.OnlyThrowableException;
import net.meisen.general.genmisc.types.Dates;

import org.junit.Test;

/**
 * Tests the implementation of the <code>DefaultExceptionRegistry</code>.
 * 
 * @author pmeisen
 * 
 */
public class TestDefaultExceptionRegistry {

	/**
	 * Tests the creation of constructors with different constructors.
	 * 
	 * @throws InvalidCatalogEntryException
	 *           if the bundle cannot be loaded
	 */
	@Test
	public void testDifferentConstructors() throws InvalidCatalogEntryException {
		final DefaultExceptionRegistry registry = new DefaultExceptionRegistry();
		final DefaultLocalizedExceptionCatalog catalog = new DefaultLocalizedExceptionCatalog(
				"net/meisen/general/genmisc/exceptions/catalog/localizedCatalog/testExceptions");

		// create the registry
		registry.addExceptionCatalog(FullException.class, catalog);
		registry.addExceptionCatalog(OnlyMessageException.class, catalog);
		registry.addExceptionCatalog(OnlyThrowableException.class, catalog);
		registry.addExceptionCatalog(OnlyMessageAndThrowableException.class,
				catalog);

		// throw some exceptions and check the result
		try {
			registry.throwException(FullException.class, 1000);
			fail("Exception was not thrown.");
		} catch (final FullException e) {
			assertNull(e.getCause());
			assertEquals("This is the first sample value", e.getMessage());
		}

		try {
			registry.throwException(FullException.class, 1000, new Locale("de"));
			fail("Exception was not thrown.");
		} catch (final FullException e) {
			assertNull(e.getCause());
			assertEquals("Dies ist der erste Testwert", e.getMessage());
		}

		try {
			registry.throwException(FullException.class, 1000, new Locale("de"),
					new IllegalStateException("Dummy"));
			fail("Exception was not thrown.");
		} catch (final FullException e) {
			assertNotNull(e.getCause());
			assertEquals(IllegalStateException.class, e.getCause().getClass());
			assertEquals("Dies ist der erste Testwert", e.getMessage());
		}

		try {
			registry.throwException(OnlyMessageException.class, 1001);
			fail("Exception was not thrown.");
		} catch (final OnlyMessageException e) {
			assertNull(e.getCause());
			assertEquals("This is the second value", e.getMessage());
		}

		try {
			registry.throwException(OnlyMessageAndThrowableException.class, 1002,
					new Locale("fr"));
			fail("Exception was not thrown.");<commit_msg>- fixed a bug in the test-case when the default locale wouldn't be English<commit_after>package net.meisen.general.genmisc.exceptions.registry;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

import net.meisen.general.genmisc.exceptions.catalog.DefaultLocalizedExceptionCatalog;
import net.meisen.general.genmisc.exceptions.catalog.IExceptionCatalog;
import net.meisen.general.genmisc.exceptions.catalog.InvalidCatalogEntryException;
import net.meisen.general.genmisc.exceptions.registry.stubs.FullException;
import net.meisen.general.genmisc.exceptions.registry.stubs.OnlyMessageAndThrowableException;
import net.meisen.general.genmisc.exceptions.registry.stubs.OnlyMessageException;
import net.meisen.general.genmisc.exceptions.registry.stubs.OnlyThrowableException;
import net.meisen.general.genmisc.types.Dates;

import org.junit.Test;

/**
 * Tests the implementation of the <code>DefaultExceptionRegistry</code>.
 * 
 * @author pmeisen
 * 
 */
public class TestDefaultExceptionRegistry {

	/**
	 * Tests the creation of constructors with different constructors.
	 * 
	 * @throws InvalidCatalogEntryException
	 *           if the bundle cannot be loaded
	 */
	@Test
	public void testDifferentConstructors() throws InvalidCatalogEntryException {
		final DefaultExceptionRegistry registry = new DefaultExceptionRegistry();
		final DefaultLocalizedExceptionCatalog catalog = new DefaultLocalizedExceptionCatalog(
				"net/meisen/general/genmisc/exceptions/catalog/localizedCatalog/testExceptions");

		// create the registry
		registry.addExceptionCatalog(FullException.class, catalog);
		registry.addExceptionCatalog(OnlyMessageException.class, catalog);
		registry.addExceptionCatalog(OnlyThrowableException.class, catalog);
		registry.addExceptionCatalog(OnlyMessageAndThrowableException.class,
				catalog);

		// throw some exceptions and check the result
		try {
			registry.throwException(FullException.class, 1000, new Locale("en"));
			fail("Exception was not thrown.");
		} catch (final FullException e) {
			assertNull(e.getCause());
			assertEquals("This is the first sample value", e.getMessage());
		}

		try {
			registry.throwException(FullException.class, 1000, new Locale("de"));
			fail("Exception was not thrown.");
		} catch (final FullException e) {
			assertNull(e.getCause());
			assertEquals("Dies ist der erste Testwert", e.getMessage());
		}

		try {
			registry.throwException(FullException.class, 1000, new Locale("de"),
					new IllegalStateException("Dummy"));
			fail("Exception was not thrown.");
		} catch (final FullException e) {
			assertNotNull(e.getCause());
			assertEquals(IllegalStateException.class, e.getCause().getClass());
			assertEquals("Dies ist der erste Testwert", e.getMessage());
		}

		try {
			registry.throwException(OnlyMessageException.class, 1001, new Locale("en"));
			fail("Exception was not thrown.");
		} catch (final OnlyMessageException e) {
			assertNull(e.getCause());
			assertEquals("This is the second value", e.getMessage());
		}

		try {
			registry.throwException(OnlyMessageAndThrowableException.class, 1002,
					new Locale("fr"));
			fail("Exception was not thrown.");
{'fraction_non_alphanumeric': 0.10758057194734454, 'fraction_numerical': 0.006052352852171282, 'mean_word_length': 5.331417624521073, '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': '7154745', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1817, 'n_words': 398}