package com.huskycode.jpaquery.util;

import org.junit.Test;

import java.util.Random;

import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;


/** */
public class RandomizerTest {

    private Random any = new Random();
    private static final int MAX_LENGTH = 100;
    
    @Test
    public void testGetString() {
        int length = Math.abs(any.nextInt(MAX_LENGTH));
        String expected = Randomizer.getString(length);

        assertThat(expected,instanceOf(String.class));
        assertThat(expected.length(), equalTo(length));

        length = 0;
        String expect = "";
        assertEquals(Randomizer.getString(length), expect);
    }

    @Test
    public void testGetAsciiString() {
        int length = Math.abs(any.nextInt(MAX_LENGTH));
        String actual = Randomizer.getAsciiString(length);

        assertThat(actual,instanceOf(String.class));
        assertThat(actual.length(), equalTo(length));

        length = 0;
        String expect = "";
        assertEquals(Randomizer.getAsciiString(length), expect);
    }

    @Test
    public void testGetInt() {
        assertThat(Randomizer.getInt(),instanceOf(Integer.class));
    }

    @Test
    public void testGetNonNegativeInt() {
        int actual = Randomizer.getNonNegativeInt();
        assertThat(actual,instanceOf(Integer.class));
        assertTrue(actual >= 0);
    }

    @Test
    public void testGetLong() {
        assertThat(Randomizer.getLong(),instanceOf(Long.class));
    }

    @Test
    public void testGetNonNegativeLong() {
        long actual = Randomizer.getNonNegativeLong();
        assertThat(actual,instanceOf(Long.class));
        assertTrue(actual >= 0);
    }

    @Test
    public void testGetDouble() {
        assertThat(Randomizer.getDouble(),instanceOf(Double.class));
    }

    @Test
    public void testGetBoolean() {
        assertThat(Randomizer.getBoolean(),instanceOf(Boolean.class));
    }
}

@@ -80,201 +80,109 @@
 til.
-Random;%0D%0A%0D%0Aimport static org.hamcrest.Matchers.instanceOf;%0D%0Aimport static org.hamcrest.Matchers.equalTo;%0D%0Aimport static org.junit.Assert.assertEquals;%0D%0Aimport static org.junit.Assert.assertThat
+ArrayList;%0D%0Aimport java.util.List;%0D%0Aimport java.util.Random;%0D%0A%0D%0Aimport static org.hamcrest.Matchers.*
 ;%0D%0Ai
@@ -211,26 +211,17 @@
 .Assert.
-assertTrue
+*
 ;%0D%0A%0D%0A%0D%0A/
@@ -2058,12 +2058,628 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    @Test%0D%0A    public void testGetRandomFromArray() %7B%0D%0A        Integer%5B%5D data = %7Bany.nextInt(), any.nextInt(), any.nextInt(), any.nextInt()%7D;%0D%0A        %0D%0A        int selectData =  Randomizer.getRandomFromArray(data);%0D%0A        %0D%0A        assertThat(selectData, isIn(data));%0D%0A    %7D%0D%0A%0D%0A%0D%0A    @Test%0D%0A    public void testGetRandomFromList() %7B%0D%0A        List%3CInteger%3E data = new ArrayList%3CInteger%3E();%0D%0A        data.add(any.nextInt());%0D%0A        data.add(any.nextInt());%0D%0A        data.add(any.nextInt());%0D%0A%0D%0A        int selectData =  Randomizer.getRandomFromList(data);%0D%0A%0D%0A        assertThat(selectData, isIn(data));%0D%0A    %7D%0D
 %0A%7D%0D%0A

add test for getRandomFromList and Array