Add failing test for #3705

This commit is contained in:
Winston Li
2017-08-02 20:51:20 +01:00
parent 8e15d63a2f
commit ad687e5f58
5 changed files with 98 additions and 19 deletions

View File

@@ -0,0 +1,11 @@
package uk.ac.ic.wlgitbridge.util;
/**
* BiConsumer interface that allows checked exceptions.
*/
@FunctionalInterface
public interface BiConsumerT<T, U, E extends Throwable> {
void accept(T t, U u) throws E;
}

View File

@@ -0,0 +1,14 @@
package uk.ac.ic.wlgitbridge.util;
/**
* Function interface that allows checked exceptions.
* @param <T>
* @param <R>
* @param <E>
*/
@FunctionalInterface
public interface FunctionT<T, R, E extends Throwable> {
R apply(T t) throws E;
}

View File

@@ -0,0 +1,32 @@
package uk.ac.ic.wlgitbridge.util;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class ResourceUtil {
/**
* Creates a copy of a resource folder. Mainly used for testing to prevent
* the original folder from being mangled.
*
* It will have the same name as the original.
* @param resource the resource name, e.g. "/uk/ac/ic/wlgitbridge/file.txt"
* @param folderProvider function used to create the folder.
* E.g. TemporaryFolder from junit
* @return
* @throws IOException
*/
public static File copyOfFolderResource(
String resource,
FunctionT<String, File, IOException> folderProvider
) throws IOException {
File original
= new File(ResourceUtil.class.getResource(resource).getFile());
File tmp = folderProvider.apply(original.getName());
FileUtils.copyDirectory(original, tmp);
return tmp;
}
}