From 09326cb8acb51a7aa69daf1176abd41517be647b Mon Sep 17 00:00:00 2001 From: Michael Muller Date: Fri, 16 Aug 2019 14:45:24 -0400 Subject: [PATCH] Added forgotten command description --- .../registry/tools/CommandTestCase.java | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/google/registry/tools/CommandTestCase.java b/core/src/test/java/google/registry/tools/CommandTestCase.java index 48def8fbb..03080e6b2 100644 --- a/core/src/test/java/google/registry/tools/CommandTestCase.java +++ b/core/src/test/java/google/registry/tools/CommandTestCase.java @@ -36,6 +36,7 @@ import google.registry.tools.params.ParameterFactory; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.io.PrintStream; import java.util.List; import org.junit.Before; @@ -75,8 +76,10 @@ public abstract class CommandTestCase { // Ensure the UNITTEST environment has been set before constructing a new command instance. RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule); command = newCommandInstance(); - System.setOut(new PrintStream(stdout)); - System.setErr(new PrintStream(stderr)); + System.out.println("XXX Before stealing output..."); + System.setOut(new PrintStream(new OutputSplitter(System.out, stdout))); + System.setErr(new PrintStream(new OutputSplitter(System.err, stderr))); + System.out.println("XXX After stealing output..."); } void runCommandInEnvironment(RegistryToolEnvironment env, String... args) throws Exception { @@ -221,4 +224,44 @@ public abstract class CommandTestCase { throw new RuntimeException(e); } } + + static class OutputSplitter extends OutputStream { + + OutputStream a, b; + + OutputSplitter(OutputStream a, OutputStream b) { + this.a = a; + this.b = b; + } + + @Override + public void write(byte[] data) throws IOException { + a.write(data); + b.write(data); + } + + @Override + public void write(byte[] data, int off, int len) throws IOException { + a.write(data, off, len); + b.write(data, off, len); + } + + @Override + public void close() throws IOException { + a.close(); + b.close(); + } + + @Override + public void flush() throws IOException { + a.close(); + b.close(); + } + + @Override + public void write(int val) throws IOException { + a.write(val); + b.write(val); + } + } }