package br.com.delogic.jnerator.util;

import java.util.Date;

import org.junit.Assert;
import org.junit.Test;

public class RandomUtilTest extends Assert {

    private double yearPeriod = 365.25 * 24 * 60 * 60 * 1000;

    @Test
    public void testGetDateBetween() {
        Date dayFrom = new Date((long) (System.currentTimeMillis() - yearPeriod));
        Date dayTo = new Date((long) (System.currentTimeMillis() + yearPeriod));

        for (int i = 0; i < 10000000; i++) {
            Date randomDate = RandomUtil.getDateBetween(2);
            assertTrue(randomDate.compareTo(dayFrom) > 0);
            assertTrue(randomDate.compareTo(dayTo) < 0);
        }

    }

    @Test
    public void testGetDateTo() {
        Date dayFrom = new Date((long) (System.currentTimeMillis() - yearPeriod));
        Date dayTo = new Date((long) (System.currentTimeMillis() + yearPeriod));

        for (int i = 0; i < 10000000; i++) {
            Date futureRandomDate = RandomUtil.getDateTo(1);
            assertTrue(futureRandomDate.compareTo(new Date()) > 0);
            if (!(futureRandomDate.compareTo(dayTo) < 0 )){
                System.out.println("Future date:" + futureRandomDate);
                System.out.println("DayTo:" + dayTo);
            }
            assertTrue(futureRandomDate.compareTo(dayTo) <= 0);

            Date pastRandomDate = RandomUtil.getDateTo(-1);
            assertTrue(pastRandomDate.compareTo(dayFrom) > 0);
            assertTrue(pastRandomDate.compareTo(new Date()) < 0);
        }

    }

}

@@ -222,51 +222,30 @@
     
-@Test%0A    public void testGetDateBetween
+private Date dayFrom
 ()
- 
 %7B%0A  
@@ -246,38 +246,30 @@
 ()%7B%0A        
-Date dayFrom =
+return
  new Date((l
@@ -313,36 +313,47 @@
 arPeriod));%0A    
+%7D%0A%0A
     
+private 
 Date dayTo = new
@@ -338,34 +338,50 @@
 ivate Date dayTo
- =
+()%7B%0A        return
  new Date((long)
@@ -417,32 +417,87 @@
 + yearPeriod));%0A
+    %7D%0A%0A    @Test%0A    public void testGetDateBetween() %7B
 %0A        for (in
@@ -629,32 +629,34 @@
 ompareTo(dayFrom
+()
 ) %3E 0);%0A        
@@ -692,24 +692,26 @@
 pareTo(dayTo
+()
 ) %3C 0);%0A    
@@ -772,173 +772,8 @@
 ) %7B%0A
-        Date dayFrom = new Date((long) (System.currentTimeMillis() - yearPeriod));%0A        Date dayTo = new Date((long) (System.currentTimeMillis() + yearPeriod));%0A%0A
     
@@ -946,207 +946,8 @@
 0);%0A
-            if (!(futureRandomDate.compareTo(dayTo) %3C 0 ))%7B%0A                System.out.println(%22Future date:%22 + futureRandomDate);%0A                System.out.println(%22DayTo:%22 + dayTo);%0A            %7D%0A
     
@@ -997,16 +997,18 @@
 To(dayTo
+()
 ) %3C= 0);
@@ -1124,16 +1124,18 @@
 (dayFrom
+()
 ) %3E 0);%0A

Fix random date generation