package ee.shy.core.diff;

import ee.shy.ResourcePaths;
import ee.shy.core.Tree;
import ee.shy.storage.DataStorage;
import ee.shy.storage.MapStorage;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.FromDataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeNotNull;

@RunWith(Theories.class)
public class TreeDifferTest {
    @Rule
    public ResourcePaths resourcePaths = new ResourcePaths(TreeDifferTest.class);

    private DataStorage storage;
    private TreeDiffer treeDiffer;

    @DataPoints("trees")
    public static String[] listTrees() throws URISyntaxException, IOException {
        return Files.list(ResourcePaths.getPath(TreeDifferTest.class, "")).filter(path -> Files.isDirectory(path)).map(path -> path.getFileName().toString()).toArray(String[]::new);
    }

    @Before
    public void setUp() throws Exception {
        storage = new MapStorage();
        treeDiffer = new TreeDiffer(storage);
    }

    @Theory
    public void testDiff(
            @FromDataPoints("trees") String original,
            @FromDataPoints("trees") String revised
    ) throws Exception {
        System.out.println(original + "-" + revised);
        List<String> expectedLines;
        if (original.equals(revised)) {
            expectedLines = Collections.emptyList();
        }
        else {
            InputStream expectedStream = getClass().getResourceAsStream(original + "-" + revised);
            assumeNotNull(expectedStream);
            expectedLines = IOUtils.readLines(expectedStream);
        }

        Tree originalTree = new Tree.Builder(storage).fromDirectory(resourcePaths.get(original)).create();
        Tree revisedTree = new Tree.Builder(storage).fromDirectory(resourcePaths.get(revised)).create();
        List<String> actualLines = treeDiffer.diff(originalTree, revisedTree);

        assertEquals(expectedLines, actualLines);
    }
}
@@ -223,16 +223,21 @@
 g.junit.
+Class
 Rule;%0Aim
@@ -255,224 +255,85 @@
 nit.
-experimental.theories.DataPoints;%0Aimport org.junit.experimental.theories.FromDataPoints;%0Aimport org.junit.experimental.theories.Theories;%0Aimport org.junit.experimental.theories.Theory;%0Aimport org.junit.runner.RunWith
+Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized
 ;%0A%0Ai
@@ -451,16 +451,73 @@
 .Files;%0A
+import java.util.ArrayList;%0Aimport java.util.Collection;%0A
 import j
@@ -657,26 +657,89 @@
 ll;%0A
-%0A@RunWith(Theories
+import static org.junit.runners.Parameterized.Parameters;%0A%0A@RunWith(Parameterized
 .cla
@@ -777,16 +777,21 @@
  %7B%0A    @
+Class
 Rule%0A   
@@ -798,16 +798,23 @@
  public 
+static 
 Resource
@@ -885,133 +885,86 @@
     
-private DataStorage storage;%0A    private TreeDiffer treeDiffer;%0A%0A    @DataPoints(%22trees%22)%0A    public static String%5B%5D listTree
+@Parameters(name = %22%7B0%7D-%7B1%7D%22)%0A    public static Collection%3CObject%5B%5D%3E parameter
 s() 
@@ -970,25 +970,18 @@
  throws 
-URISyntax
+IO
 Exceptio
@@ -983,18 +983,25 @@
 eption, 
-IO
+URISyntax
 Exceptio
@@ -1016,14 +1016,228 @@
     
-return
+/*%0A            Cannot use ClassRule in Parameters due to:%0A            - https://github.com/junit-team/junit4/issues/671,%0A            - https://github.com/junit-team/junit4/issues/527.%0A         */%0A        String%5B%5D trees =
  Fil
@@ -1292,16 +1292,33 @@
 ss, %22%22))
+%0A                
 .filter(
@@ -1349,16 +1349,33 @@
 y(path))
+%0A                
 .map(pat
@@ -1409,16 +1409,33 @@
 tring())
+%0A                
 .toArray
@@ -1455,302 +1455,534 @@
 w);%0A
+%0A
     
-%7D%0A%0A
     
-@Before%0A    public void setUp() throws Exception %7B%0A        storage = new MapStorage();%0A        treeDiffer = new TreeDiffer(storage);%0A    %7D%0A%0A    @Theory%0A    public void testDiff(%0A            @FromDataPoints(%22trees%22) String original,%0A            @FromDataPoints(%22trees%22) String
+List%3CObject%5B%5D%3E parameters = new ArrayList%3C%3E();%0A        for (String original : trees) %7B%0A            for (String revised : trees) %7B%0A                parameters.add(new Object%5B%5D%7Boriginal, revised%7D);%0A            %7D%0A        %7D%0A        return parameters;%0A    %7D%0A%0A    private DataStorage storage;%0A    private TreeDiffer treeDiffer;%0A%0A    private final String original;%0A    private final String revised;%0A%0A    public TreeDifferTest(String original, String revised) %7B%0A        this.original = original;%0A        this.revised =
  revised
 %0A   
@@ -1981,87 +1981,216 @@
 ised
+;
 %0A    
-) throws Exception %7B%0A        System.out.println(original + %22-%22 + revised);
+%7D%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        storage = new MapStorage();%0A        treeDiffer = new TreeDiffer(storage);%0A    %7D%0A%0A    @Test%0A    public void testDiff() throws Exception %7B
 %0A   

Replace Theory runner with Parametrized runner for TreeDIfferTest