Skip to content

Commit 11cad9e

Browse files
committed
Fix sample in ref doc
Closes gh-7142
1 parent 0d33187 commit 11cad9e

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

spring-boot-docs/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</organization>
1818
<properties>
1919
<main.basedir>${basedir}/..</main.basedir>
20+
<disable.checks>true</disable.checks>
2021
</properties>
2122
<dependencies>
2223
<dependency>

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4981,28 +4981,7 @@ For convenience, tests that need to make REST calls to the started server can ad
49814981

49824982
[source,java,indent=0]
49834983
----
4984-
import org.junit.*;
4985-
import org.junit.runner.*;
4986-
import org.springframework.boot.test.context.web.*;
4987-
import org.springframework.boot.test.web.client.*;
4988-
import org.springframework.test.context.junit4.*;
4989-
4990-
import static org.assertj.core.api.Assertions.*
4991-
4992-
@RunWith(SpringRunner.class)
4993-
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
4994-
public class MyWebIntegrationTests {
4995-
4996-
@Autowired
4997-
private TestRestTemplate restTemplate;
4998-
4999-
@Test
5000-
public void exampleTest() {
5001-
String body = this.restTemplate.getForObject("/", String.class);
5002-
assertThat(body).isEqualTo("Hello World");
5003-
}
5004-
5005-
}
4984+
include::{code-examples}/test/web/RandomPortExampleTests.java[tag=test-random-port]
50064985
----
50074986

50084987

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2012-2016 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+
* http://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.test.web;
18+
19+
// tag::test-random-port[]
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
26+
import org.springframework.boot.test.web.client.TestRestTemplate;
27+
import org.springframework.test.context.junit4.SpringRunner;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
@RunWith(SpringRunner.class)
32+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
33+
public class RandomPortExampleTests {
34+
35+
@Autowired
36+
private TestRestTemplate restTemplate;
37+
38+
@Test
39+
public void exampleTest() {
40+
String body = this.restTemplate.getForObject("/", String.class);
41+
assertThat(body).isEqualTo("Hello World");
42+
}
43+
44+
}
45+
// tag::test-random-port[]

0 commit comments

Comments
 (0)