1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .test .web .servlet ;
18
18
19
- import org .junit .jupiter .api .BeforeEach ;
20
19
import org .junit .jupiter .api .Test ;
21
- import org .junit .jupiter .api .extension .ExtendWith ;
20
+ import org .junit .jupiter .api .TestInstance ;
21
+ import org .junit .jupiter .api .TestInstance .Lifecycle ;
22
22
23
- import org .springframework .beans .factory .annotation .Autowired ;
24
23
import org .springframework .context .annotation .Bean ;
25
24
import org .springframework .context .annotation .Configuration ;
26
- import org .springframework .test .context .ContextConfiguration ;
27
- import org .springframework .test .context .junit .jupiter .SpringExtension ;
28
- import org .springframework .test .context .web .WebAppConfiguration ;
29
- import org .springframework .web .bind .annotation .RequestMapping ;
25
+ import org .springframework .test .context .junit .jupiter .web .SpringJUnitWebConfig ;
26
+ import org .springframework .web .bind .annotation .GetMapping ;
30
27
import org .springframework .web .bind .annotation .RestController ;
31
28
import org .springframework .web .context .WebApplicationContext ;
32
29
import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
47
44
* @author Rob Winch
48
45
* @since 4.2
49
46
*/
50
- @ ExtendWith (SpringExtension .class )
51
- @ ContextConfiguration
52
- @ WebAppConfiguration
53
- public class MockMvcReuseTests {
47
+ @ SpringJUnitWebConfig
48
+ @ TestInstance (Lifecycle .PER_CLASS )
49
+ class MockMvcReuseTests {
54
50
55
51
private static final String HELLO = "hello" ;
56
52
private static final String ENIGMA = "enigma" ;
57
53
private static final String FOO = "foo" ;
58
54
private static final String BAR = "bar" ;
59
55
60
- @ Autowired
61
- private WebApplicationContext wac ;
56
+ private final MockMvc mvc ;
62
57
63
- private MockMvc mvc ;
64
58
65
-
66
- @ BeforeEach
67
- public void setUp () {
68
- this .mvc = webAppContextSetup (this .wac ).build ();
59
+ MockMvcReuseTests (WebApplicationContext wac ) {
60
+ this .mvc = webAppContextSetup (wac ).build ();
69
61
}
70
62
63
+
71
64
@ Test
72
- public void sessionAttributesAreClearedBetweenInvocations () throws Exception {
65
+ void sessionAttributesAreClearedBetweenInvocations () throws Exception {
73
66
74
67
this .mvc .perform (get ("/" ))
75
68
.andExpect (content ().string (HELLO ))
@@ -85,7 +78,7 @@ public void sessionAttributesAreClearedBetweenInvocations() throws Exception {
85
78
}
86
79
87
80
@ Test
88
- public void requestParametersAreClearedBetweenInvocations () throws Exception {
81
+ void requestParametersAreClearedBetweenInvocations () throws Exception {
89
82
this .mvc .perform (get ("/" ))
90
83
.andExpect (content ().string (HELLO ));
91
84
@@ -102,21 +95,21 @@ public void requestParametersAreClearedBetweenInvocations() throws Exception {
102
95
static class Config {
103
96
104
97
@ Bean
105
- public MyController myController () {
98
+ MyController myController () {
106
99
return new MyController ();
107
100
}
108
101
}
109
102
110
103
@ RestController
111
104
static class MyController {
112
105
113
- @ RequestMapping ("/" )
114
- public String hello () {
106
+ @ GetMapping ("/" )
107
+ String hello () {
115
108
return HELLO ;
116
109
}
117
110
118
- @ RequestMapping (path = "/" , params = ENIGMA )
119
- public String enigma () {
111
+ @ GetMapping (path = "/" , params = ENIGMA )
112
+ String enigma () {
120
113
return ENIGMA ;
121
114
}
122
115
}
0 commit comments