From a65e72e200c6b90d29a8902ec54ff3b5e607c42b Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Wed, 30 Nov 2022 11:07:21 +0100 Subject: [PATCH 1/2] Seems like it's time to add some serious testing ... --- base/pom.xml | 15 +++++++++++ .../aadarchi/base/utils/FileResolverTest.java | 25 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java diff --git a/base/pom.xml b/base/pom.xml index be93feb2..32f2b9a0 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -72,5 +72,20 @@ com.pivovarit throwing-function + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core + test + \ No newline at end of file diff --git a/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java b/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java new file mode 100644 index 00000000..8a4af60e --- /dev/null +++ b/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java @@ -0,0 +1,25 @@ +package org.ndx.aadarchi.base.utils; + +import java.io.File; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.assertj.core.api.Assertions; + +class FileResolverTest { + + @Test + void bug_291_absolute_path_cant_be_resolved() { + FileResolver resolver = new FileResolver(); + // Given + // This file resolves as project base execution dir + String userDir = System.getProperty("user.dir"); + File userFile = new File(userDir); + resolver.basedir = new File(userDir); + // When + Path resolved = resolver.fileAsUrltoPath(userDir); + // Then + Assertions.assertThat(resolved).isEqualTo(userFile.toPath()); + } + +} From 63b4af278cb773d4e7d5c13656752e09b69f91e6 Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Wed, 30 Nov 2022 11:09:53 +0100 Subject: [PATCH 2/2] Fixes #291 --- .../org/ndx/aadarchi/base/utils/FileResolver.java | 3 ++- .../ndx/aadarchi/base/utils/FileResolverTest.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java b/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java index 0e64e56a..418017c0 100644 --- a/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java +++ b/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java @@ -37,7 +37,8 @@ public Path fileAsUrltoPath(String file) { if (file.startsWith("file:")) { return Paths.get(new URL(file).toURI()); } else { - return new File(basedir, file).toPath(); + // Maybe the file should be resolved as a full path file + return basedir.toPath().resolve(file); } } catch (MalformedURLException | URISyntaxException e) { throw new UnableToResolveFileException(String.format("Unable to transform String %s into a file/path object", file), e); diff --git a/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java b/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java index 8a4af60e..dc5172bf 100644 --- a/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java +++ b/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java @@ -8,6 +8,19 @@ class FileResolverTest { + @Test + void can_resolve_subfolder() { + FileResolver resolver = new FileResolver(); + // Given + // This file resolves as project base execution dir + String userDir = System.getProperty("user.dir"); + File userFile = new File(userDir); + resolver.basedir = new File(userDir); + // When + Path resolved = resolver.fileAsUrltoPath("src/main/java"); + // Then + Assertions.assertThat(resolved).isEqualTo(new File(userFile, "src/main/java").toPath()); + } @Test void bug_291_absolute_path_cant_be_resolved() { FileResolver resolver = new FileResolver();