Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation to use JUnit Jupiter #17507

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7038,9 +7038,8 @@ property:

[source,java,indent=0]
----
@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.main.web-application-type=reactive")
public class MyWebFluxTests { ... }
class MyWebFluxTests { ... }
----


Expand Down Expand Up @@ -7103,10 +7102,10 @@ that class explicitly where it is required, as shown in the following example:
----
@SpringBootTest
@Import(MyTestsConfiguration.class)
public class MyTests {
class MyTests {

@Test
public void exampleTest() {
void exampleTest() {
...
}

Expand Down Expand Up @@ -7360,7 +7359,7 @@ Strings respectively. Any helper fields on the test class can be `@Autowired` wh
}

@Test
public void testDeserialize() throws Exception {
void testDeserialize() throws Exception {
String content = "{\"make\":\"Ford\",\"model\":\"Focus\"}";
assertThat(this.json.parse(content))
.isEqualTo(new VehicleDetails("Ford", "Focus"));
Expand Down Expand Up @@ -7651,10 +7650,9 @@ following example:

[source,java,indent=0]
----
@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace=Replace.NONE)
public class ExampleRepositoryTests {
class ExampleRepositoryTests {

// ...

Expand Down Expand Up @@ -7780,7 +7778,7 @@ The following class shows the `@DataMongoTest` annotation in use:
import org.springframework.data.mongodb.core.MongoTemplate;

@DataMongoTest
public class ExampleDataMongoTests {
class ExampleDataMongoTests {

@Autowired
private MongoTemplate mongoTemplate;
Expand All @@ -7800,7 +7798,7 @@ the following example:
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;

@DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class)
public class ExampleDataMongoNonEmbeddedTests {
class ExampleDataMongoNonEmbeddedTests {

}
----
Expand All @@ -7827,7 +7825,7 @@ The following example shows a typical setup for using Neo4J tests in Spring Boot
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest;

@DataNeo4jTest
public class ExampleDataNeo4jTests {
class ExampleDataNeo4jTests {

@Autowired
private YourRepository repository;
Expand All @@ -7850,7 +7848,7 @@ as follows:

@DataNeo4jTest
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class ExampleNonTransactionalTests {
class ExampleNonTransactionalTests {

}
----
Expand All @@ -7876,7 +7874,7 @@ The following example shows the `@DataRedisTest` annotation in use:
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;

@DataRedisTest
public class ExampleDataRedisTests {
class ExampleDataRedisTests {

@Autowired
private YourRepository repository;
Expand Down Expand Up @@ -7907,7 +7905,7 @@ The following example shows the `@DataLdapTest` annotation in use:
import org.springframework.ldap.core.LdapTemplate;

@DataLdapTest
public class ExampleDataLdapTests {
class ExampleDataLdapTests {

@Autowired
private LdapTemplate ldapTemplate;
Expand All @@ -7927,7 +7925,7 @@ following example:
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest;

@DataLdapTest(excludeAutoConfiguration = EmbeddedLdapAutoConfiguration.class)
public class ExampleDataLdapNonEmbeddedTests {
class ExampleDataLdapNonEmbeddedTests {

}
----
Expand All @@ -7950,7 +7948,7 @@ The specific beans that you want to test should be specified by using the `value
[source,java,indent=0]
----
@RestClientTest(RemoteVehicleDetailsService.class)
public class ExampleRestClientTest {
class ExampleRestClientTest {

@Autowired
private RemoteVehicleDetailsService service;
Expand All @@ -7959,7 +7957,7 @@ The specific beans that you want to test should be specified by using the `value
private MockRestServiceServer server;

@Test
public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails()
void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails()
throws Exception {
this.server.expect(requestTo("/greet/details"))
.andRespond(withSuccess("hello", MediaType.TEXT_PLAIN));
Expand Down Expand Up @@ -8114,10 +8112,9 @@ simply by adding `@ImportAutoConfiguration` to the test as shown in the followin

[source,java,indent=0]
----
@RunWith(SpringRunner.class)
@JdbcTest
@ImportAutoConfiguration(IntegrationAutoConfiguration.class)
public class ExampleJdbcTests {
class ExampleJdbcTests {

}
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@

// tag::source[]
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
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 static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;

@ExtendWith(SpringExtension.class)
@WebFluxTest
@AutoConfigureRestDocs
public class UsersDocumentationTests {
class UsersDocumentationTests {

@Autowired
private WebTestClient webTestClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
Expand All @@ -33,7 +34,7 @@
class MockMvcExampleTests {

@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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.springframework.test.web.reactive.server.WebTestClient;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class RandomPortWebTestClientExampleTests {
class RandomPortWebTestClientExampleTests {

@Test
void exampleTest(@Autowired WebTestClient webClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.time.Duration;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -29,7 +28,6 @@
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -39,7 +37,6 @@
* @author Stephane Nicoll
*/
// tag::test[]
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class SampleWebClientTests {

Expand Down