Skip to content

Commit 0edf7cb

Browse files
committed
Polish Log4j2 XML configuration tests
See gh-22983
1 parent f6492cd commit 0edf7cb

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2FileXmlTests.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@
3636
*/
3737
class Log4j2FileXmlTests extends Log4j2XmlTests {
3838

39+
@TempDir
40+
File temp;
41+
42+
@Override
3943
@BeforeEach
40-
void configureLogFile(@TempDir File temp) {
41-
System.setProperty(LoggingSystemProperties.LOG_FILE, new File(temp, "test.log").getAbsolutePath());
44+
void prepareConfiguration() {
45+
System.setProperty(LoggingSystemProperties.LOG_FILE, new File(this.temp, "test.log").getAbsolutePath());
46+
super.prepareConfiguration();
4247
}
4348

49+
@Override
4450
@AfterEach
45-
void clearLogFile() {
51+
void stopConfiguration() {
52+
super.stopConfiguration();
4653
System.clearProperty(LoggingSystemProperties.LOG_FILE);
4754
}
4855

@@ -75,8 +82,8 @@ void whenLogLDateformatPatternIsNotConfiguredThenFileAppenderUsesDefault() {
7582

7683
@Test
7784
void whenLogDateformatPatternIsSetThenFileAppenderUsesIt() {
78-
withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "custom",
79-
() -> assertThat(fileAppenderPattern()).contains("custom"));
85+
withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "dd-MM-yyyy",
86+
() -> assertThat(fileAppenderPattern()).contains("dd-MM-yyyy"));
8087
}
8188

8289
@Override

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2XmlTests.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.logging.log4j.core.config.ConfigurationFactory;
2525
import org.apache.logging.log4j.core.config.ConfigurationSource;
2626
import org.apache.logging.log4j.core.layout.PatternLayout;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.BeforeEach;
2729
import org.junit.jupiter.api.Test;
2830

2931
import org.springframework.boot.logging.LoggingSystemProperties;
@@ -37,6 +39,18 @@
3739
*/
3840
class Log4j2XmlTests {
3941

42+
private Configuration configuration;
43+
44+
@BeforeEach
45+
void prepareConfiguration() {
46+
this.configuration = initializeConfiguration();
47+
}
48+
49+
@AfterEach
50+
void stopConfiguration() {
51+
this.configuration.stop();
52+
}
53+
4054
@Test
4155
void whenLogExceptionConversionWordIsNotConfiguredThenConsoleUsesDefault() {
4256
assertThat(consolePattern()).contains("%xwEx");
@@ -66,8 +80,8 @@ void whenLogLDateformatPatternIsNotConfiguredThenConsoleUsesDefault() {
6680

6781
@Test
6882
void whenLogDateformatPatternIsSetThenConsoleUsesIt() {
69-
withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "custom",
70-
() -> assertThat(consolePattern()).contains("custom"));
83+
withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "dd-MM-yyyy",
84+
() -> assertThat(consolePattern()).contains("dd-MM-yyyy"));
7185
}
7286

7387
protected void withSystemProperty(String name, String value, Runnable action) {

0 commit comments

Comments
 (0)