/**
 * 
 */
package uk.co.jemos.podam.test.unit;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

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

import uk.co.jemos.podam.api.DataProviderStrategy;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;
import uk.co.jemos.podam.api.RandomDataProviderStrategy;
import uk.co.jemos.podam.common.PodamConstants;
import uk.co.jemos.podam.test.dto.PojoWithMapsAndCollections;
import uk.co.jemos.podam.test.strategies.CustomRandomDataProviderStrategy;

/**
 * It checks that the {@link RandomDataProviderStrategy} is initialised properly
 * 
 * @author Marco Tedone
 * 
 */
public class RandomDataProviderStrategyInitialisationUnitTest {

	private DataProviderStrategy strategy;
	
	private static final int numOfCollectionElemsBackup
			= RandomDataProviderStrategy.getInstance().getNumberOfCollectionElements(Object.class);

	@After
	public void after() {
		strategy.setDefaultNumberOfCollectionElements(numOfCollectionElemsBackup);
	}

	@Test
	public void testNumberOfCollectionElementChange() {

		strategy = RandomDataProviderStrategy.getInstance();
		Assert.assertEquals(
				"An incorrect default number of collection elements",
				PodamConstants.DEFAULT_NBR_COLLECTION_ELEMENTS,
				strategy.getNumberOfCollectionElements(Object.class));

		int aNumberOfCollectionElements = 3;
		strategy.setDefaultNumberOfCollectionElements(aNumberOfCollectionElements);
		Assert.assertEquals(
				"An incorrect default number of collection elements",
				aNumberOfCollectionElements,
				strategy.getNumberOfCollectionElements(Object.class));

	}

	@Test
	public void testInitialization() {

		strategy = RandomDataProviderStrategy.getInstance();
		Assert.assertEquals(
				"An incorrect default number of collection elements",
				PodamConstants.DEFAULT_NBR_COLLECTION_ELEMENTS,
				strategy.getNumberOfCollectionElements(Object.class));

		int aNumberOfCollectionElements = 3;
		strategy = RandomDataProviderStrategy
				.getInstance(aNumberOfCollectionElements);
		Assert.assertEquals(
				"An incorrect default number of collection elements",
				aNumberOfCollectionElements,
				strategy.getNumberOfCollectionElements(Object.class));

	}

	@Test
	public void testRandomDataProviderStrategy() {

		strategy = RandomDataProviderStrategy.getInstance();
		PodamFactory factory = new PodamFactoryImpl(strategy);
		PojoWithMapsAndCollections pojo =
				factory.manufacturePojo(PojoWithMapsAndCollections.class);

		Assert.assertNotNull("POJO manufacturing failed", pojo);
		Assert.assertNotNull("Array is null", pojo.getArray());
		Assert.assertEquals(
				strategy.getNumberOfCollectionElements(Object.class),
				pojo.getArray().length);
		Assert.assertNotNull("List is null", pojo.getList());
		Assert.assertEquals(
				strategy.getNumberOfCollectionElements(Object.class),
				pojo.getList().size());
		Assert.assertNotNull("Map is null", pojo.getMap());
		Assert.assertEquals(
				strategy.getNumberOfCollectionElements(Object.class),
				pojo.getMap().size());

	}

	@Test
	public void testCustomRandomDataProviderStrategy() {

		strategy = new CustomRandomDataProviderStrategy();
		PodamFactory factory = new PodamFactoryImpl(strategy);
		PojoWithMapsAndCollections pojo =
				factory.manufacturePojo(PojoWithMapsAndCollections.class);

		Assert.assertNotNull("POJO manufacturing failed", pojo);
		Assert.assertNotNull("Array is null", pojo.getArray());
		Assert.assertEquals(2, pojo.getArray().length);
		Assert.assertNotNull("List is null", pojo.getList());
		Assert.assertEquals(3, pojo.getList().size());
		Assert.assertNotNull("Map is null", pojo.getMap());
		Assert.assertEquals(4, pojo.getMap().size());

	}

	@Test
	public void testRandomProviderStrategyForLong() {

		strategy = new CustomRandomDataProviderStrategy();
		PodamFactory factory = new PodamFactoryImpl(strategy);
		Map<?, ?> pojo =
				factory.manufacturePojo(HashMap.class, Long.class, String.class);

		Assert.assertNotNull("POJO manufacturing failed", pojo);
		Assert.assertEquals("Wrong map size",
				strategy.getNumberOfCollectionElements(String.class),
				pojo.size());

	}

}

@@ -362,32 +362,153 @@
 oviderStrategy;%0A
+import uk.co.jemos.podam.common.AbstractConstructorComparator;%0Aimport uk.co.jemos.podam.common.AbstractMethodComparator;%0A
 import uk.co.jem
@@ -4279,10 +4279,1121 @@
 );%0A%0A%09%7D%0A%0A
+%09@Test%0A%09public void testConstructorComparator() %7B%0A%0A%09%09strategy = RandomDataProviderStrategy.getInstance();%0A%09%09RandomDataProviderStrategy randomStrategy = (RandomDataProviderStrategy) strategy;%0A%09%09AbstractConstructorComparator comparator = randomStrategy.getConstructorComparator();%0A%09%09Assert.assertNotNull(comparator);%0A%09%09randomStrategy.setConstructorComparator(null);%0A%09%09Assert.assertEquals(null, randomStrategy.getConstructorComparator());%0A%09%09randomStrategy.setConstructorComparator(comparator);%0A%09%09Assert.assertEquals(comparator, randomStrategy.getConstructorComparator());%0A%09%7D%0A%0A%09@Test%0A%09public void testMethodComparator() %7B%0A%0A%09%09strategy = RandomDataProviderStrategy.getInstance();%0A%09%09RandomDataProviderStrategy randomStrategy = (RandomDataProviderStrategy) strategy;%0A%09%09AbstractMethodComparator comparator = randomStrategy.getMethodComparator();%0A%09%09Assert.assertNotNull(comparator);%0A%09%09randomStrategy.setMethodComparator(null);%0A%09%09Assert.assertEquals(null, randomStrategy.getMethodComparator());%0A%09%09randomStrategy.setMethodComparator(comparator);%0A%09%09Assert.assertEquals(comparator, randomStrategy.getMethodComparator());%0A%09%7D%0A%0A
 %7D%0A

Test method and constructor comparators mangling in RandomDataProviderStrategy