package me.alb_i986.selenium.tinafw.tasks;

import org.junit.Test;

import me.alb_i986.selenium.tinafw.ui.WebPage;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

public class WebTasksTest {
	
	/**
	 * Given an initial page,
	 * When sleepFor 3 seconds,
	 * Then the method should return after 3 seconds (let's say between 3 and 4 seconds),
	 * And the returned page is the same object as the one passed.
	 */
	@Test
	public void sleepFor() {
		WebPage initialPage = new WebPage() {
			
			@Override
			public String getTitle() {
				return "title";
			}
			
			@Override
			public String getCurrentUrl() {
				return "current url";
			}
		};
		long startTimeMillis = System.currentTimeMillis();
		WebPage finalPage = WebTasks.sleepFor(3).run(initialPage);
		long endTimeMillis = System.currentTimeMillis();
		assertThat(endTimeMillis - startTimeMillis,
				allOf(
					greaterThanOrEqualTo(3000L),
					lessThanOrEqualTo(4000l)
				)
		);
		assertSame(initialPage, finalPage);
	}
}

@@ -37,16 +37,41 @@
 tasks;%0A%0A
+import org.junit.Before;%0A
 import o
@@ -133,17 +133,16 @@
 ebPage;%0A
-%0A
 import s
@@ -239,165 +239,400 @@
 t %7B%0A
-%09
 %0A%09
-/**%0A%09 * Given an initial page,%0A%09 * When sleepFor 3 seconds,%0A%09 * Then the method should r
+private WebPage stubPage;%0A%09%0A%09@Before%0A%09public void before() %7B%0A%09%09stubPage = new WebPage() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public String getTitle() %7B%0A%09%09%09%09return %22title%22;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public String g
 et
+C
 ur
-n after 3 seconds (let's say between 3 and 4 seconds)
+rentUrl() %7B%0A%09%09%09%09return %22current url%22;%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%09%0A%0A%09/**%0A%09 * Testing %7B@link WebTasks#nullTask()%7D.%0A%09 * %3Cp%3E%0A%09 * Given an initial page,%0A%09 * When %7B@link WebTasks#nullTask()%7D is run
 ,%0A%09 * 
-And
+Then
  the
@@ -646,18 +646,25 @@
 ed page 
-i
 s
+hould be
  the sam
@@ -669,32 +669,27 @@
 ame 
-object as the one passed
+as the initial page
 .%0A%09 
@@ -711,24 +711,24 @@
 ic void 
-sleepFor
+nullTask
 () %7B%0A%09%09W
@@ -734,21 +734,19 @@
 WebPage 
+f
 in
-iti
 alPage =
@@ -750,183 +750,386 @@
 e = 
-new WebPage() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public String getTitle() %7B%0A%09%09%09%09return %22title%22;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public String g
+WebTasks.nullTask().run(stubPage);%0A%09%09assertSame(stubPage, finalPage);%0A%09%7D%0A%09%0A%09/**%0A%09 * Testing %7B@link WebTasks#sleepFor(int)%7D.%0A%09 * %3Cp%3E%0A%09 * Given an initial page,%0A%09 * When sleepFor 2 seconds,%0A%09 * Then the method should r
 et
-C
 ur
-rentUrl() %7B%0A%09%09%09%09return %22current url%22;%0A%09%09%09%7D%0A%09%09%7D;
+n after 2 seconds (let's say between 1 and 3 seconds),%0A%09 * And the returned page should be the same as the initial page.%0A%09 */%0A%09@Test%0A%09public void sleepFor() %7B
 %0A%09%09l
@@ -1222,22 +1222,19 @@
 For(
-3
+2
 ).run(
-initial
+stub
 Page
@@ -1370,17 +1370,17 @@
 EqualTo(
-3
+1
 000L),%0A%09
@@ -1405,13 +1405,13 @@
 lTo(
-4000l
+3000L
 )%0A%09%09
@@ -1432,23 +1432,20 @@
 ertSame(
-initial
+stub
 Page, fi

update WebTasksTest: refactor + add test for #nullTask