From c2488b1a9b4843b2cd5140d61b2baaccb889fac1 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 6 Nov 2013 13:18:55 +0000 Subject: [PATCH] Flush output streams in capture Avoids possible test failures owing to unflushed buffers --- .../springframework/boot/OutputCapture.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/OutputCapture.java b/spring-boot/src/test/java/org/springframework/boot/OutputCapture.java index 72b3bc6108..b4dd043af0 100644 --- a/spring-boot/src/test/java/org/springframework/boot/OutputCapture.java +++ b/spring-boot/src/test/java/org/springframework/boot/OutputCapture.java @@ -72,8 +72,19 @@ public class OutputCapture implements TestRule { this.copy = null; } + public void flush() { + try { + this.captureOut.flush(); + this.captureErr.flush(); + } + catch (IOException e) { + // ignore + } + } + @Override public String toString() { + flush(); return this.copy.toString(); } @@ -104,12 +115,17 @@ public class OutputCapture implements TestRule { public void write(byte[] b, int off, int len) throws IOException { this.copy.write(b, off, len); this.original.write(b, off, len); - this.original.flush(); } public PrintStream getOriginal() { return this.original; } + + @Override + public void flush() throws IOException { + this.copy.flush(); + this.original.flush(); + } } /**