package com.noveogroup.android.task;

import org.junit.Test;

import java.util.concurrent.Executors;

public class TaskTest {

    private TaskExecutor createTaskExecutor() {
        return new SimpleTaskExecutor(Executors.newFixedThreadPool(3)) {
            @Override
            protected TaskEnvironment createTaskEnvironment(TaskHandler taskHandler) {
                return new SimpleTaskEnvironment(taskHandler);
            }
        };
    }

    @Test
    public void runTest() throws InterruptedException {
        final Helper helper = new Helper();

        TaskExecutor executor = createTaskExecutor();
        executor.execute(new Task() {
            @Override
            public Object run(Object input, TaskEnvironment env) throws Throwable {
                helper.append("Task::run");
                return null;
            }
        });
        Thread.sleep(Utils.DT);

        helper.check("Task::run");
    }

}

@@ -242,180 +242,465 @@
 (3))
- %7B
+;
 %0A    
+%7D%0A%0A
     
-    @Override%0A            protected TaskEnvironment createTaskEnvironment(TaskHandler taskHandler) %7B%0A                return new SimpleTaskEnvironment(taskHandler
+@Test%0A    public void runTest() throws InterruptedException %7B%0A        final Helper helper = new Helper();%0A%0A        TaskExecutor executor = createTaskExecutor();%0A%0A        executor.addTaskListener(new TaskListener.Default%3CObject, Object%3E() %7B%0A            @Override%0A            public void onStart(TaskHandler%3CObject, Object%3E handler) %7B%0A                helper.append(%22%5BTaskListener::onStart%7B%25d,%25s%7D%5D%22, handler.args().input(), handler.args().output()
 );%0A 
@@ -712,24 +712,25 @@
       %7D%0A
+%0A
         
 %7D;%0A    %7D
@@ -725,137 +725,217 @@
     
-%7D;%0A
     
-%7D%0A%0A    @Test%0A    public void runTest() throws InterruptedException %7B%0A        final Helper helper = new Helper(
+@Override%0A            public void onFinish(TaskHandler%3CObject, Object%3E handler) %7B%0A                helper.append(%22%5BTaskListener::onFinish%7B%25d,%25s%7D%5D%22, handler.args().input(), handler.args().output()
 );%0A
-%0A
         
 Task
@@ -934,54 +934,27 @@
     
-TaskExecutor executor = createTaskExecutor(
+    %7D%0A        %7D
 );%0A
+%0A
     
@@ -982,16 +982,33 @@
 new Task
+%3CInteger, String%3E
 () %7B%0A   
@@ -1049,25 +1049,26 @@
 lic 
-Object run(Object
+String run(Integer
  inp
@@ -1086,16 +1086,33 @@
 ironment
+%3CInteger, String%3E
  env) th
@@ -1159,16 +1159,17 @@
 append(%22
+%5B
 Task::ru
@@ -1161,32 +1161,33 @@
 pend(%22%5BTask::run
+%5D
 %22);%0A            
@@ -1201,12 +1201,542 @@
 urn 
-null
+String.valueOf(input);%0A            %7D%0A        %7D, 100, new TaskListener.Default%3CInteger, String%3E() %7B%0A            @Override%0A            public void onCreate(TaskHandler%3CInteger, String%3E handler) %7B%0A                helper.append(%22%5BTaskListener::onCreate%7B%25d,%25s%7D%5D%22, handler.args().input(), handler.args().output());%0A            %7D%0A%0A            @Override%0A            public void onDestroy(TaskHandler%3CInteger, String%3E handler) %7B%0A                helper.append(%22%5BTaskListener::onDestroy%7B%25d,%25s%7D%5D%22, handler.args().input(), handler.args().output())
 ;%0A  
@@ -1814,25 +1814,161 @@
 .check(%22
+%5B
 Task
-::run
+Listener::onCreate%7B100,null%7D%5D%5BTaskListener::onStart%7B100,null%7D%5D%5BTask::run%5D%5BTaskListener::onFinish%7B100,100%7D%5D%5BTaskListener::onDestroy%7B100,100%7D%5D
 %22);%0A    

improve test