|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.web.reactive;
|
18 | 18 |
|
19 |
| -import org.junit.Rule; |
20 | 19 | import org.junit.Test;
|
21 |
| -import org.junit.rules.ExpectedException; |
22 | 20 |
|
23 |
| -import org.springframework.boot.test.util.TestPropertyValues; |
24 |
| -import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; |
| 21 | +import org.springframework.boot.test.context.ContextLoader; |
25 | 22 | import org.springframework.context.annotation.Bean;
|
26 | 23 | import org.springframework.context.annotation.Configuration;
|
27 | 24 | import org.springframework.http.server.reactive.HttpHandler;
|
|
37 | 34 | *
|
38 | 35 | * @author Brian Clozel
|
39 | 36 | * @author Stephane Nicoll
|
| 37 | + * @author Andy Wilkinson |
40 | 38 | */
|
41 | 39 | public class HttpHandlerAutoConfigurationTests {
|
42 | 40 |
|
43 |
| - @Rule |
44 |
| - public ExpectedException thrown = ExpectedException.none(); |
45 |
| - |
46 |
| - private GenericReactiveWebApplicationContext context; |
| 41 | + private final ContextLoader contextLoader = new ContextLoader().webReactive() |
| 42 | + .autoConfig(HttpHandlerAutoConfiguration.class); |
47 | 43 |
|
48 | 44 | @Test
|
49 | 45 | public void shouldNotProcessIfExistingHttpHandler() {
|
50 |
| - load(CustomHttpHandler.class); |
51 |
| - assertThat(this.context.getBeansOfType(HttpHandler.class)).hasSize(1); |
52 |
| - assertThat(this.context.getBean(HttpHandler.class)) |
53 |
| - .isSameAs(this.context.getBean("customHttpHandler")); |
| 46 | + this.contextLoader.config(CustomHttpHandler.class).load(context -> { |
| 47 | + assertThat(context.getBeansOfType(HttpHandler.class)).hasSize(1); |
| 48 | + assertThat(context.getBean(HttpHandler.class)) |
| 49 | + .isSameAs(context.getBean("customHttpHandler")); |
| 50 | + }); |
54 | 51 | }
|
55 | 52 |
|
56 | 53 | @Test
|
57 | 54 | public void shouldConfigureHttpHandlerAnnotation() {
|
58 |
| - load(WebFluxAutoConfiguration.class); |
59 |
| - assertThat(this.context.getBeansOfType(HttpHandler.class).size()).isEqualTo(1); |
60 |
| - } |
61 |
| - |
62 |
| - private void load(Class<?> config, String... environment) { |
63 |
| - this.context = new GenericReactiveWebApplicationContext(); |
64 |
| - TestPropertyValues.of(environment).applyTo(this.context); |
65 |
| - if (this.context != null) { |
66 |
| - this.context.register(config); |
67 |
| - } |
68 |
| - this.context.register(HttpHandlerAutoConfiguration.class); |
69 |
| - this.context.refresh(); |
| 55 | + this.contextLoader.autoConfig(WebFluxAutoConfiguration.class).load(context -> { |
| 56 | + assertThat(context.getBeansOfType(HttpHandler.class).size()).isEqualTo(1); |
| 57 | + }); |
70 | 58 | }
|
71 | 59 |
|
72 | 60 | @Configuration
|
|
0 commit comments