diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java index 3b478ca981..f865045ca8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java @@ -16,16 +16,14 @@ package org.springframework.boot.logging; -import java.io.File; +import java.io.IOException; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; import org.springframework.util.StringUtils; -import static org.junit.Assert.assertTrue; - /** * Base for {@link LoggingSystem} tests. * @@ -36,31 +34,20 @@ public abstract class AbstractLoggingSystemTests { private static final String JAVA_IO_TMPDIR = "java.io.tmpdir"; - private static String tempDir; + @Rule + public TemporaryFolder temp = new TemporaryFolder(); - @BeforeClass - public static void configureTempdir() { - tempDir = System.getProperty(JAVA_IO_TMPDIR); - File newTempDir = new File("target/tmp"); - newTempDir.mkdirs(); - System.setProperty(JAVA_IO_TMPDIR, newTempDir.getAbsolutePath()); - } - - @AfterClass - public static void reinstateTempDir() { - System.setProperty(JAVA_IO_TMPDIR, tempDir); - } + private String originalTempFolder; @Before - public void deleteTempLog() { - deleteFile(new File(tmpDir() + "/spring.log")); - deleteFile(new File(tmpDir() + "/tmp.log")); + public void configureTempdir() throws IOException { + this.originalTempFolder = System.getProperty(JAVA_IO_TMPDIR); + System.setProperty(JAVA_IO_TMPDIR, this.temp.newFolder().getAbsolutePath()); } - private void deleteFile(File file) { - if (file.exists()) { - assertTrue("Unable to delete file", file.delete()); - } + @After + public void reinstateTempDir() { + System.setProperty(JAVA_IO_TMPDIR, this.originalTempFolder); } @After