From cd4167c4625771a66590fd280adfbe738a3f0f64 Mon Sep 17 00:00:00 2001 From: tienvn Date: Sat, 8 Jul 2023 00:39:27 +0700 Subject: [PATCH] add unit test --- .../RelativePathConverterUnitTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 core-java-modules/core-java-20/src/test/java/com/baeldung/convertpaths/RelativePathConverterUnitTest.java diff --git a/core-java-modules/core-java-20/src/test/java/com/baeldung/convertpaths/RelativePathConverterUnitTest.java b/core-java-modules/core-java-20/src/test/java/com/baeldung/convertpaths/RelativePathConverterUnitTest.java new file mode 100644 index 0000000000..1573611697 --- /dev/null +++ b/core-java-modules/core-java-20/src/test/java/com/baeldung/convertpaths/RelativePathConverterUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.convertpaths; + +import org.junit.Test; + +public class RelativePathConverterUnitTest { + + @Test + public void testConvertToAbsolutePath() { + String relativePath = "data/sample.txt"; + System.out.println(RelativePathConverter.convertToAbsoluteUsePathsClass(relativePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileClass(relativePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileSystemsClass(relativePath)); + } + + @Test + public void testConvertToAbsolutePath_withAbsolutePath() { + String absolutePath = "/var/www/index.html"; + System.out.println(RelativePathConverter.convertToAbsoluteUsePathsClass(absolutePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileClass(absolutePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileSystemsClass(absolutePath)); + } + + @Test + public void testConvertToAbsolutePath_withEmptyPath() { + String emptyPath = ""; + System.out.println(RelativePathConverter.convertToAbsoluteUsePathsClass(emptyPath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileClass(emptyPath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileSystemsClass(emptyPath)); + } + + @Test + public void testConvertToAbsolutePath_withParentDirectory() { + String relativePath = "../data/sample.txt"; + System.out.println(RelativePathConverter.convertToAbsoluteUsePathsClass(relativePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileClass(relativePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileSystemsClass(relativePath)); + } + + @Test + public void testConvertToAbsolutePath_withRelativePathContainingDots() { + String relativePath = "././data/sample.txt"; + System.out.println(RelativePathConverter.convertToAbsoluteUsePathsClass(relativePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileClass(relativePath)); + System.out.println(RelativePathConverter.convertToAbsoluteUseFileSystemsClass(relativePath)); + } +}