From 04eb44b2ea292da09426e8cc9d82453d015da109 Mon Sep 17 00:00:00 2001 From: Alexey Bakhtin Date: Thu, 12 Dec 2024 14:51:38 -0800 Subject: [PATCH] 8346140: tools/jar/ExtractFilesTest.java and tools/jar/MultipleManifestTest.java fails with jtreg5.1 --- jdk/test/tools/jar/ExtractFilesTest.java | 34 ++++++++------------ jdk/test/tools/jar/MultipleManifestTest.java | 31 ++++++------------ 2 files changed, 24 insertions(+), 41 deletions(-) diff --git a/jdk/test/tools/jar/ExtractFilesTest.java b/jdk/test/tools/jar/ExtractFilesTest.java index f3a7a60810..77a205d39a 100644 --- a/jdk/test/tools/jar/ExtractFilesTest.java +++ b/jdk/test/tools/jar/ExtractFilesTest.java @@ -31,12 +31,7 @@ * @run junit/othervm ExtractFilesTest */ -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.*; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -51,13 +46,12 @@ import jdk.testlibrary.FileUtils; import sun.tools.jar.Main; -@TestInstance(Lifecycle.PER_CLASS) public class ExtractFilesTest { private final String nl = System.lineSeparator(); private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); private final PrintStream out = new PrintStream(baos); - @BeforeAll + @Before public void setupJar() throws IOException { mkdir("test1 test2"); echo("testfile1", "test1/testfile1"); @@ -66,7 +60,7 @@ public void setupJar() throws IOException { rm("test1 test2"); } - @AfterAll + @After public void cleanup() { rm("test.jar"); } @@ -83,7 +77,7 @@ public void testExtract() throws IOException { " inflated: testfile1" + nl + " inflated: testfile2" + nl; rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + Assert.assertArrayEquals(baos.toByteArray(), output.getBytes()); } /** @@ -98,9 +92,9 @@ public void testOverwrite() throws IOException { " inflated: META-INF/MANIFEST.MF" + nl + " inflated: testfile1" + nl + " inflated: testfile2" + nl; - Assertions.assertEquals("testfile1", cat("testfile1")); + Assert.assertEquals("testfile1", cat("testfile1")); rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + Assert.assertArrayEquals(baos.toByteArray(), output.getBytes()); } /** @@ -115,10 +109,10 @@ public void testKeptOldFile() throws IOException { " inflated: META-INF/MANIFEST.MF" + nl + " skipped: testfile1 exists" + nl + " inflated: testfile2" + nl; - Assertions.assertEquals("", cat("testfile1")); - Assertions.assertEquals("testfile2", cat("testfile2")); + Assert.assertEquals("", cat("testfile1")); + Assert.assertEquals("testfile2", cat("testfile2")); rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + Assert.assertArrayEquals(baos.toByteArray(), output.getBytes()); } /** @@ -133,10 +127,10 @@ public void testGnuOptionsKeptOldFile() throws IOException { " inflated: META-INF/MANIFEST.MF" + nl + " skipped: testfile1 exists" + nl + " skipped: testfile2 exists" + nl; - Assertions.assertEquals("", cat("testfile1")); - Assertions.assertEquals("", cat("testfile2")); + Assert.assertEquals("", cat("testfile1")); + Assert.assertEquals("", cat("testfile2")); rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + Assert.assertArrayEquals(baos.toByteArray(), output.getBytes()); } /** @@ -152,8 +146,8 @@ public void testWarningOnInvalidKeepOption() throws IOException { "testfile1" + nl + "testfile2" + nl; - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); - Assertions.assertEquals("Warning: The k option is not valid with current usage, will be ignored." + nl, err); + Assert.assertArrayEquals(baos.toByteArray(), output.getBytes()); + Assert.assertEquals("Warning: The k option is not valid with current usage, will be ignored." + nl, err); } private Stream mkpath(String... args) { diff --git a/jdk/test/tools/jar/MultipleManifestTest.java b/jdk/test/tools/jar/MultipleManifestTest.java index c62fef47dd..7b8592dc06 100644 --- a/jdk/test/tools/jar/MultipleManifestTest.java +++ b/jdk/test/tools/jar/MultipleManifestTest.java @@ -33,13 +33,7 @@ import java.io.ByteArrayOutputStream; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.*; import java.io.IOException; import java.io.InputStream; @@ -60,8 +54,7 @@ import jdk.testlibrary.FileUtils; import sun.tools.jar.Main; -@TestInstance(Lifecycle.PER_CLASS) -class MultipleManifestTest { +public class MultipleManifestTest { private final String nl = System.lineSeparator(); private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); private final PrintStream jarOut = new PrintStream(baos); @@ -85,8 +78,9 @@ class MultipleManifestTest { * * @throws IOException if an unexpected IOException occurs */ - @AfterAll + @After public void cleanup() throws IOException { + rm("META-INF entry1.txt entry2.txt"); Files.deleteIfExists(zip); } @@ -95,7 +89,7 @@ public void cleanup() throws IOException { * * @throws IOException if an error occurs */ - @BeforeAll + @Before public void writeManifestAsFirstSecondAndFourthEntry() throws IOException { int locPosA, locPosB, cenPos; System.out.printf("%n%n*****Creating Jar with the Manifest as the 1st, 2nd and 4th entry*****%n%n"); @@ -132,11 +126,6 @@ public void writeManifestAsFirstSecondAndFourthEntry() throws IOException { Files.write(zip, template); } - @AfterEach - public void removeExtractedFiles() { - rm("META-INF entry1.txt entry2.txt"); - } - /** * Extract by default should have the last manifest. */ @@ -144,13 +133,13 @@ public void removeExtractedFiles() { public void testOverwrite() throws IOException { jar("xvf " + zip.toString()); println(); - Assertions.assertEquals("3.0", getManifestVersion()); + Assert.assertEquals("3.0", getManifestVersion()); String output = " inflated: META-INF/MANIFEST.MF" + nl + " inflated: META-INF/MANIFEST.MF" + nl + " inflated: entry1.txt" + nl + " inflated: META-INF/MANIFEST.MF" + nl + " inflated: entry2.txt" + nl; - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + Assert.assertArrayEquals(baos.toByteArray(), output.getBytes()); } /** @@ -160,13 +149,13 @@ public void testOverwrite() throws IOException { public void testKeptOldFile() throws IOException { jar("xkvf " + zip.toString()); println(); - Assertions.assertEquals("1.0", getManifestVersion()); + Assert.assertEquals("1.0", getManifestVersion()); String output = " inflated: META-INF/MANIFEST.MF" + nl + " skipped: META-INF/MANIFEST.MF exists" + nl + " inflated: entry1.txt" + nl + " skipped: META-INF/MANIFEST.MF exists" + nl + " inflated: entry2.txt" + nl; - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + Assert.assertArrayEquals(baos.toByteArray(), output.getBytes()); } private String getManifestVersion() throws IOException { @@ -216,4 +205,4 @@ private void rm(String cmdline) { } }); } -} \ No newline at end of file +}