16
16
17
17
package org .springframework .test .web .reactive .server .samples .bind ;
18
18
19
- import org .junit .jupiter .api .BeforeEach ;
20
19
import org .junit .jupiter .api .Test ;
21
20
22
- import org .springframework .context . annotation .AnnotationConfigApplicationContext ;
23
- import org .springframework .context .annotation . Bean ;
21
+ import org .springframework .beans . factory . annotation .Autowired ;
22
+ import org .springframework .context .ApplicationContext ;
24
23
import org .springframework .context .annotation .Configuration ;
24
+ import org .springframework .context .annotation .Import ;
25
+ import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
25
26
import org .springframework .test .web .reactive .server .WebTestClient ;
26
27
import org .springframework .web .bind .annotation .GetMapping ;
27
28
import org .springframework .web .bind .annotation .RestController ;
34
35
* @author Rossen Stoyanchev
35
36
* @since 5.0
36
37
*/
37
- public class ApplicationContextTests {
38
+ @ SpringJUnitConfig
39
+ class ApplicationContextTests {
38
40
39
- private WebTestClient client ;
41
+ @ Autowired
42
+ ApplicationContext context ;
40
43
41
44
42
- @ BeforeEach
43
- public void setUp () throws Exception {
44
-
45
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
46
- context .register (WebConfig .class );
47
- context .refresh ();
48
-
49
- this .client = WebTestClient .bindToApplicationContext (context ).build ();
50
- }
51
-
52
45
@ Test
53
- public void test () throws Exception {
54
- this .client .get ().uri ("/test" )
46
+ void buildWithDefaults () {
47
+ var client = WebTestClient .bindToApplicationContext (context ).build ();
48
+
49
+ client .get ().uri ("/test" )
55
50
.exchange ()
56
51
.expectStatus ().isOk ()
57
52
.expectBody (String .class ).isEqualTo ("It works!" );
@@ -60,20 +55,15 @@ public void test() throws Exception {
60
55
61
56
@ Configuration
62
57
@ EnableWebFlux
63
- static class WebConfig {
64
-
65
- @ Bean
66
- public TestController controller () {
67
- return new TestController ();
68
- }
69
-
58
+ @ Import (TestController .class )
59
+ static class WebFluxConfig {
70
60
}
71
61
72
62
@ RestController
73
63
static class TestController {
74
64
75
65
@ GetMapping ("/test" )
76
- public String handle () {
66
+ String test () {
77
67
return "It works!" ;
78
68
}
79
69
}
0 commit comments