This commit is contained in:
Kacper Koza 2019-04-25 09:24:36 +02:00
parent 81b323a695
commit 068f4d1eb6
1 changed files with 15 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.baeldung.resourcedirectory;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
@ -9,17 +10,28 @@ import java.nio.file.Paths;
public class ReadResourceDirectoryUnitTest {
@Test
public void shouldReadResourceAbsolutePathWithFile() {
public void givenResourcePath_whenReadAbsolutePathWithFile_thenAbsolutePathEndsWithDirectory() {
String path = "src/test/resources";
File file = new File(path);
String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
Assert.assertTrue(absolutePath.endsWith("src/test/resources"));
}
@Test
public void shouldReadResourceAbsolutePathWithResources() {
public void givenResourcePath_whenReadAbsolutePathWithPaths_thenAbsolutePathEndsWithDirectory() {
Path resourceDirectory = Paths.get("src", "test", "resources");
String absolutePath = resourceDirectory.toFile().getAbsolutePath();
System.out.println(absolutePath);
Assert.assertTrue(absolutePath.endsWith("src/test/resources"));
}
@Test
public void givenResourceFile_whenReadResourceWithClassLoader_thenPathEndWithFilename() {
String resourceName = "example_resource.txt";
ClassLoader classLoader = getClass().getClassLoader();
@ -27,16 +39,7 @@ public class ReadResourceDirectoryUnitTest {
String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
Assert.assertTrue(absolutePath.endsWith("/example_resource.txt"));
}
@Test
public void shouldReadResourceAbsolutePathWithPaths() {
Path resourceDirectory = Paths.get("src", "test", "resources");
String absolutePath = resourceDirectory.toFile().getAbsolutePath();
System.out.println(absolutePath);
}
}