Ignore existing output when asserting captured log output

Closes gh-12734
This commit is contained in:
Andy Wilkinson 2018-04-04 14:14:45 +01:00
parent ac88a60071
commit c4923d6273
1 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -201,8 +201,10 @@ public class LoggingApplicationListenerTests {
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
String existingOutput = this.outputCapture.toString();
logger.info("Hello world");
String output = this.outputCapture.toString().trim();
String output = this.outputCapture.toString().substring(existingOutput.length())
.trim();
assertThat(output).startsWith("target/foo.log");
}
@ -226,8 +228,10 @@ public class LoggingApplicationListenerTests {
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
String existingOutput = this.outputCapture.toString();
logger.info("Hello world");
String output = this.outputCapture.toString().trim();
String output = this.outputCapture.toString().substring(existingOutput.length())
.trim();
assertThat(output).startsWith("target/foo/spring.log");
}