Merge pull request #6757 from kacperkoza/master

read src/test/resources
This commit is contained in:
Loredana Crusoveanu 2019-04-29 11:02:07 +03:00 committed by GitHub
commit f69d930e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,2 @@
### Relevant Articles:
-

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>junit-5-configuration</artifactId>
<version>1.0-SNAPSHOT</version>
<name>junit-5-configuration</name>
<description>Intro to JUnit 5 configuration</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<properties>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
<junit.platform.version>1.2.0</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
</properties>
</project>

View File

@ -0,0 +1,45 @@
package com.baeldung.resourcedirectory;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ReadResourceDirectoryUnitTest {
@Test
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 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();
File file = new File(classLoader.getResource(resourceName).getFile());
String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
Assert.assertTrue(absolutePath.endsWith("/example_resource.txt"));
}
}

View File

@ -32,5 +32,6 @@
<module>test-containers</module>
<module>testing</module>
<module>testng</module>
<module>junit-5-configuration</module>
</modules>
</project>