Fix warnings

This commit is contained in:
Rossen Stoyanchev 2015-12-22 16:16:51 -05:00
parent 12b73caa84
commit 74b77e0d74
2 changed files with 26 additions and 19 deletions

View File

@ -19,7 +19,7 @@ package org.springframework.web.servlet.mvc.method.annotation;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.io.Writer; import java.io.Writer;
import java.util.Arrays; import java.util.Collections;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -34,7 +34,6 @@ import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
@ -44,7 +43,11 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler; import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* Test fixture with {@link ExceptionHandlerExceptionResolver}. * Test fixture with {@link ExceptionHandlerExceptionResolver}.
@ -54,6 +57,7 @@ import static org.junit.Assert.*;
* @author Kazuki Shimizu * @author Kazuki Shimizu
* @since 3.1 * @since 3.1
*/ */
@SuppressWarnings("unused")
public class ExceptionHandlerExceptionResolverTests { public class ExceptionHandlerExceptionResolverTests {
private static int RESOLVER_COUNT; private static int RESOLVER_COUNT;
@ -83,6 +87,7 @@ public class ExceptionHandlerExceptionResolverTests {
} }
@SuppressWarnings("ConstantConditions")
@Test @Test
public void nullHandler() { public void nullHandler() {
Object handler = null; Object handler = null;
@ -94,7 +99,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test @Test
public void setCustomArgumentResolvers() throws Exception { public void setCustomArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.resolver.setCustomArgumentResolvers(Arrays.asList(resolver)); this.resolver.setCustomArgumentResolvers(Collections.singletonList(resolver));
this.resolver.afterPropertiesSet(); this.resolver.afterPropertiesSet();
assertTrue(this.resolver.getArgumentResolvers().getResolvers().contains(resolver)); assertTrue(this.resolver.getArgumentResolvers().getResolvers().contains(resolver));
@ -104,7 +109,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test @Test
public void setArgumentResolvers() throws Exception { public void setArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.resolver.setArgumentResolvers(Arrays.asList(resolver)); this.resolver.setArgumentResolvers(Collections.singletonList(resolver));
this.resolver.afterPropertiesSet(); this.resolver.afterPropertiesSet();
assertMethodProcessorCount(1, HANDLER_COUNT); assertMethodProcessorCount(1, HANDLER_COUNT);
@ -113,7 +118,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test @Test
public void setCustomReturnValueHandlers() { public void setCustomReturnValueHandlers() {
HandlerMethodReturnValueHandler handler = new ViewNameMethodReturnValueHandler(); HandlerMethodReturnValueHandler handler = new ViewNameMethodReturnValueHandler();
this.resolver.setCustomReturnValueHandlers(Arrays.asList(handler)); this.resolver.setCustomReturnValueHandlers(Collections.singletonList(handler));
this.resolver.afterPropertiesSet(); this.resolver.afterPropertiesSet();
assertTrue(this.resolver.getReturnValueHandlers().getHandlers().contains(handler)); assertTrue(this.resolver.getReturnValueHandlers().getHandlers().contains(handler));
@ -123,7 +128,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test @Test
public void setReturnValueHandlers() { public void setReturnValueHandlers() {
HandlerMethodReturnValueHandler handler = new ModelMethodProcessor(); HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
this.resolver.setReturnValueHandlers(Arrays.asList(handler)); this.resolver.setReturnValueHandlers(Collections.singletonList(handler));
this.resolver.afterPropertiesSet(); this.resolver.afterPropertiesSet();
assertMethodProcessorCount(RESOLVER_COUNT, 1); assertMethodProcessorCount(RESOLVER_COUNT, 1);

View File

@ -28,6 +28,7 @@ import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler; import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
import org.springframework.web.method.ControllerAdviceBean; import org.springframework.web.method.ControllerAdviceBean;
/** /**
* A sub-class of {@link SimpAnnotationMethodMessageHandler} to provide support * A sub-class of {@link SimpAnnotationMethodMessageHandler} to provide support
* for {@link org.springframework.web.bind.annotation.ControllerAdvice * for {@link org.springframework.web.bind.annotation.ControllerAdvice
@ -38,8 +39,9 @@ import org.springframework.web.method.ControllerAdviceBean;
*/ */
public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMethodMessageHandler { public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMethodMessageHandler {
public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel, MessageChannel clientOutChannel,
SimpMessageSendingOperations brokerTemplate) { public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel,
MessageChannel clientOutChannel, SimpMessageSendingOperations brokerTemplate) {
super(clientInChannel, clientOutChannel, brokerTemplate); super(clientInChannel, clientOutChannel, brokerTemplate);
} }
@ -58,9 +60,9 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Looking for @MessageExceptionHandler mappings: " + getApplicationContext()); logger.debug("Looking for @MessageExceptionHandler mappings: " + getApplicationContext());
} }
List<ControllerAdviceBean> controllerAdvice = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext()); List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
AnnotationAwareOrderComparator.sort(controllerAdvice); AnnotationAwareOrderComparator.sort(beans);
initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(controllerAdvice)); initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(beans));
} }
private void initMessagingAdviceCache(List<MessagingAdviceBean> beans) { private void initMessagingAdviceCache(List<MessagingAdviceBean> beans) {
@ -68,8 +70,8 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
return; return;
} }
for (MessagingAdviceBean bean : beans) { for (MessagingAdviceBean bean : beans) {
Class<?> beanType = bean.getBeanType(); Class<?> type = bean.getBeanType();
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(beanType); AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(type);
if (resolver.hasExceptionMappings()) { if (resolver.hasExceptionMappings()) {
registerExceptionHandlerAdvice(bean, resolver); registerExceptionHandlerAdvice(bean, resolver);
logger.info("Detected @MessageExceptionHandler methods in " + bean); logger.info("Detected @MessageExceptionHandler methods in " + bean);
@ -89,12 +91,12 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
this.adviceBean = adviceBean; this.adviceBean = adviceBean;
} }
public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> controllerAdvice) { public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> beans) {
List<MessagingAdviceBean> messagingAdvice = new ArrayList<MessagingAdviceBean>(controllerAdvice.size()); List<MessagingAdviceBean> result = new ArrayList<MessagingAdviceBean>(beans.size());
for (ControllerAdviceBean bean : controllerAdvice) { for (ControllerAdviceBean bean : beans) {
messagingAdvice.add(new MessagingControllerAdviceBean(bean)); result.add(new MessagingControllerAdviceBean(bean));
} }
return messagingAdvice; return result;
} }
@Override @Override