Skip to content

Commit 19ddfad

Browse files
wilkinsonasnicoll
authored andcommitted
Migrate some more tests to the new ContextLoader
1 parent e91b4d0 commit 19ddfad

File tree

6 files changed

+665
-633
lines changed

6 files changed

+665
-633
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616

1717
package org.springframework.boot.autoconfigure.web.reactive;
1818

19-
import org.junit.Rule;
2019
import org.junit.Test;
21-
import org.junit.rules.ExpectedException;
2220

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;
2522
import org.springframework.context.annotation.Bean;
2623
import org.springframework.context.annotation.Configuration;
2724
import org.springframework.http.server.reactive.HttpHandler;
@@ -37,36 +34,27 @@
3734
*
3835
* @author Brian Clozel
3936
* @author Stephane Nicoll
37+
* @author Andy Wilkinson
4038
*/
4139
public class HttpHandlerAutoConfigurationTests {
4240

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);
4743

4844
@Test
4945
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+
});
5451
}
5552

5653
@Test
5754
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+
});
7058
}
7159

7260
@Configuration

0 commit comments

Comments
 (0)