From af7a03b4c9cec47d1176f74d5ddd5f5aa6ecf935 Mon Sep 17 00:00:00 2001 From: nowjin Date: Tue, 29 Nov 2022 17:38:59 +0900 Subject: [PATCH 1/2] Improve test coverage for OutputCaptureRule See gh-33405 --- .../test/system/OutputCaptureRuleTests.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java index 0cc92fbef6..616324fa6e 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java @@ -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"); + } } From 711e2528fbbd6f0406c43b8eb578e91a787cfde8 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 29 Nov 2022 14:09:26 -0800 Subject: [PATCH 2/2] Polish 'Improve test coverage for OutputCaptureRule' See gh-33405 --- .../boot/test/system/OutputCaptureRuleTests.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java index 616324fa6e..3c1ec217fd 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java @@ -41,7 +41,6 @@ public class OutputCaptureRuleTests { public void getAllShouldReturnAllCapturedOutput() { System.out.println("Hello World"); System.err.println("Hello Error"); - assertThat(this.output.getAll()).contains("Hello World", "Hello Error"); } @@ -49,23 +48,22 @@ public class OutputCaptureRuleTests { 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"); } + + @Test + public void captureShouldBeAssertable() { + System.out.println("Hello World"); + assertThat(this.output).contains("Hello World"); + } + }