Skip to content

Commit

Permalink
Delete JDK regression tests
Browse files Browse the repository at this point in the history
Additional cleanup
  • Loading branch information
marschall committed Jan 22, 2024
1 parent e804719 commit 4527dcd
Showing 1 changed file with 10 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.file.StandardOpenOption.CREATE_NEW;
import static java.nio.file.StandardOpenOption.WRITE;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.condition.JRE.JAVA_12;

import java.io.BufferedWriter;
import java.io.IOException;
Expand All @@ -14,14 +14,12 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Map;
import java.util.jar.JarOutputStream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.RegisterExtension;

class ZipFileSystemInteroperabilityTest {
Expand All @@ -30,106 +28,45 @@ class ZipFileSystemInteroperabilityTest {

// Avoid casts in FileSystems.newFileSystem(Path, ClassLoader)
private static final ClassLoader NULL_CLASS_LOADER = null;
private static final Map<String, ?> CREATE_ENV = Collections.singletonMap("create", "false");

// https://docs.oracle.com/en/java/javase/21/docs/api/jdk.zipfs/module-summary.html#zip-file-system-properties-heading
private static final Map<String, ?> DO_CREATE_FILE_ENV = Collections.singletonMap("create", "true");

@RegisterExtension
final FileSystemExtension extension = new FileSystemExtension();

@Test
void createZipFileSystem() throws IOException {
FileSystem memoryFileSystem = this.extension.getFileSystem();
Map<String, String> env = Collections.singletonMap("create", "true");
URI uri = URI.create(FS_URI + memoryFileSystem.getPath("/file.zip").toUri());
try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
try (FileSystem zipfs = FileSystems.newFileSystem(uri, DO_CREATE_FILE_ENV)) {
try (BufferedWriter writer = Files.newBufferedWriter(zipfs.getPath("hello.txt"), US_ASCII, CREATE_NEW, WRITE)) {
writer.write("world");
}
}
}

@Test
@EnabledForJreRange(min = JRE.JAVA_12, disabledReason = "nested zips only available on JDK 12+")
@EnabledForJreRange(min = JAVA_12, disabledReason = "nested zips only available on JDK 12+")
void createNestedZips() throws IOException {
FileSystem memoryFileSystem = this.extension.getFileSystem();
Path outerZip = memoryFileSystem.getPath("/file.zip");
try (OutputStream stream = new JarOutputStream(Files.newOutputStream(outerZip, CREATE_NEW, WRITE))) {
// nothing, just create an empty jar
}
try (FileSystem zipfs = FileSystems.newFileSystem(outerZip, NULL_CLASS_LOADER)) {
Path innerZip = zipfs.getPath("hello.zip");
try (FileSystem outerZipFs = FileSystems.newFileSystem(outerZip, NULL_CLASS_LOADER)) {
Path innerZip = outerZipFs.getPath("hello.zip");
try (OutputStream stream = new JarOutputStream(Files.newOutputStream(innerZip, CREATE_NEW, WRITE))) {
// nothing, just create an empty jar
}
// locate file system by using the syntax
// defined in java.net.JarURLConnection
try (FileSystem zipfs2 = FileSystems.newFileSystem(innerZip, NULL_CLASS_LOADER)) {
try (BufferedWriter writer = Files.newBufferedWriter(zipfs2.getPath("hello.txt"), US_ASCII, CREATE_NEW, WRITE)) {
try (FileSystem innerZipFs = FileSystems.newFileSystem(innerZip, NULL_CLASS_LOADER)) {
try (BufferedWriter writer = Files.newBufferedWriter(innerZipFs.getPath("hello.txt"), US_ASCII, CREATE_NEW, WRITE)) {
writer.write("world");
}
}
}
}

@Test
@EnabledForJreRange(min = JRE.JAVA_9, disabledReason = "zip FS path to URI conversion works on JDK 9+")
void jarToUriRegression() throws IOException {
Path jarFolder = Files.createTempDirectory("jartest");
try {
Path jarFile = jarFolder.resolve("test.jar");
try {
Map<String, String> env = Collections.singletonMap("create", "true");
URI uri = URI.create(FS_URI + jarFile.toUri());
try (FileSystem jarfs = FileSystems.newFileSystem(uri, env)) {
Path p = jarfs.getPath("hello.txt");
assertNotNull(Paths.get(p.toUri()));
}
} finally {
Files.delete(jarFile);
}
} finally {
Files.delete(jarFolder);
}
}

@Test
void jarToUriRegressionFixed() throws IOException {
Path jarFile = Files.createTempFile(null, ".jar");
try (OutputStream stream = new JarOutputStream(Files.newOutputStream(jarFile))) {
// nothing, just create an empty jar
}
try {
URI uri = URI.create(FS_URI + jarFile.toUri());
try (FileSystem jarfs = FileSystems.newFileSystem(uri, CREATE_ENV)) {
Path p = jarfs.getPath("hello.txt");
assertNotNull(Paths.get(p.toUri()));
}
} finally {
Files.delete(jarFile);
}
}

@Test
@EnabledForJreRange(min = JRE.JAVA_12, disabledReason = "nested zips only available on JDK 12+")
void nestedJarsRegression() throws IOException {
Path outerJar = Files.createTempFile("outer", ".jar");
try (OutputStream stream = new JarOutputStream(Files.newOutputStream(outerJar))) {
// nothing, just create an empty jar
}
try {
try (FileSystem jarfs = FileSystems.newFileSystem(outerJar, NULL_CLASS_LOADER)) {
Path innerJar = jarfs.getPath("inner.jar");
try (OutputStream stream = new JarOutputStream(Files.newOutputStream(innerJar, CREATE_NEW, WRITE))) {
// nothing, just create an empty jar
}
try (FileSystem zipfs2 = FileSystems.newFileSystem(innerJar, NULL_CLASS_LOADER)) {
try (BufferedWriter writer = Files.newBufferedWriter(zipfs2.getPath("hello.txt"), US_ASCII, CREATE_NEW, WRITE)) {
writer.write("world");
}
}
}
} finally {
Files.delete(outerJar);
}
}

}

0 comments on commit 4527dcd

Please sign in to comment.