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.UnsupportedEncodingException;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Before;
import org.junit.BeforeClass;
@ -34,7 +34,6 @@ import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.ResponseBody;
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.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}.
@ -54,6 +57,7 @@ import static org.junit.Assert.*;
* @author Kazuki Shimizu
* @since 3.1
*/
@SuppressWarnings("unused")
public class ExceptionHandlerExceptionResolverTests {
private static int RESOLVER_COUNT;
@ -83,6 +87,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
@SuppressWarnings("ConstantConditions")
@Test
public void nullHandler() {
Object handler = null;
@ -94,7 +99,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test
public void setCustomArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.resolver.setCustomArgumentResolvers(Arrays.asList(resolver));
this.resolver.setCustomArgumentResolvers(Collections.singletonList(resolver));
this.resolver.afterPropertiesSet();
assertTrue(this.resolver.getArgumentResolvers().getResolvers().contains(resolver));
@ -104,7 +109,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test
public void setArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.resolver.setArgumentResolvers(Arrays.asList(resolver));
this.resolver.setArgumentResolvers(Collections.singletonList(resolver));
this.resolver.afterPropertiesSet();
assertMethodProcessorCount(1, HANDLER_COUNT);
@ -113,7 +118,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test
public void setCustomReturnValueHandlers() {
HandlerMethodReturnValueHandler handler = new ViewNameMethodReturnValueHandler();
this.resolver.setCustomReturnValueHandlers(Arrays.asList(handler));
this.resolver.setCustomReturnValueHandlers(Collections.singletonList(handler));
this.resolver.afterPropertiesSet();
assertTrue(this.resolver.getReturnValueHandlers().getHandlers().contains(handler));
@ -123,7 +128,7 @@ public class ExceptionHandlerExceptionResolverTests {
@Test
public void setReturnValueHandlers() {
HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
this.resolver.setReturnValueHandlers(Arrays.asList(handler));
this.resolver.setReturnValueHandlers(Collections.singletonList(handler));
this.resolver.afterPropertiesSet();
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.web.method.ControllerAdviceBean;
/**
* A sub-class of {@link SimpAnnotationMethodMessageHandler} to provide support
* for {@link org.springframework.web.bind.annotation.ControllerAdvice
@ -38,8 +39,9 @@ import org.springframework.web.method.ControllerAdviceBean;
*/
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);
}
@ -58,9 +60,9 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
if (logger.isDebugEnabled()) {
logger.debug("Looking for @MessageExceptionHandler mappings: " + getApplicationContext());
}
List<ControllerAdviceBean> controllerAdvice = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
AnnotationAwareOrderComparator.sort(controllerAdvice);
initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(controllerAdvice));
List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
AnnotationAwareOrderComparator.sort(beans);
initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(beans));
}
private void initMessagingAdviceCache(List<MessagingAdviceBean> beans) {
@ -68,8 +70,8 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
return;
}
for (MessagingAdviceBean bean : beans) {
Class<?> beanType = bean.getBeanType();
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(beanType);
Class<?> type = bean.getBeanType();
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(type);
if (resolver.hasExceptionMappings()) {
registerExceptionHandlerAdvice(bean, resolver);
logger.info("Detected @MessageExceptionHandler methods in " + bean);
@ -89,12 +91,12 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
this.adviceBean = adviceBean;
}
public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> controllerAdvice) {
List<MessagingAdviceBean> messagingAdvice = new ArrayList<MessagingAdviceBean>(controllerAdvice.size());
for (ControllerAdviceBean bean : controllerAdvice) {
messagingAdvice.add(new MessagingControllerAdviceBean(bean));
public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> beans) {
List<MessagingAdviceBean> result = new ArrayList<MessagingAdviceBean>(beans.size());
for (ControllerAdviceBean bean : beans) {
result.add(new MessagingControllerAdviceBean(bean));
}
return messagingAdvice;
return result;
}
@Override