package org.jerkar.api.utils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import org.jerkar.api.utils.JkUtilsFile;
import org.junit.Test;

public class JkUtilsFileTest {

    @Test
    public void testFileOf() throws Exception {
        final URL sampleFileUrl = JkUtilsFileTest.class
                .getResource("samplefolder/subfolder/sample.txt");
        final File sampleFile = new File(sampleFileUrl.toURI().getPath());
        assertTrue(sampleFile.exists());
        final File sampleDir = sampleFile.getParentFile().getParentFile();

        List<File> files = JkUtilsFile.filesOf(sampleDir, false);
        assertEquals(1, files.size());

        files = JkUtilsFile.filesOf(sampleDir, true);
        assertEquals(2, files.size());

        final FileFilter fileFilter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return !pathname.getName().equals("sample.txt");
            }
        };

        files = JkUtilsFile.filesOf(sampleDir, fileFilter, false);
        assertEquals(0, files.size());

        files = JkUtilsFile.filesOf(sampleDir, fileFilter, true);
        assertEquals(1, files.size());
    }

    @Test
    public void testRelativePath() throws IOException {
        final File base = new File("C:\\my\\root\\folder");
        final File file1 = new File("C:\\my\\root\\folder\\foo\\bar.txt");
        final File file2 = new File("C:\\my\\root\\foo\\bar.txt");
        assertEquals("foo\\bar.txt", JkUtilsFile.getRelativePath(base, file1));
        assertEquals("..\\foo\\bar.txt", JkUtilsFile.getRelativePath(base, file2));
    }

}

@@ -261,62 +261,52 @@
 rg.j
-erkar.api.utils.JkUtilsFile;%0D%0Aimport org.junit.Test;%0D%0A
+unit.Test;%0D%0A%0D%0A%0D%0A@SuppressWarnings(%22javadoc%22)
 %0D%0Apu
@@ -1482,36 +1482,33 @@
 new File(%22C:
-%5C%5Cmy%5C%5C
+/my/
 root
-%5C%5C
+/
 folder%22);%0D%0A 
@@ -1549,33 +1549,28 @@
 (%22C:
-%5C%5Cmy%5C%5C
+/my/
 root
-%5C%5C
+/
 folder
-%5C%5Cfoo%5C%5C
+/foo/
 bar.
@@ -1620,25 +1620,21 @@
 (%22C:
-%5C%5Cmy%5C%5C
+/my/
 root
-%5C%5Cfoo%5C%5C
+/foo/
 bar.
@@ -1666,18 +1666,38 @@
 als(%22foo
-%5C%5C
+%22 + File.separator + %22
 bar.txt%22
@@ -1770,15 +1770,55 @@
 (%22..
-%5C%5Cfoo%5C%5C
+%22 + File.separator + %22foo%22 + File.separator + %22
 bar.

fix test UNIX