Extract junit-5-configuration

This commit is contained in:
Kacper Koza
2019-04-25 09:12:44 +02:00
parent d6235c73e6
commit 81b323a695
5 changed files with 45 additions and 1 deletions
@@ -0,0 +1,42 @@
package com.baeldung.resourcedirectory;
import org.junit.Test;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ReadResourceDirectoryUnitTest {
@Test
public void shouldReadResourceAbsolutePathWithFile() {
String path = "src/test/resources";
File file = new File(path);
String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
}
@Test
public void shouldReadResourceAbsolutePathWithResources() {
String resourceName = "example_resource.txt";
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(resourceName).getFile());
String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
}
@Test
public void shouldReadResourceAbsolutePathWithPaths() {
Path resourceDirectory = Paths.get("src", "test", "resources");
String absolutePath = resourceDirectory.toFile().getAbsolutePath();
System.out.println(absolutePath);
}
}