From 12631714658e43f7e4b79ffd3765ed199251f390 Mon Sep 17 00:00:00 2001 From: Kacper Koza Date: Thu, 18 Apr 2019 22:21:35 +0200 Subject: [PATCH] read src/test/resources --- .../ReadResourceDirectoryTest.java | 42 +++++++++++++++++++ .../src/test/resources/example_resource.txt | 0 2 files changed, 42 insertions(+) create mode 100644 testing-modules/junit-5/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryTest.java create mode 100644 testing-modules/junit-5/src/test/resources/example_resource.txt diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryTest.java new file mode 100644 index 0000000000..20951dc7eb --- /dev/null +++ b/testing-modules/junit-5/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryTest.java @@ -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 ReadResourceDirectoryTest { + + @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); + } + + +} diff --git a/testing-modules/junit-5/src/test/resources/example_resource.txt b/testing-modules/junit-5/src/test/resources/example_resource.txt new file mode 100644 index 0000000000..e69de29bb2