/**
 * 
 */
package com.github.jsonldjava.utils;

import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.io.IOUtils;

/**
 * @author Peter Ansell p_ansell@yahoo.com
 * 
 */
public class TestUtils {

    public static InputStream copyResourceToFileStream(File testDir, String resource)
            throws Exception {
        return new FileInputStream(copyResourceToFile(testDir, resource));
    }

    public static String copyResourceToFile(File testDir, String resource) throws Exception {
        String filename = resource.substring(resource.lastIndexOf('/'));
        String directory = resource.substring(0, resource.lastIndexOf('/'));
        File nextDirectory = new File(testDir, directory);
        nextDirectory.mkdirs();
        File nextFile = new File(nextDirectory, filename);
        nextFile.createNewFile();

        InputStream inputStream = TestUtils.class.getResourceAsStream(resource);
        assertNotNull("Missing test resource: " + resource, inputStream);

        IOUtils.copy(inputStream, new FileOutputStream(nextFile));
        return nextFile.getAbsolutePath();
    }

    public static String join(Collection<String> list, String delim) {
        final StringBuilder builder = new StringBuilder();
        final Iterator<String> iter = list.iterator();
        while (iter.hasNext()) {
            builder.append(iter.next());
            if (!iter.hasNext()) {
                break;
            }
            builder.append(delim);
        }
        return builder.toString();
    }

    private TestUtils() {
    }

}

@@ -699,16 +699,118 @@
 lename =
+ resource;%0A        String directory = %22%22;%0A        if (resource.contains(%22/%22)) %7B%0A            filename =
  resourc
@@ -849,38 +849,35 @@
 ('/'));%0A        
-String
+   
  directory = res
@@ -915,32 +915,42 @@
 tIndexOf('/'));%0A
+        %7D%0A
         File nex

support case where url doesn't have a slash in it