This commit is contained in:
Phillip Webb 2019-07-14 17:39:45 +01:00
parent 8d4a2add63
commit cdf43a7489
6 changed files with 8 additions and 37 deletions

View File

@ -18,9 +18,9 @@ package org.springframework.boot.test.system;
/**
* Provides access to {@link System#out System.out} and {@link System#err System.err}
* output that has been captured by the {@link OutputCaptureExtension}. Can be used to
* apply assertions either using AssertJ or standard JUnit assertions. For example:
* <pre class="code">
* output that has been captured by the {@link OutputCaptureExtension} or
* {@link OutputCaptureRule}. Can be used to apply assertions either using AssertJ or
* standard JUnit assertions. For example: <pre class="code">
* assertThat(output).contains("started"); // Checks all output
* assertThat(output.getErr()).contains("failed"); // Only checks System.err
* assertThat(output.getOut()).contains("ok"); // Only checks System.put

View File

@ -33,7 +33,7 @@ import org.junit.jupiter.api.extension.ParameterResolver;
* parameter resolution} for a {@link CapturedOutput} instance which can be used to assert
* that the correct output was written.
* <p>
* To use with {@link ExtendWith @ExtendWith}, inject the {@link CapturedOutput} as an
* To use, add {@link ExtendWith @ExtendWith} and inject the {@link CapturedOutput} as an
* argument to your test class constructor or test method:
*
* <pre class="code">

View File

@ -83,7 +83,7 @@ public class OutputCaptureRule implements TestRule, CapturedOutput {
/**
* Resets the current capture session, clearing its captured output.
* @deprecated since 2.2 with no replacement
* @deprecated since 2.2.0 with no replacement
*/
@Deprecated
public void reset() {

View File

@ -17,20 +17,13 @@
package org.springframework.boot.testsupport.system;
/**
* Provides access to {@link System#out System.out} and {@link System#err System.err}
* output that has been capture by the {@link OutputCaptureExtension}. Can be used to
* apply assertions either using AssertJ or standard JUnit assertions. For example:
* <pre class="code">
* assertThat(output).contains("started"); // Checks all output
* assertThat(output.getErr()).contains("failed"); // Only checks System.err
* assertThat(output.getOut()).contains("ok"); // Only checks System.put
* </pre>
* Internal test class providing access to {@link System#out System.out} and
* {@link System#err System.err} output that has been captured.
*
* @author Madhura Bhave
* @author Phillip Webb
* @author Andy Wilkinson
* @since 2.2.0
* @see OutputCaptureExtension
*/
public interface CapturedOutput extends CharSequence {

View File

@ -35,8 +35,6 @@ import org.springframework.util.Assert;
* @author Madhura Bhave
* @author Phillip Webb
* @author Andy Wilkinson
* @see OutputCaptureExtension
* @see OutputCaptureRule
*/
class OutputCapture implements CapturedOutput {

View File

@ -20,7 +20,6 @@ import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
@ -28,31 +27,12 @@ import org.junit.jupiter.api.extension.ParameterResolver;
/**
* Internal JUnit 5 {@code @Extension} to capture {@link System#out System.out} and
* {@link System#err System.err}. Can be used on a test class via
* {@link ExtendWith @ExtendWith}. This extension provides {@link ParameterResolver
* parameter resolution} for a {@link CapturedOutput} instance which can be used to assert
* that the correct output was written.
* <p>
* To use with {@link ExtendWith @ExtendWith}, inject the {@link CapturedOutput} as an
* argument to your test class constructor or test method:
*
* <pre class="code">
* &#064;ExtendWith(OutputCaptureExtension.class)
* class MyTest {
*
* &#064;Test
* void test(CapturedOutput output) {
* assertThat(output).contains("ok");
* }
*
* }
* </pre>
* {@link System#err System.err}.
*
* @author Madhura Bhave
* @author Phillip Webb
* @author Andy Wilkinson
* @since 2.2.0
* @see CapturedOutput
*/
public class OutputCaptureExtension
implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback, ParameterResolver {