|
| 1 | +/* |
| 2 | + * Copyright 2012-2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.micrometer.core.testsupport.system; |
| 18 | + |
| 19 | +/** |
| 20 | + * Provides access to {@link System#out System.out} and {@link System#err System.err} |
| 21 | + * output that has been captured by the {@link OutputCaptureExtension}. Can be used to |
| 22 | + * apply assertions either using AssertJ or standard JUnit assertions. For example: |
| 23 | + * <pre class="code"> |
| 24 | + * assertThat(output).contains("started"); // Checks all output |
| 25 | + * assertThat(output.getErr()).contains("failed"); // Only checks System.err |
| 26 | + * assertThat(output.getOut()).contains("ok"); // Only checks System.out |
| 27 | + * </pre> |
| 28 | + * <p> |
| 29 | + * Copied from <a href= |
| 30 | + * "https://github.com/spring-projects/spring-boot/blob/88c9ae97b5638491964537bb5b1f7dfbea1ae047/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/system/CapturedOutput.java">org.springframework.boot.test.system.CapturedOutput</a> |
| 31 | + * in Spring Boot. |
| 32 | + * |
| 33 | + * @author Madhura Bhave |
| 34 | + * @author Phillip Webb |
| 35 | + * @author Andy Wilkinson |
| 36 | + * @see OutputCaptureExtension |
| 37 | + */ |
| 38 | +public interface CapturedOutput extends CharSequence { |
| 39 | + |
| 40 | + @Override |
| 41 | + default int length() { |
| 42 | + return toString().length(); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + default char charAt(int index) { |
| 47 | + return toString().charAt(index); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + default CharSequence subSequence(int start, int end) { |
| 52 | + return toString().subSequence(start, end); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Return all content (both {@link System#out System.out} and {@link System#err |
| 57 | + * System.err}) in the order that it was captured. |
| 58 | + * @return all captured output |
| 59 | + */ |
| 60 | + String getAll(); |
| 61 | + |
| 62 | + /** |
| 63 | + * Return {@link System#out System.out} content in the order that it was captured. |
| 64 | + * @return {@link System#out System.out} captured output |
| 65 | + */ |
| 66 | + String getOut(); |
| 67 | + |
| 68 | + /** |
| 69 | + * Return {@link System#err System.err} content in the order that it was captured. |
| 70 | + * @return {@link System#err System.err} captured output |
| 71 | + */ |
| 72 | + String getErr(); |
| 73 | + |
| 74 | +} |
0 commit comments