Skip to content

Commit 7ed563c

Browse files
codebrewertommysitu
authored andcommitted
Generate Windows-friendly absolute paths from classpath resource URLs
1 parent 218bbb9 commit 7ed563c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/io/specto/hoverfly/junit/core/config/HoverflyConfigValidator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.net.URI;
1111
import java.net.URISyntaxException;
1212
import java.net.URL;
13+
import java.nio.file.Path;
1314
import java.util.Optional;
1415

1516

@@ -116,6 +117,14 @@ private void checkResourceOnClasspath(String resourceName) {
116117
private Optional<String> getTestResourcesFolderPath(String relativePath) {
117118
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
118119
URL url = classLoader.getResource(relativePath);
119-
return Optional.ofNullable(url).map(URL::getPath);
120+
return Optional.ofNullable(url).map(this::toPath);
121+
}
122+
123+
private String toPath(URL url) {
124+
try {
125+
return Path.of(url.toURI()).toString();
126+
} catch (URISyntaxException e) {
127+
return null;
128+
}
120129
}
121130
}

0 commit comments

Comments
 (0)