Replace WebMvcConfigurerAdapter with default methods

Issue: SPR-15465
This commit is contained in:
Rossen Stoyanchev
2017-04-20 16:13:08 -04:00
parent d3b178a812
commit 7df3d68b2a
21 changed files with 165 additions and 123 deletions

View File

@@ -46,8 +46,13 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
import org.springframework.web.util.UrlPathHelper;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.verify;
/**
* A test fixture for {@link DelegatingWebMvcConfiguration} tests.
@@ -118,7 +123,7 @@ public class DelegatingWebMvcConfigurationTests {
final HttpMessageConverter customConverter = mock(HttpMessageConverter.class);
final StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
List<WebMvcConfigurer> configurers = new ArrayList<>();
configurers.add(new WebMvcConfigurerAdapter() {
configurers.add(new WebMvcConfigurer() {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(stringConverter);
@@ -176,7 +181,7 @@ public class DelegatingWebMvcConfigurationTests {
@Test
public void configureExceptionResolvers() throws Exception {
List<WebMvcConfigurer> configurers = new ArrayList<>();
configurers.add(new WebMvcConfigurerAdapter() {
configurers.add(new WebMvcConfigurer() {
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
exceptionResolvers.add(new DefaultHandlerExceptionResolver());
@@ -195,7 +200,7 @@ public class DelegatingWebMvcConfigurationTests {
final UrlPathHelper pathHelper = mock(UrlPathHelper.class);
List<WebMvcConfigurer> configurers = new ArrayList<>();
configurers.add(new WebMvcConfigurerAdapter() {
configurers.add(new WebMvcConfigurer() {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseRegisteredSuffixPatternMatch(true)

View File

@@ -40,7 +40,7 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for view resolution with {@code @EnableWebMvc}.
@@ -128,7 +128,7 @@ public class ViewResolutionIntegrationTests {
}
@EnableWebMvc
static abstract class AbstractWebConfig extends WebMvcConfigurerAdapter {
static abstract class AbstractWebConfig implements WebMvcConfigurer {
@Bean
public SampleController sampleController() {

View File

@@ -18,7 +18,6 @@ package org.springframework.web.servlet.config.annotation;
import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -363,7 +362,7 @@ public class WebMvcConfigurationSupportTests {
@EnableWebMvc
@Configuration
static class CustomViewResolverOrderConfig extends WebMvcConfigurerAdapter {
static class CustomViewResolverOrderConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
@@ -374,7 +373,7 @@ public class WebMvcConfigurationSupportTests {
@EnableWebMvc
@Configuration
static class CustomArgumentResolverConfig extends WebMvcConfigurerAdapter {
static class CustomArgumentResolverConfig implements WebMvcConfigurer {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {

View File

@@ -50,13 +50,21 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.*;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromController;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMethodCall;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMethodName;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.on;
/**
* Unit tests for {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
@@ -500,7 +508,7 @@ public class MvcUriComponentsBuilderTests {
@EnableWebMvc
static class WebConfig extends WebMvcConfigurerAdapter {
static class WebConfig implements WebMvcConfigurer {
@Bean
public PersonsAddressesController controller() {

View File

@@ -65,10 +65,10 @@ import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static org.junit.Assert.*;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import static org.junit.Assert.assertEquals;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
/**
* Test access to parts of a multipart request with {@link RequestPart}.
@@ -198,7 +198,7 @@ public class RequestPartIntegrationTests {
@Configuration
@EnableWebMvc
static class RequestPartTestConfig extends WebMvcConfigurerAdapter {
static class RequestPartTestConfig implements WebMvcConfigurer {
@Bean
public RequestPartTestController controller() {