Skip to content

Commit 7cf98d1

Browse files
author
Dave Syer
committed
Tidy up log tests
Bamboo doesn't seem to be causing issues now, so assume [Fixes #52871199] [bs-176] -Djava.util.logging.config.file is passed to log4j as a file name?
1 parent 5aba327 commit 7cf98d1

File tree

2 files changed

+10
-48
lines changed

2 files changed

+10
-48
lines changed

spring-boot/src/test/java/org/springframework/boot/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void addEnviroment(ConfigurableApplicationContext context,
3636
int index = pair.indexOf(":");
3737
String key = pair.substring(0, index > 0 ? index : pair.length());
3838
String value = index > 0 ? pair.substring(index + 1) : "";
39-
map.put(key, value);
39+
map.put(key.trim(), value.trim());
4040
}
4141
context.getEnvironment().getPropertySources()
4242
.addFirst(new MapPropertySource("test", map));

spring-boot/src/test/java/org/springframework/boot/context/initializer/LoggingApplicationContextInitializerTests.java

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import org.junit.rules.TemporaryFolder;
3030
import org.springframework.boot.OutputCapture;
3131
import org.springframework.boot.SpringApplication;
32+
import org.springframework.boot.TestUtils;
3233
import org.springframework.boot.logging.LogLevel;
3334
import org.springframework.boot.logging.java.JavaLoggingSystem;
3435
import org.springframework.context.support.GenericApplicationContext;
35-
import org.springframework.core.env.PropertySource;
3636

3737
import static org.hamcrest.Matchers.containsString;
3838
import static org.hamcrest.Matchers.not;
@@ -90,16 +90,8 @@ public void testDefaultConfigLocation() {
9090

9191
@Test
9292
public void testOverrideConfigLocation() {
93-
this.context.getEnvironment().getPropertySources()
94-
.addFirst(new PropertySource<String>("manual") {
95-
@Override
96-
public Object getProperty(String name) {
97-
if ("logging.config".equals(name)) {
98-
return "classpath:logback-nondefault.xml";
99-
}
100-
return null;
101-
}
102-
});
93+
TestUtils.addEnviroment(this.context,
94+
"logging.config: classpath:logback-nondefault.xml");
10395
this.initializer.initialize(this.context);
10496
this.logger.info("Hello world");
10597
String output = this.outputCapture.toString().trim();
@@ -110,35 +102,16 @@ public Object getProperty(String name) {
110102

111103
@Test
112104
public void testOverrideConfigDoesNotExist() throws Exception {
113-
this.context.getEnvironment().getPropertySources()
114-
.addFirst(new PropertySource<String>("manual") {
115-
@Override
116-
public Object getProperty(String name) {
117-
if ("logging.config".equals(name)) {
118-
return "doesnotexist.xml";
119-
}
120-
return null;
121-
}
122-
});
105+
TestUtils.addEnviroment(this.context, "logging.config: doesnotexist.xml");
123106
this.initializer.initialize(this.context);
124107
// Should not throw
125108
}
126109

127110
@Test
128111
public void testAddLogFileProperty() {
129-
this.context.getEnvironment().getPropertySources()
130-
.addFirst(new PropertySource<String>("manual") {
131-
@Override
132-
public Object getProperty(String name) {
133-
if ("logging.config".equals(name)) {
134-
return "classpath:logback-nondefault.xml";
135-
}
136-
if ("logging.file".equals(name)) {
137-
return "foo.log";
138-
}
139-
return null;
140-
}
141-
});
112+
TestUtils.addEnviroment(this.context,
113+
"logging.config: classpath:logback-nondefault.xml",
114+
"logging.file: foo.log");
142115
this.initializer.initialize(this.context);
143116
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
144117
logger.info("Hello world");
@@ -148,19 +121,8 @@ public Object getProperty(String name) {
148121

149122
@Test
150123
public void testAddLogPathProperty() {
151-
this.context.getEnvironment().getPropertySources()
152-
.addFirst(new PropertySource<String>("manual") {
153-
@Override
154-
public Object getProperty(String name) {
155-
if ("logging.config".equals(name)) {
156-
return "classpath:logback-nondefault.xml";
157-
}
158-
if ("logging.path".equals(name)) {
159-
return "foo/";
160-
}
161-
return null;
162-
}
163-
});
124+
TestUtils.addEnviroment(this.context,
125+
"logging.config: classpath:logback-nondefault.xml", "logging.path: foo/");
164126
this.initializer.initialize(this.context);
165127
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
166128
logger.info("Hello world");

0 commit comments

Comments
 (0)