diff options
Diffstat (limited to 'src/test/java/org/javacs/FindResource.java')
-rw-r--r-- | src/test/java/org/javacs/FindResource.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/java/org/javacs/FindResource.java b/src/test/java/org/javacs/FindResource.java new file mode 100644 index 0000000..355223a --- /dev/null +++ b/src/test/java/org/javacs/FindResource.java @@ -0,0 +1,24 @@ +package org.javacs; + +import java.io.File; +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Represents a java source on the system resource path. + */ +public class FindResource { + public static URI uri(String resourcePath) { + if (resourcePath.startsWith("/")) + resourcePath = resourcePath.substring(1); + + Path path = Paths.get("./src/test/resources").resolve(resourcePath).normalize(); + File file = path.toFile(); + + if (!file.exists()) + throw new RuntimeException(file + " does not exist"); + + return file.toURI(); + } +} |