Skip to content

Commit c4923d6

Browse files
committed
Ignore existing output when asserting captured log output
Closes gh-12734
1 parent ac88a60 commit c4923d6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -201,8 +201,10 @@ public void addLogFileProperty() {
201201
this.initializer.initialize(this.context.getEnvironment(),
202202
this.context.getClassLoader());
203203
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
204+
String existingOutput = this.outputCapture.toString();
204205
logger.info("Hello world");
205-
String output = this.outputCapture.toString().trim();
206+
String output = this.outputCapture.toString().substring(existingOutput.length())
207+
.trim();
206208
assertThat(output).startsWith("target/foo.log");
207209
}
208210

@@ -226,8 +228,10 @@ public void addLogPathProperty() {
226228
this.initializer.initialize(this.context.getEnvironment(),
227229
this.context.getClassLoader());
228230
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
231+
String existingOutput = this.outputCapture.toString();
229232
logger.info("Hello world");
230-
String output = this.outputCapture.toString().trim();
233+
String output = this.outputCapture.toString().substring(existingOutput.length())
234+
.trim();
231235
assertThat(output).startsWith("target/foo/spring.log");
232236
}
233237

0 commit comments

Comments
 (0)