Flush output streams in capture

Avoids possible test failures owing to unflushed buffers
This commit is contained in:
Dave Syer
2013-11-06 13:18:55 +00:00
parent c678be49e3
commit c2488b1a9b

View File

@@ -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();
}
}
/**