From c4923d62733b3f573bece5c1c445a6f1944564f8 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 4 Apr 2018 14:14:45 +0100 Subject: [PATCH] Ignore existing output when asserting captured log output Closes gh-12734 --- .../boot/logging/LoggingApplicationListenerTests.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index 80e2ccfa616..6977904b51f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -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"); }