Change LoggingSystemTests to use real temp folder
Update AbstractLoggingSystemTests to use a TemporaryFolder rule. Fixes gh-3349
This commit is contained in:
parent
5c6fef903d
commit
8e78ba8ce7
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue