Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gurpreet- committed Aug 30, 2019
1 parent 318b131 commit e5a8484
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
ext {
artifactId = "resource-loader"
groupId = "co.libly"
version = '1.2.2'
version = '1.2.3'
description = "Resource Loader gives you the functions to load resource files inside or outside JARs."
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/co/libly/resourceloader/FileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static FileLoader get() {
* @return The file your directory.
* @throws IOException
*/
public File load(String relativePath, Class aClass) throws IOException {
return load(relativePath, new HashSet<>(), aClass);
public File load(String relativePath) throws IOException {
return load(relativePath, new HashSet<>());
}

/**
Expand All @@ -49,12 +49,12 @@ public File load(String relativePath, Class aClass) throws IOException {
* @return The file your directory.
* @throws IOException
*/
public File load(String relativePath, Set<PosixFilePermission> permissions, Class aClass) throws IOException {
return loadFromRelativePath(relativePath, permissions, aClass);
public File load(String relativePath, Set<PosixFilePermission> permissions) throws IOException {
return loadFromRelativePath(relativePath, permissions);
}

private File loadFromRelativePath(String relativePath, Set<PosixFilePermission> filePermissions, Class aClass) throws IOException {
File file = copyToTempDirectory(relativePath, aClass);
private File loadFromRelativePath(String relativePath, Set<PosixFilePermission> filePermissions) throws IOException {
File file = copyToTempDirectory(relativePath);
setPermissions(file, filePermissions);
return file;
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/co/libly/resourceloader/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ public class ResourceLoader {
* if it is in a JAR or not.
* @param relativePath A relative path to a file or directory
* relative to the resources folder.
* @param aClass
* @return The file or directory you want to load.
* @throws IOException
*/
public File copyToTempDirectory(String relativePath, Class aClass) throws IOException {
public File copyToTempDirectory(String relativePath) throws IOException {
// If the file does not start with a separator,
// then let's make sure it does!
if (!relativePath.startsWith(File.separator)) {
Expand All @@ -69,7 +68,7 @@ public File copyToTempDirectory(String relativePath, Class aClass) throws IOExce
mainTempDir.mkdirs();

try {
URL jarUrl = getThisJarPath(aClass);
URL jarUrl = getThisJarPath();
// Is the user loading this in a JAR?
if (jarUrl.toString().endsWith(".jar")) {
// If so the get the file/directory
Expand Down Expand Up @@ -363,9 +362,8 @@ protected boolean isPosixCompliant() {
* If we're in a JAR, we can get our path
* using this method.
* @return URL of this JAR.
* @param aClass
*/
public URL getThisJarPath(Class aClass) {
return aClass.getProtectionDomain().getCodeSource().getLocation();
public URL getThisJarPath() {
return getClass().getProtectionDomain().getCodeSource().getLocation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public File load(String relativePath, Class clzz) {
public File load(String relativePath, List<Class> classes) {
synchronized (lock) {
try {
File library = copyToTempDirectory(relativePath, classes.get(0));
File library = copyToTempDirectory(relativePath);
setPermissions(library);
if (library.isDirectory()) {
throw new IOException("Please supply a relative path to a file and not a directory.");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/co/libly/resourceloader/FileLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public void loadLoader() {

@Test
public void loadFile() throws IOException {
File file = fileLoader.load("test1.txt", FileLoaderTest.class);
File file = fileLoader.load("test1.txt");
assertThat(file)
.as("Load a file")
.isNotNull();
}

@Test
public void loadFileCheckContents() throws IOException {
File file = fileLoader.load("test1.txt", FileLoaderTest.class);
File file = fileLoader.load("test1.txt");

assertThat(file)
.as("Load a file testing the content")
Expand All @@ -45,7 +45,7 @@ public void loadFileCheckContents() throws IOException {

@Test
public void loadWholeFolders() throws IOException {
File file = fileLoader.load("folder2", FileLoaderTest.class);
File file = fileLoader.load("folder2");

assertThat(file)
.as("Load a directory with children")
Expand Down

0 comments on commit e5a8484

Please sign in to comment.