package com.wizzardo.http.framework.template;

import com.wizzardo.tools.io.FileTools;
import com.wizzardo.tools.io.IOTools;
import org.junit.Assert;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by wizzardo on 14/11/16.
 */
public class LocalResourcesToolsTest {

    @Test
    public void test_getResource() throws IOException {
        LocalResourcesTools resources = new LocalResourcesTools();

        Assert.assertEquals("foo", resources.getResourceAsString("test_resource"));

        Assert.assertEquals("foo", resources.getResourceAsString("/test_resource"));
    }

    @Test
    public void test_getResource_2() throws IOException {
        LocalResourcesTools resources = new LocalResourcesTools();

        FileTools.text("/tmp/test_resource", "foo");

        Assert.assertEquals("foo", resources.getResourceAsString("/tmp/test_resource"));

        try {
            resources.getResource("/tmp/test_resource_2");
            Assert.assertTrue(false);
        } catch (FileNotFoundException e) {
            Assert.assertEquals("file /tmp/test_resource_2 not found", e.getMessage());
        }
    }
}
@@ -167,16 +167,37 @@
 .Test;%0A%0A
+import java.io.File;%0A
 import j
@@ -218,32 +218,32 @@
 FoundException;%0A
-
 import java.io.I
@@ -281,16 +281,66 @@
 tStream;
+%0Aimport java.util.concurrent.atomic.AtomicInteger;
 %0A%0A/**%0A *
@@ -1247,24 +1247,24 @@
 Message());%0A
-
         %7D%0A  
@@ -1266,10 +1266,1326 @@
  %7D%0A    %7D
+%0A%0A    @Test%0A    public void test_getResourceFile() throws IOException %7B%0A        LocalResourcesTools resources = new LocalResourcesTools();%0A%0A        FileTools.text(%22/tmp/test_resource%22, %22foo%22);%0A        AtomicInteger counter = new AtomicInteger();%0A        resources.getResourceFile(%22/tmp/test_resource%22, file -%3E %7B%0A            Assert.assertEquals(%22foo%22, FileTools.text(file));%0A            counter.incrementAndGet();%0A        %7D);%0A        Assert.assertEquals(1, counter.get());%0A%0A%0A        resources.getResourceFile(%22/tmp/test_resource_not_exists%22, file -%3E %7B%0A            Assert.assertEquals(%22foo%22, FileTools.text(file));%0A            counter.incrementAndGet();%0A        %7D);%0A        Assert.assertEquals(1, counter.get());%0A    %7D%0A%0A    @Test%0A    public void test_getResourceFile_2() throws IOException %7B%0A        LocalResourcesTools resources = new LocalResourcesTools();%0A%0A        Assert.assertEquals(%22foo%22, FileTools.text(resources.getResourceFile(%22test_resource%22)));%0A    %7D%0A%0A    @Test%0A    public void test_getResourceFile_3() throws IOException %7B%0A        LocalResourcesTools resources = new LocalResourcesTools();%0A        resources.addResourcesDir(new File(%22/tmp%22));%0A%0A        FileTools.text(%22/tmp/test_resource_foo%22, %22foo%22);%0A        Assert.assertEquals(%22foo%22, FileTools.text(resources.getResourceFile(%22test_resource_foo%22)));%0A    %7D
 %0A%7D

improve tests