From 1ee0626c94e6862fc21c99257e53433ee7ce4d36 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 17 Feb 2017 21:06:58 +0100 Subject: [PATCH] Polishing --- .../MethodValidationInterceptor.java | 6 ++--- .../MethodValidationPostProcessor.java | 8 +++--- .../ModelAttributeMethodProcessor.java | 5 ++-- ...essageConverterMethodArgumentResolver.java | 4 +-- .../ServletInvocableHandlerMethod.java | 6 ++--- .../web/servlet/config/MvcNamespaceTests.java | 25 +++++++++++-------- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java index 75c76ca3dd..9ccb286462 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,14 +47,12 @@ import org.springframework.validation.annotation.Validated; * at the type level of the containing target class, applying to all public service methods * of that class. By default, JSR-303 will validate against its default group only. * - *

As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider - * (such as Hibernate Validator 5.x). + *

As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider. * * @author Juergen Hoeller * @since 3.1 * @see MethodValidationPostProcessor * @see javax.validation.executable.ExecutableValidator - * @see org.hibernate.validator.method.MethodValidator */ public class MethodValidationInterceptor implements MethodInterceptor { diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java index 1ddd851a9c..00d0a967f1 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,14 +48,12 @@ import org.springframework.validation.annotation.Validated; * inline constraint annotations. Validation groups can be specified through {@code @Validated} * as well. By default, JSR-303 will validate against its default group only. * - *

As of Spring 4.0, this functionality requires either a Bean Validation 1.1 provider - * (such as Hibernate Validator 5.x) or the Bean Validation 1.0 API with Hibernate Validator - * 4.3. The actual provider will be autodetected and automatically adapted. + *

As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider. * * @author Juergen Hoeller * @since 3.1 * @see MethodValidationInterceptor - * @see org.hibernate.validator.method.MethodValidator + * @see javax.validation.executable.ExecutableValidator */ @SuppressWarnings("serial") public class MethodValidationPostProcessor extends AbstractBeanFactoryAwareAdvisingPostProcessor diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java index 8c82eefdd5..755de18e31 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,8 +54,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; * @author Rossen Stoyanchev * @since 3.1 */ -public class ModelAttributeMethodProcessor - implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler { +public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler { protected final Log logger = LogFactory.getLog(getClass()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java index 9222449adf..d49861df48 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -250,7 +250,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements } /** - * Validate the request part if applicable. + * Validate the binding target if applicable. *

The default implementation checks for {@code @javax.validation.Valid}, * Spring's {@link org.springframework.validation.annotation.Validated}, * and custom annotations whose name starts with "Valid". diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java index 541eae2690..d1f7a1e009 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,8 +110,8 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { * @param mavContainer the ModelAndViewContainer for this request * @param providedArgs "given" arguments matched by type (not resolved) */ - public void invokeAndHandle(ServletWebRequest webRequest, - ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception { + public void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer mavContainer, + Object... providedArgs) throws Exception { Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs); setResponseStatus(webRequest); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java index 160149be1f..ff316d5173 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,7 +142,6 @@ import org.springframework.web.servlet.view.tiles3.TilesConfigurer; import org.springframework.web.servlet.view.tiles3.TilesViewResolver; import org.springframework.web.util.UrlPathHelper; -import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @@ -159,7 +158,9 @@ import static org.junit.Assert.*; */ public class MvcNamespaceTests { - public static final String VIEWCONTROLLER_BEAN_NAME = "org.springframework.web.servlet.config.viewControllerHandlerMapping"; + public static final String VIEWCONTROLLER_BEAN_NAME = + "org.springframework.web.servlet.config.viewControllerHandlerMapping"; + private GenericWebApplicationContext appContext; @@ -197,7 +198,7 @@ public class MvcNamespaceTests { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json"); NativeWebRequest webRequest = new ServletWebRequest(request); ContentNegotiationManager manager = mapping.getContentNegotiationManager(); - assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest)); + assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest)); RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class); assertNotNull(adapter); @@ -697,7 +698,8 @@ public class MvcNamespaceTests { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml"); NativeWebRequest webRequest = new ServletWebRequest(request); - assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest)); + assertEquals(Collections.singletonList(MediaType.valueOf("application/rss+xml")), + manager.resolveMediaTypes(webRequest)); ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class); assertNotNull(compositeResolver); @@ -882,7 +884,7 @@ public class MvcNamespaceTests { assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray()); assertNull(config.getExposedHeaders()); assertTrue(config.getAllowCredentials()); - assertEquals(new Long(1800), config.getMaxAge()); + assertEquals(Long.valueOf(1800), config.getMaxAge()); } } @@ -905,14 +907,14 @@ public class MvcNamespaceTests { assertArrayEquals(new String[]{"header1", "header2", "header3"}, config.getAllowedHeaders().toArray()); assertArrayEquals(new String[]{"header1", "header2"}, config.getExposedHeaders().toArray()); assertFalse(config.getAllowCredentials()); - assertEquals(new Long(123), config.getMaxAge()); + assertEquals(Long.valueOf(123), config.getMaxAge()); config = configs.get("/resources/**"); assertArrayEquals(new String[]{"http://domain1.com"}, config.getAllowedOrigins().toArray()); assertArrayEquals(new String[]{"GET", "HEAD", "POST"}, config.getAllowedMethods().toArray()); assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray()); assertNull(config.getExposedHeaders()); assertTrue(config.getAllowCredentials()); - assertEquals(new Long(1800), config.getMaxAge()); + assertEquals(Long.valueOf(1800), config.getMaxAge()); } } @@ -928,21 +930,21 @@ public class MvcNamespaceTests { @DateTimeFormat(iso = ISO.DATE) - @Target({ElementType.PARAMETER}) + @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface IsoDate { } @NumberFormat(style = NumberFormat.Style.PERCENT) - @Target({ElementType.PARAMETER}) + @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface PercentNumber { } @Validated(MyGroup.class) - @Target({ElementType.PARAMETER}) + @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface MyValid { } @@ -961,6 +963,7 @@ public class MvcNamespaceTests { public void testBind(@RequestParam @IsoDate Date date, @RequestParam(required = false) @PercentNumber Double percent, @MyValid TestBean bean, BindingResult result) { + this.date = date; this.percent = percent; this.recordedValidationError = (result.getErrorCount() == 1);