package com.hpe.caf.worker.testing.execution;

import com.hpe.caf.worker.testing.TestControllerSingle;
import com.hpe.caf.worker.testing.TestItem;
import com.hpe.caf.worker.testing.TestItemProvider;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by oloughli on 27/05/2016.
 */
public class TestRunnerSingle {
    private static TestItemProvider itemProvider;
    private static boolean mode;

    public static Set<Object[]> setUpTest(TestControllerProvider controllerProvider) throws Exception{
        Collection<TestItem> items = getItemProvider(controllerProvider,mode).getItems();
        Set<Object[]> s=new HashSet<Object[]>();
        for (TestItem i: items) {
            s.add(new Object[]{i});

            if(i.getInputIdentifier() == null)
                i.setInputIdentifier(i.getTag());
        }
        return s;
    }

    public static TestControllerSingle getTestController(TestControllerProvider controllerProvider, boolean dataGenerationMode) throws Exception {
        mode = dataGenerationMode;
        TestControllerSingle controller = dataGenerationMode? controllerProvider.getNewDataPreparationController() : controllerProvider.getNewTestController();
        return controller;
    }

    public static TestItemProvider getItemProvider(TestControllerProvider controllerProvider, boolean typeOfItemProvider)
    {
        itemProvider = controllerProvider.getItemProvider(typeOfItemProvider);
        return itemProvider;
    }

    public static TestItemProvider getItemProvider()
    {
        return itemProvider;
    }
}

@@ -590,16 +590,58 @@
  items =
+ null;%0D%0A        try %7B%0D%0A            items =
  getItem
@@ -683,24 +683,258 @@
 etItems();%0D%0A
+        %7D%0D%0A        catch (NumberFormatException e)%0D%0A        %7B%0D%0A            e.printStackTrace();%0D%0A            if (e.getCause() != null)%7B%0D%0A                e.getCause().printStackTrace();%0D%0A            %7D%0D%0A            throw e;%0D%0A        %7D%0D%0A
         Set%3C
@@ -945,16 +945,17 @@
 ct%5B%5D%3E s=
+ 
 new Hash
@@ -958,24 +958,16 @@
 HashSet%3C
-Object%5B%5D
 %3E();%0D%0A  

Update TestRunnerSingle to catch NumberFormatException