Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/291 cant resolve full path #294

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,20 @@
<groupId>com.pivovarit</groupId>
<artifactId>throwing-function</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 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();
// 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());
}

}