From 3fe2005e06db8a0582647b92e83ee4eec5d2259d Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 19 Aug 2020 10:21:03 -0700 Subject: [PATCH] Use @AfterEach to close the source jar file Update `JarFileWrapperTests` so that the jar files are closed after each test. See gh-22991 --- .../boot/loader/jar/JarFileWrapperTests.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileWrapperTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileWrapperTests.java index 83482dbcd3..354142fd68 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileWrapperTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileWrapperTests.java @@ -30,6 +30,7 @@ import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.zip.ZipEntry; +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; @@ -51,11 +52,16 @@ class JarFileWrapperTests { private JarFileWrapper wrapper; @BeforeEach - void setup(@TempDir File temp) throws IOException { + void setup(@TempDir File temp) throws Exception { this.parent = new SpyJarFile(createTempJar(temp)); this.wrapper = new JarFileWrapper(this.parent); } + @AfterEach + void cleanup() throws Exception { + this.parent.close(); + } + private File createTempJar(File temp) throws IOException { File file = new File(temp, "temp.jar"); new JarOutputStream(new FileOutputStream(file)).close();