diff --git a/javatests/google/registry/tools/BUILD b/javatests/google/registry/tools/BUILD index 9583f12ff..f01c4d359 100644 --- a/javatests/google/registry/tools/BUILD +++ b/javatests/google/registry/tools/BUILD @@ -13,7 +13,9 @@ java_library( srcs = glob([ "*.java", ]), - resources = glob(["testdata/*.*"]), + resources = glob([ + "testdata/*.*", + ]), deps = [ "//java/com/google/common/annotations", "//java/com/google/common/base", diff --git a/javatests/google/registry/tools/CommandTestCase.java b/javatests/google/registry/tools/CommandTestCase.java index 5c26f82b2..6dac241dc 100644 --- a/javatests/google/registry/tools/CommandTestCase.java +++ b/javatests/google/registry/tools/CommandTestCase.java @@ -49,7 +49,8 @@ import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public abstract class CommandTestCase { - private ByteArrayOutputStream stdout = new ByteArrayOutputStream(); + private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); + private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); protected C command; @@ -71,6 +72,7 @@ public abstract class CommandTestCase { RegistryToolEnvironment.UNITTEST.setup(); command = newCommandInstance(); System.setOut(new PrintStream(stdout)); + System.setErr(new PrintStream(stderr)); } void runCommandInEnvironment(RegistryToolEnvironment env, String... args) throws Exception { @@ -156,6 +158,13 @@ public abstract class CommandTestCase { } } + protected void assertInStderr(String... expected) throws Exception { + String stderror = new String(stderr.toByteArray(), UTF_8); + for (String line : expected) { + assertThat(stderror).contains(line); + } + } + void assertNotInStdout(String expected) throws Exception { assertThat(getStdoutAsString()).doesNotContain(expected); }