|
| 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 | + * |
| 29 | + * @author Madhura Bhave |
| 30 | + * @author Phillip Webb |
| 31 | + * @author Andy Wilkinson |
| 32 | + * @see OutputCaptureExtension |
| 33 | + */ |
| 34 | +public interface CapturedOutput extends CharSequence { |
| 35 | + |
| 36 | + @Override |
| 37 | + default int length() { |
| 38 | + return toString().length(); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + default char charAt(int index) { |
| 43 | + return toString().charAt(index); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + default CharSequence subSequence(int start, int end) { |
| 48 | + return toString().subSequence(start, end); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Return all content (both {@link System#out System.out} and {@link System#err |
| 53 | + * System.err}) in the order that it was captured. |
| 54 | + * @return all captured output |
| 55 | + */ |
| 56 | + String getAll(); |
| 57 | + |
| 58 | + /** |
| 59 | + * Return {@link System#out System.out} content in the order that it was captured. |
| 60 | + * @return {@link System#out System.out} captured output |
| 61 | + */ |
| 62 | + String getOut(); |
| 63 | + |
| 64 | + /** |
| 65 | + * Return {@link System#err System.err} content in the order that it was captured. |
| 66 | + * @return {@link System#err System.err} captured output |
| 67 | + */ |
| 68 | + String getErr(); |
| 69 | + |
| 70 | +} |
0 commit comments