Improve test coverage for OutputCaptureRule

See gh-33405
This commit is contained in:
nowjin
2022-11-29 17:38:59 +09:00
committed by Phillip Webb
parent 14d4211b6a
commit af7a03b4c9

View File

@@ -37,10 +37,35 @@ public class OutputCaptureRuleTests {
assertThat(this.output.toString()).contains("Hello World");
}
@Test
public void getAllShouldReturnAllCapturedOutput() {
System.out.println("Hello World");
System.err.println("Hello Error");
assertThat(this.output.getAll()).contains("Hello World", "Hello Error");
}
@Test
public void getOutShouldOnlyReturnOutputCapturedFromSystemOut() {
System.out.println("Hello World");
System.err.println("Hello Error");
assertThat(this.output.getOut()).contains("Hello World");
assertThat(this.output.getOut()).doesNotContain("Hello Error");
}
@Test
public void captureShouldBeAssertable() {
System.out.println("Hello World");
assertThat(this.output).contains("Hello World");
}
@Test
public void getErrShouldOnlyReturnOutputCapturedFromSystemErr() {
System.out.println("Hello World");
System.err.println("Hello Error");
assertThat(this.output.getErr()).contains("Hello Error");
assertThat(this.output.getErr()).doesNotContain("Hello World");
}
}