More defensive testing of tmpdir

This commit is contained in:
Dave Syer 2014-03-11 15:53:30 +00:00
parent 0439b39381
commit 207d4853ed
1 changed files with 8 additions and 3 deletions

View File

@ -51,7 +51,11 @@ public class LogbackLoggingSystemTests {
@Before @Before
public void setup() { public void setup() {
this.logger = new SLF4JLogFactory().getInstance(getClass().getName()); this.logger = new SLF4JLogFactory().getInstance(getClass().getName());
new File("/tmp/spring.log").delete(); new File(tmpDir() + "/spring.log").delete();
}
private String tmpDir() {
return System.getProperty("java.io.tmpdir");
} }
@After @After
@ -68,8 +72,9 @@ public class LogbackLoggingSystemTests {
this.logger.info("Hello world"); this.logger.info("Hello world");
String output = this.output.toString().trim(); String output = this.output.toString().trim();
assertTrue("Wrong output:\n" + output, output.contains("Hello world")); assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
assertTrue("Wrong output:\n" + output, output.contains("/tmp/spring.log")); assertTrue("Wrong output (not " + tmpDir() + " :\n" + output,
assertFalse(new File("/tmp/spring.log").exists()); output.contains(tmpDir() + "/tmp.log"));
assertFalse(new File(tmpDir() + "/tmp.log").exists());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)