|
16 | 16 | */
|
17 | 17 | package org.apache.logging.log4j.core.appender.rolling;
|
18 | 18 |
|
19 |
| -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 19 | +import static org.assertj.core.api.Assertions.assertThat; |
20 | 20 |
|
21 |
| -import java.io.File; |
| 21 | +import java.nio.file.Path; |
22 | 22 | import java.time.LocalTime;
|
23 | 23 | import org.apache.logging.log4j.core.Logger;
|
24 | 24 | import org.apache.logging.log4j.core.LoggerContext;
|
25 | 25 | import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
|
26 | 26 | import org.apache.logging.log4j.test.junit.CleanUpDirectories;
|
| 27 | +import org.apache.logging.log4j.test.junit.TempLoggingDir; |
27 | 28 | import org.junit.jupiter.api.Test;
|
28 | 29 |
|
29 |
| -@CleanUpDirectories(RollingRandomAppenderDirectWriteAndSwitchDirectorTest.DIR) |
30 |
| -class RollingRandomAppenderDirectWriteAndSwitchDirectorTest { |
| 30 | +@CleanUpDirectories(RollingRandomAppenderDirectWriteAndSwitchDirectoryTest.DIR) |
| 31 | +class RollingRandomAppenderDirectWriteAndSwitchDirectoryTest { |
31 | 32 | public static final String DIR = "target/rolling-random-direct-switch-director";
|
32 | 33 |
|
| 34 | + @TempLoggingDir |
| 35 | + private Path loggingPath; |
| 36 | + |
33 | 37 | @Test
|
34 |
| - @LoggerContextSource(value = "log4j-rolling-random-direct-switch-director.xml", timeout = 10) |
| 38 | + @LoggerContextSource(value = "appender/rolling/RollingRandomAppenderDirectWriteAndSwitchDirectoryTest.xml", timeout = 10) |
35 | 39 | void testAppender(final LoggerContext context) throws Exception {
|
36 |
| - final Logger logger = context.getLogger(RollingRandomAppenderDirectWriteAndSwitchDirectorTest.class.getName()); |
| 40 | + final Logger logger = context.getLogger(RollingRandomAppenderDirectWriteAndSwitchDirectoryTest.class.getName()); |
37 | 41 | final LocalTime start = LocalTime.now();
|
38 | 42 | LocalTime end;
|
39 | 43 | do {
|
40 | 44 | end = LocalTime.now();
|
41 | 45 | logger.info("test log");
|
42 | 46 | Thread.sleep(100);
|
43 | 47 | } while (start.getSecond() == end.getSecond());
|
44 |
| - |
45 |
| - final File nextLogFile = new File(String.format("%s/%d/%d.log", DIR, end.getSecond(), end.getSecond())); |
46 |
| - assertTrue(nextLogFile.exists(), "nextLogFile not created"); |
| 48 | + Path nextLogPath = loggingPath.resolve(String.format("%d/%d.log", end.getSecond(), end.getSecond())); |
| 49 | + assertThat(nextLogPath).as("Archived log for second %s", end.getSecond()).exists(); |
47 | 50 | }
|
48 | 51 | }
|
0 commit comments