Commit 93bcc3dc authored by wonwoo's avatar wonwoo Committed by Stephane Nicoll

Update documentation to use JUnit Jupiter

See gh-17507
parent e5b596c1
...@@ -7023,9 +7023,8 @@ property: ...@@ -7023,9 +7023,8 @@ property:
[source,java,indent=0] [source,java,indent=0]
---- ----
@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.main.web-application-type=reactive") @SpringBootTest(properties = "spring.main.web-application-type=reactive")
public class MyWebFluxTests { ... } class MyWebFluxTests { ... }
---- ----
...@@ -7088,10 +7087,10 @@ that class explicitly where it is required, as shown in the following example: ...@@ -7088,10 +7087,10 @@ that class explicitly where it is required, as shown in the following example:
---- ----
@SpringBootTest @SpringBootTest
@Import(MyTestsConfiguration.class) @Import(MyTestsConfiguration.class)
public class MyTests { class MyTests {
@Test @Test
public void exampleTest() { void exampleTest() {
... ...
} }
...@@ -7345,7 +7344,7 @@ Strings respectively. Any helper fields on the test class can be `@Autowired` wh ...@@ -7345,7 +7344,7 @@ Strings respectively. Any helper fields on the test class can be `@Autowired` wh
} }
@Test @Test
public void testDeserialize() throws Exception { void testDeserialize() throws Exception {
String content = "{\"make\":\"Ford\",\"model\":\"Focus\"}"; String content = "{\"make\":\"Ford\",\"model\":\"Focus\"}";
assertThat(this.json.parse(content)) assertThat(this.json.parse(content))
.isEqualTo(new VehicleDetails("Ford", "Focus")); .isEqualTo(new VehicleDetails("Ford", "Focus"));
...@@ -7636,10 +7635,9 @@ following example: ...@@ -7636,10 +7635,9 @@ following example:
[source,java,indent=0] [source,java,indent=0]
---- ----
@RunWith(SpringRunner.class)
@DataJpaTest @DataJpaTest
@AutoConfigureTestDatabase(replace=Replace.NONE) @AutoConfigureTestDatabase(replace=Replace.NONE)
public class ExampleRepositoryTests { class ExampleRepositoryTests {
// ... // ...
...@@ -7765,7 +7763,7 @@ The following class shows the `@DataMongoTest` annotation in use: ...@@ -7765,7 +7763,7 @@ The following class shows the `@DataMongoTest` annotation in use:
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
@DataMongoTest @DataMongoTest
public class ExampleDataMongoTests { class ExampleDataMongoTests {
@Autowired @Autowired
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
...@@ -7785,7 +7783,7 @@ the following example: ...@@ -7785,7 +7783,7 @@ the following example:
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
@DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class) @DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class)
public class ExampleDataMongoNonEmbeddedTests { class ExampleDataMongoNonEmbeddedTests {
} }
---- ----
...@@ -7812,7 +7810,7 @@ The following example shows a typical setup for using Neo4J tests in Spring Boot ...@@ -7812,7 +7810,7 @@ The following example shows a typical setup for using Neo4J tests in Spring Boot
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest; import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest;
@DataNeo4jTest @DataNeo4jTest
public class ExampleDataNeo4jTests { class ExampleDataNeo4jTests {
@Autowired @Autowired
private YourRepository repository; private YourRepository repository;
...@@ -7835,7 +7833,7 @@ as follows: ...@@ -7835,7 +7833,7 @@ as follows:
@DataNeo4jTest @DataNeo4jTest
@Transactional(propagation = Propagation.NOT_SUPPORTED) @Transactional(propagation = Propagation.NOT_SUPPORTED)
public class ExampleNonTransactionalTests { class ExampleNonTransactionalTests {
} }
---- ----
...@@ -7861,7 +7859,7 @@ The following example shows the `@DataRedisTest` annotation in use: ...@@ -7861,7 +7859,7 @@ The following example shows the `@DataRedisTest` annotation in use:
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest; import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
@DataRedisTest @DataRedisTest
public class ExampleDataRedisTests { class ExampleDataRedisTests {
@Autowired @Autowired
private YourRepository repository; private YourRepository repository;
...@@ -7892,7 +7890,7 @@ The following example shows the `@DataLdapTest` annotation in use: ...@@ -7892,7 +7890,7 @@ The following example shows the `@DataLdapTest` annotation in use:
import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.LdapTemplate;
@DataLdapTest @DataLdapTest
public class ExampleDataLdapTests { class ExampleDataLdapTests {
@Autowired @Autowired
private LdapTemplate ldapTemplate; private LdapTemplate ldapTemplate;
...@@ -7912,7 +7910,7 @@ following example: ...@@ -7912,7 +7910,7 @@ following example:
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest; import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest;
@DataLdapTest(excludeAutoConfiguration = EmbeddedLdapAutoConfiguration.class) @DataLdapTest(excludeAutoConfiguration = EmbeddedLdapAutoConfiguration.class)
public class ExampleDataLdapNonEmbeddedTests { class ExampleDataLdapNonEmbeddedTests {
} }
---- ----
...@@ -7935,7 +7933,7 @@ The specific beans that you want to test should be specified by using the `value ...@@ -7935,7 +7933,7 @@ The specific beans that you want to test should be specified by using the `value
[source,java,indent=0] [source,java,indent=0]
---- ----
@RestClientTest(RemoteVehicleDetailsService.class) @RestClientTest(RemoteVehicleDetailsService.class)
public class ExampleRestClientTest { class ExampleRestClientTest {
@Autowired @Autowired
private RemoteVehicleDetailsService service; private RemoteVehicleDetailsService service;
...@@ -7944,7 +7942,7 @@ The specific beans that you want to test should be specified by using the `value ...@@ -7944,7 +7942,7 @@ The specific beans that you want to test should be specified by using the `value
private MockRestServiceServer server; private MockRestServiceServer server;
@Test @Test
public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails()
throws Exception { throws Exception {
this.server.expect(requestTo("/greet/details")) this.server.expect(requestTo("/greet/details"))
.andRespond(withSuccess("hello", MediaType.TEXT_PLAIN)); .andRespond(withSuccess("hello", MediaType.TEXT_PLAIN));
...@@ -8099,10 +8097,9 @@ simply by adding `@ImportAutoConfiguration` to the test as shown in the followin ...@@ -8099,10 +8097,9 @@ simply by adding `@ImportAutoConfiguration` to the test as shown in the followin
[source,java,indent=0] [source,java,indent=0]
---- ----
@RunWith(SpringRunner.class)
@JdbcTest @JdbcTest
@ImportAutoConfiguration(IntegrationAutoConfiguration.class) @ImportAutoConfiguration(IntegrationAutoConfiguration.class)
public class ExampleJdbcTests { class ExampleJdbcTests {
} }
---- ----
......
...@@ -18,20 +18,17 @@ package org.springframework.boot.docs.test.autoconfigure.restdocs.webclient; ...@@ -18,20 +18,17 @@ package org.springframework.boot.docs.test.autoconfigure.restdocs.webclient;
// tag::source[] // tag::source[]
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient;
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document; import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
@ExtendWith(SpringExtension.class)
@WebFluxTest @WebFluxTest
@AutoConfigureRestDocs @AutoConfigureRestDocs
public class UsersDocumentationTests { class UsersDocumentationTests {
@Autowired @Autowired
private WebTestClient webTestClient; private WebTestClient webTestClient;
......
...@@ -20,6 +20,7 @@ package org.springframework.boot.docs.test.web; ...@@ -20,6 +20,7 @@ package org.springframework.boot.docs.test.web;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
...@@ -33,7 +34,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -33,7 +34,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
class MockMvcExampleTests { class MockMvcExampleTests {
@Test @Test
void exampleTest(MockMvc mvc) throws Exception { void exampleTest(@Autowired MockMvc mvc) throws Exception {
mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Hello World")); mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Hello World"));
} }
......
...@@ -26,7 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; ...@@ -26,7 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class RandomPortWebTestClientExampleTests { class RandomPortWebTestClientExampleTests {
@Test @Test
void exampleTest(@Autowired WebTestClient webClient) { void exampleTest(@Autowired WebTestClient webClient) {
......
...@@ -19,7 +19,6 @@ package org.springframework.boot.docs.web.client; ...@@ -19,7 +19,6 @@ package org.springframework.boot.docs.web.client;
import java.time.Duration; import java.time.Duration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -29,7 +28,6 @@ import org.springframework.boot.test.web.client.TestRestTemplate; ...@@ -29,7 +28,6 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -39,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -39,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
// tag::test[] // tag::test[]
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class SampleWebClientTests { class SampleWebClientTests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment