/*
 * The MIT License
 *
 *   Copyright (c) 2015, Mahmoud Ben Hassine (mahmoud@benhassine.fr)
 *
 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 *   of this software and associated documentation files (the "Software"), to deal
 *   in the Software without restriction, including without limitation the rights
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *   copies of the Software, and to permit persons to whom the Software is
 *   furnished to do so, subject to the following conditions:
 *
 *   The above copyright notice and this permission notice shall be included in
 *   all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *   THE SOFTWARE.
 */

package io.github.benas.jpopulator.randomizers;

import org.junit.Before;
import org.junit.Test;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Test class for {@link io.github.benas.jpopulator.randomizers.MapRandomizer}.
 *
 * @author Mahmoud Ben Hassine (mahmoud@benhassine.fr)
 */
public class MapRandomizerTest {

    private MapRandomizer<String, String> mapRandomizer;

    @Before
    public void setUp() throws Exception {
        mapRandomizer = new MapRandomizer<String, String>(new FirstNameRandomizer(), new LastNameRandomizer(), 3);
    }

    @Test
    public void generatedMapShouldNotBeEmpty() throws Exception {
        Map<String, String> names = mapRandomizer.getRandomValue();

        assertThat(names).isNotNull().hasSize(3);
    }

    @Test(expected = IllegalArgumentException.class)
    public void minElementsShouldBePositive() throws Exception {
        mapRandomizer = new MapRandomizer<String, String>(new FirstNameRandomizer(), new LastNameRandomizer(), -3);
    }

    @Test(expected = IllegalArgumentException.class)
    public void maxElementsShouldBeGreaterThanOrEqualToOne() throws Exception {
        mapRandomizer = new MapRandomizer<String, String>(new FirstNameRandomizer(), new LastNameRandomizer(), 0, 0);
    }

    @Test(expected = IllegalArgumentException.class)
    public void maxElementsShouldBeGreaterThanOrEqualToMinElements() throws Exception {
        mapRandomizer = new MapRandomizer<String, String>(new FirstNameRandomizer(), new LastNameRandomizer(), 2, 1);
    }

}

@@ -1246,16 +1246,66 @@
 izers;%0A%0A
+import io.github.benas.jpopulator.api.Randomizer;%0A
 import o
@@ -1366,16 +1366,41 @@
 til.Map;
+%0Aimport java.util.Random;
 %0A%0Aimport
@@ -1648,36 +1648,282 @@
 ate 
-MapRandomizer%3CString, String
+Randomizer%3CInteger%3E randomizer = new Randomizer%3CInteger%3E() %7B%0A        private Random random = new Random();%0A        @Override%0A        public Integer getRandomValue() %7B%0A            return random.nextInt(100000);%0A        %7D%0A    %7D;%0A    %0A    private MapRandomizer%3CInteger, Integer
 %3E ma
@@ -2037,64 +2037,39 @@
 zer%3C
-String, String%3E(new FirstNameRandomizer(), new LastNameR
+Integer, Integer%3E(randomizer, r
 ando
@@ -2073,18 +2073,16 @@
 ndomizer
-()
 , 3);%0A  
@@ -2174,30 +2174,32 @@
     Map%3C
-String, String
+Integer, Integer
 %3E names 
@@ -2454,64 +2454,39 @@
 zer%3C
-String, String%3E(new FirstNameRandomizer(), new LastNameR
+Integer, Integer%3E(randomizer, r
 ando
@@ -2490,18 +2490,16 @@
 ndomizer
-()
 , -3);%0A 
@@ -2683,64 +2683,39 @@
 zer%3C
-String, String%3E(new FirstNameRandomizer(), new LastNameR
+Integer, Integer%3E(randomizer, r
 ando
@@ -2719,18 +2719,16 @@
 ndomizer
-()
 , 0, 0);
@@ -2922,64 +2922,39 @@
 zer%3C
-String, String%3E(new FirstNameRandomizer(), new LastNameR
+Integer, Integer%3E(randomizer, r
 ando
@@ -2958,18 +2958,16 @@
 ndomizer
-()
 , 2, 1);

fix MapRandomizer test: use a large range of random values to avoid generating duplicate entries in the map (which makes the test fail)