Skip to content

Commit

Permalink
Try to fix NestedFileSystemProviderTests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Oct 20, 2023
1 parent d22969a commit dad5dc6
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.spi.FileSystemProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -69,6 +72,11 @@ void setup() throws Exception {
this.uriPrefix = "nested:" + this.file.toURI().getPath() + "/!";
}

@AfterEach
void cleanUp() {
this.provider.cleanUp();
}

@Test
void getSchemeReturnsScheme() {
assertThat(this.provider.getScheme()).isEqualTo("nested");
Expand Down Expand Up @@ -259,6 +267,8 @@ static class TestNestedFileSystemProvider extends NestedFileSystemProvider {

private Path mockJarPath;

private List<Path> paths = new ArrayList<>();

@Override
protected Path getJarPath(Path path) {
return (this.mockJarPath != null) ? this.mockJarPath : super.getJarPath(path);
Expand All @@ -268,6 +278,24 @@ void setMockJarPath(Path mockJarPath) {
this.mockJarPath = mockJarPath;
}

@Override
public Path getPath(URI uri) {
Path path = super.getPath(uri);
this.paths.add(path);
return path;
}

private void cleanUp() {
this.paths.forEach((path) -> {
try {
Path.of(path.toUri()).getFileSystem().close();
}
catch (Exception ex) {
// Ignore
}
});
}

}

}

0 comments on commit dad5dc6

Please sign in to comment.