瀏覽代碼

Update Junit5 annotations in documentation
- replace Before with BeforeEach
- replace RunWith with ExtendWith

Closes gh-10934

nor-ek 3 年之前
父節點
當前提交
416f94f979

+ 2 - 2
docs/modules/ROOT/pages/reactive/test/method.adoc

@@ -8,7 +8,7 @@ The following minimal sample shows what we can do:
 .Java
 .Java
 [source,java,role="primary"]
 [source,java,role="primary"]
 ----
 ----
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
 @ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
 public class HelloWorldMessageServiceTests {
 public class HelloWorldMessageServiceTests {
 	@Autowired
 	@Autowired
@@ -42,7 +42,7 @@ public class HelloWorldMessageServiceTests {
 .Kotlin
 .Kotlin
 [source,kotlin,role="secondary"]
 [source,kotlin,role="secondary"]
 ----
 ----
-@RunWith(SpringRunner::class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(classes = [HelloWebfluxMethodApplication::class])
 @ContextConfiguration(classes = [HelloWebfluxMethodApplication::class])
 class HelloWorldMessageServiceTests {
 class HelloWorldMessageServiceTests {
     @Autowired
     @Autowired

+ 2 - 2
docs/modules/ROOT/pages/reactive/test/web/setup.adoc

@@ -4,7 +4,7 @@ The basic setup looks like this:
 
 
 [source,java]
 [source,java]
 ----
 ----
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
 @ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
 public class HelloWebfluxMethodApplicationTests {
 public class HelloWebfluxMethodApplicationTests {
 	@Autowired
 	@Autowired
@@ -12,7 +12,7 @@ public class HelloWebfluxMethodApplicationTests {
 
 
 	WebTestClient rest;
 	WebTestClient rest;
 
 
-	@Before
+	@BeforeEach
 	public void setup() {
 	public void setup() {
 		this.rest = WebTestClient
 		this.rest = WebTestClient
 			.bindToApplicationContext(this.context)
 			.bindToApplicationContext(this.context)

+ 7 - 7
docs/modules/ROOT/pages/servlet/test/method.adoc

@@ -51,7 +51,7 @@ Before we can use the Spring Security test support, we must perform some setup:
 .Java
 .Java
 [source,java,role="primary"]
 [source,java,role="primary"]
 ----
 ----
-@RunWith(SpringJUnit4ClassRunner.class) // <1>
+@ExtendWith(SpringExtension.class) // <1>
 @ContextConfiguration // <2>
 @ContextConfiguration // <2>
 public class WithMockUserTests {
 public class WithMockUserTests {
 	// ...
 	// ...
@@ -61,13 +61,13 @@ public class WithMockUserTests {
 .Kotlin
 .Kotlin
 [source,kotlin,role="secondary"]
 [source,kotlin,role="secondary"]
 ----
 ----
-@RunWith(SpringJUnit4ClassRunner::class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration
 @ContextConfiguration
 class WithMockUserTests {
 class WithMockUserTests {
     // ...
     // ...
 }
 }
 ----
 ----
-<1> `@RunWith` instructs the spring-test module that it should create an `ApplicationContext`. This is no different than using the existing Spring Test support. For additional information, refer to the https://docs.spring.io/spring-framework/docs/4.0.x/spring-framework-reference/htmlsingle/#integration-testing-annotations-standard[Spring Reference]
+<1> `@ExtendWith` instructs the spring-test module that it should create an `ApplicationContext`. For additional information refer to https://docs.spring.io/spring-framework/docs/current/reference/html/testing.html#testcontext-junit-jupiter-extension[Spring reference].
 <2> `@ContextConfiguration` instructs the spring-test the configuration to use to create the `ApplicationContext`. Since no configuration is specified, the default configuration locations will be tried. This is no different than using the existing Spring Test support. For additional information, refer to the https://docs.spring.io/spring-framework/docs/4.0.x/spring-framework-reference/htmlsingle/#testcontext-ctx-management[Spring Reference]
 <2> `@ContextConfiguration` instructs the spring-test the configuration to use to create the `ApplicationContext`. Since no configuration is specified, the default configuration locations will be tried. This is no different than using the existing Spring Test support. For additional information, refer to the https://docs.spring.io/spring-framework/docs/4.0.x/spring-framework-reference/htmlsingle/#testcontext-ctx-management[Spring Reference]
 ====
 ====
 
 
@@ -233,7 +233,7 @@ The following example runs every test with a user whose username is `admin`, who
 .Java
 .Java
 [source,java,role="primary"]
 [source,java,role="primary"]
 ----
 ----
-@RunWith(SpringJUnit4ClassRunner.class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration
 @ContextConfiguration
 @WithMockUser(username="admin",roles={"USER","ADMIN"})
 @WithMockUser(username="admin",roles={"USER","ADMIN"})
 public class WithMockUserTests {
 public class WithMockUserTests {
@@ -244,7 +244,7 @@ public class WithMockUserTests {
 .Kotlin
 .Kotlin
 [source,kotlin,role="secondary"]
 [source,kotlin,role="secondary"]
 ----
 ----
-@RunWith(SpringJUnit4ClassRunner::class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration
 @ContextConfiguration
 @WithMockUser(username="admin",roles=["USER","ADMIN"])
 @WithMockUser(username="admin",roles=["USER","ADMIN"])
 class WithMockUserTests {
 class WithMockUserTests {
@@ -318,7 +318,7 @@ The following example runs `withMockUser1` and `withMockUser2` by using <<test-m
 .Java
 .Java
 [source,java,role="primary"]
 [source,java,role="primary"]
 ----
 ----
-@RunWith(SpringJUnit4ClassRunner.class)
+@ExtendWith(SpringExtension.class)
 @WithMockUser
 @WithMockUser
 public class WithUserClassLevelAuthenticationTests {
 public class WithUserClassLevelAuthenticationTests {
 
 
@@ -341,7 +341,7 @@ public class WithUserClassLevelAuthenticationTests {
 .Kotlin
 .Kotlin
 [source,kotlin,role="secondary"]
 [source,kotlin,role="secondary"]
 ----
 ----
-@RunWith(SpringJUnit4ClassRunner::class)
+@ExtendWith(SpringExtension.class)
 @WithMockUser
 @WithMockUser
 class WithUserClassLevelAuthenticationTests {
 class WithUserClassLevelAuthenticationTests {
     @Test
     @Test

+ 4 - 4
docs/modules/ROOT/pages/servlet/test/mockmvc/setup.adoc

@@ -17,7 +17,7 @@ To do so, use Spring Security's `SecurityMockMvcConfigurers.springSecurity()`:
 
 
 import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
 import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
 
 
-@RunWith(SpringJUnit4ClassRunner.class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(classes = SecurityConfig.class)
 @ContextConfiguration(classes = SecurityConfig.class)
 @WebAppConfiguration
 @WebAppConfiguration
 public class CsrfShowcaseTests {
 public class CsrfShowcaseTests {
@@ -27,7 +27,7 @@ public class CsrfShowcaseTests {
 
 
 	private MockMvc mvc;
 	private MockMvc mvc;
 
 
-	@Before
+	@BeforeEach
 	public void setup() {
 	public void setup() {
 		mvc = MockMvcBuilders
 		mvc = MockMvcBuilders
 				.webAppContextSetup(context)
 				.webAppContextSetup(context)
@@ -41,7 +41,7 @@ public class CsrfShowcaseTests {
 .Kotlin
 .Kotlin
 [source,kotlin,role="secondary"]
 [source,kotlin,role="secondary"]
 ----
 ----
-@RunWith(SpringJUnit4ClassRunner::class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(classes = [SecurityConfig::class])
 @ContextConfiguration(classes = [SecurityConfig::class])
 @WebAppConfiguration
 @WebAppConfiguration
 class CsrfShowcaseTests {
 class CsrfShowcaseTests {
@@ -51,7 +51,7 @@ class CsrfShowcaseTests {
 
 
     private var mvc: MockMvc? = null
     private var mvc: MockMvc? = null
 
 
-    @Before
+    @BeforeEach
     fun setup() {
     fun setup() {
         mvc = MockMvcBuilders
         mvc = MockMvcBuilders
             .webAppContextSetup(context)
             .webAppContextSetup(context)