File tree Expand file tree Collapse file tree 2 files changed +46
-18
lines changed
spring-boot-project/spring-boot-docs/src
test/java/org/springframework/boot/docs/test/rule Expand file tree Collapse file tree 2 files changed +46
-18
lines changed Original file line number Diff line number Diff line change @@ -7933,26 +7933,10 @@ for assertions, as follows:
7933
7933
7934
7934
[source,java,indent=0]
7935
7935
----
7936
- import org.junit.Rule;
7937
- import org.junit.Test;
7938
- import org.springframework.boot.test.rule.OutputCapture;
7939
-
7940
- import static org.hamcrest.Matchers.*;
7941
- import static org.junit.Assert.*;
7942
-
7943
- public class MyTest {
7944
-
7945
- @Rule
7946
- public OutputCapture capture = new OutputCapture();
7936
+ include::{test-examples}/test/rule/OutputCaptureTests.java[tag=test]
7937
+ ----
7947
7938
7948
- @Test
7949
- public void testName() throws Exception {
7950
- System.out.println("Hello World!");
7951
- assertThat(capture.toString(), containsString("World");
7952
- }
7953
7939
7954
- }
7955
- ----
7956
7940
7957
7941
[[boot-features-rest-templates-test-utility]]
7958
7942
==== TestRestTemplate
Original file line number Diff line number Diff line change
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 org .springframework .boot .docs .test .rule ;
18
+
19
+ import org .junit .Rule ;
20
+ import org .junit .Test ;
21
+
22
+ import org .springframework .boot .test .rule .OutputCapture ;
23
+
24
+ import static org .assertj .core .api .Assertions .assertThat ;
25
+
26
+ /**
27
+ * Sample showcasing the use of {@link OutputCapture}.
28
+ *
29
+ * @author Stephane Nicoll
30
+ */
31
+ // tag::test[]
32
+ public class OutputCaptureTests {
33
+
34
+ @ Rule
35
+ public final OutputCapture capture = new OutputCapture ();
36
+
37
+ @ Test
38
+ public void testName () {
39
+ System .out .println ("Hello World!" );
40
+ assertThat (this .capture .toString ()).contains ("World" );
41
+ }
42
+
43
+ }
44
+ // end::test[]
You can’t perform that action at this time.
0 commit comments