Commit 8e78ba8c authored by Phillip Webb's avatar Phillip Webb

Change LoggingSystemTests to use real temp folder

Update AbstractLoggingSystemTests to use a TemporaryFolder rule.

Fixes gh-3349
parent 5c6fef90
...@@ -16,16 +16,14 @@ ...@@ -16,16 +16,14 @@
package org.springframework.boot.logging; package org.springframework.boot.logging;
import java.io.File; import java.io.IOException;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import static org.junit.Assert.assertTrue;
/** /**
* Base for {@link LoggingSystem} tests. * Base for {@link LoggingSystem} tests.
* *
...@@ -36,31 +34,20 @@ public abstract class AbstractLoggingSystemTests { ...@@ -36,31 +34,20 @@ public abstract class AbstractLoggingSystemTests {
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir"; 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 private String originalTempFolder;
public static void reinstateTempDir() {
System.setProperty(JAVA_IO_TMPDIR, tempDir);
}
@Before @Before
public void deleteTempLog() { public void configureTempdir() throws IOException {
deleteFile(new File(tmpDir() + "/spring.log")); this.originalTempFolder = System.getProperty(JAVA_IO_TMPDIR);
deleteFile(new File(tmpDir() + "/tmp.log")); System.setProperty(JAVA_IO_TMPDIR, this.temp.newFolder().getAbsolutePath());
} }
private void deleteFile(File file) { @After
if (file.exists()) { public void reinstateTempDir() {
assertTrue("Unable to delete file", file.delete()); System.setProperty(JAVA_IO_TMPDIR, this.originalTempFolder);
}
} }
@After @After
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment