Skip to content

Commit 038266a

Browse files
nor-ekjzheaux
authored andcommitted
Update JUnit 5 annotations in documentation
- replace Before with BeforeEach - replace RunWith with ExtendWith Closes gh-10934
1 parent cf559ab commit 038266a

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

docs/modules/ROOT/pages/reactive/test/method.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Here is a minimal sample of what we can do:
88
.Java
99
[source,java,role="primary"]
1010
----
11-
@RunWith(SpringRunner.class)
11+
@ExtendWith(SpringExtension.class)
1212
@ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
1313
public class HelloWorldMessageServiceTests {
1414
@Autowired
@@ -42,7 +42,7 @@ public class HelloWorldMessageServiceTests {
4242
.Kotlin
4343
[source,kotlin,role="secondary"]
4444
----
45-
@RunWith(SpringRunner::class)
45+
@ExtendWith(SpringExtension.class)
4646
@ContextConfiguration(classes = [HelloWebfluxMethodApplication::class])
4747
class HelloWorldMessageServiceTests {
4848
@Autowired

docs/modules/ROOT/pages/reactive/test/web/setup.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ The basic setup looks like this:
44

55
[source,java]
66
----
7-
@RunWith(SpringRunner.class)
7+
@ExtendWith(SpringExtension.class)
88
@ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
99
public class HelloWebfluxMethodApplicationTests {
1010
@Autowired
1111
ApplicationContext context;
1212
1313
WebTestClient rest;
1414
15-
@Before
15+
@BeforeEach
1616
public void setup() {
1717
this.rest = WebTestClient
1818
.bindToApplicationContext(this.context)

docs/modules/ROOT/pages/servlet/test/method.adoc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,22 @@ Before we can use Spring Security Test support, we must perform some setup. An e
4949
.Java
5050
[source,java,role="primary"]
5151
----
52-
@RunWith(SpringJUnit4ClassRunner.class) // <1>
52+
@ExtendWith(SpringExtension.class) // <1>
5353
@ContextConfiguration // <2>
5454
public class WithMockUserTests {
5555
----
5656
5757
.Kotlin
5858
[source,kotlin,role="secondary"]
5959
----
60-
@RunWith(SpringJUnit4ClassRunner::class)
60+
@ExtendWith(SpringExtension.class)
6161
@ContextConfiguration
6262
class WithMockUserTests {
6363
----
64-
====
6564
6665
This is a basic example of how to setup Spring Security Test. The highlights are:
6766
68-
<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]
67+
<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].
6968
<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]
7069
7170
NOTE: Spring Security hooks into Spring Test support using the `WithSecurityContextTestExecutionListener` which will ensure our tests are ran with the correct user.
@@ -225,7 +224,7 @@ For example, the following would run every test with a user with the username "a
225224
.Java
226225
[source,java,role="primary"]
227226
----
228-
@RunWith(SpringJUnit4ClassRunner.class)
227+
@ExtendWith(SpringExtension.class)
229228
@ContextConfiguration
230229
@WithMockUser(username="admin",roles={"USER","ADMIN"})
231230
public class WithMockUserTests {
@@ -234,7 +233,7 @@ public class WithMockUserTests {
234233
.Kotlin
235234
[source,kotlin,role="secondary"]
236235
----
237-
@RunWith(SpringJUnit4ClassRunner::class)
236+
@ExtendWith(SpringExtension.class)
238237
@ContextConfiguration
239238
@WithMockUser(username="admin",roles=["USER","ADMIN"])
240239
class WithMockUserTests {
@@ -304,7 +303,7 @@ For example, the following will run withMockUser1 and withMockUser2 using <<test
304303
.Java
305304
[source,java,role="primary"]
306305
----
307-
@RunWith(SpringJUnit4ClassRunner.class)
306+
@ExtendWith(SpringExtension.class)
308307
@WithMockUser
309308
public class WithUserClassLevelAuthenticationTests {
310309
@@ -327,7 +326,7 @@ public class WithUserClassLevelAuthenticationTests {
327326
.Kotlin
328327
[source,kotlin,role="secondary"]
329328
----
330-
@RunWith(SpringJUnit4ClassRunner::class)
329+
@ExtendWith(SpringExtension.class)
331330
@WithMockUser
332331
class WithUserClassLevelAuthenticationTests {
333332
@Test

docs/modules/ROOT/pages/servlet/test/mockmvc/setup.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ NOTE: Spring Security's testing support requires spring-test-4.1.3.RELEASE or gr
1515
1616
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
1717
18-
@RunWith(SpringJUnit4ClassRunner.class)
18+
@ExtendWith(SpringExtension.class)
1919
@ContextConfiguration(classes = SecurityConfig.class)
2020
@WebAppConfiguration
2121
public class CsrfShowcaseTests {
@@ -25,7 +25,7 @@ public class CsrfShowcaseTests {
2525
2626
private MockMvc mvc;
2727
28-
@Before
28+
@BeforeEach
2929
public void setup() {
3030
mvc = MockMvcBuilders
3131
.webAppContextSetup(context)
@@ -39,7 +39,7 @@ public class CsrfShowcaseTests {
3939
.Kotlin
4040
[source,kotlin,role="secondary"]
4141
----
42-
@RunWith(SpringJUnit4ClassRunner::class)
42+
@ExtendWith(SpringExtension.class)
4343
@ContextConfiguration(classes = [SecurityConfig::class])
4444
@WebAppConfiguration
4545
class CsrfShowcaseTests {
@@ -49,7 +49,7 @@ class CsrfShowcaseTests {
4949
5050
private var mvc: MockMvc? = null
5151
52-
@Before
52+
@BeforeEach
5353
fun setup() {
5454
mvc = MockMvcBuilders
5555
.webAppContextSetup(context)

0 commit comments

Comments
 (0)