Clean up warnings in spring-webmvc

This commit is contained in:
Sam Brannen 2018-04-04 14:04:54 +02:00
parent 2c648379ab
commit aba882af4c
49 changed files with 153 additions and 156 deletions

View File

@ -754,6 +754,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
private static class EmptyHandler {
@SuppressWarnings("unused")
public void handle() {
throw new UnsupportedOperationException("Not implemented");
}

View File

@ -447,6 +447,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
return result;
}
@SuppressWarnings("unused")
public HttpHeaders handle() {
return this.headers;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -287,7 +287,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
@Nullable
protected Object adaptArgumentIfNecessary(@Nullable Object arg, MethodParameter parameter) {
if (parameter.getParameterType() == Optional.class) {
if (arg == null || (arg instanceof Collection && ((Collection) arg).isEmpty()) ||
if (arg == null || (arg instanceof Collection && ((Collection<?>) arg).isEmpty()) ||
(arg instanceof Object[] && ((Object[]) arg).length == 0)) {
return Optional.empty();
}

View File

@ -190,7 +190,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
valueType = getReturnValueType(outputValue, returnType);
declaredType = getGenericType(returnType);
}
if (isResourceType(value, returnType)) {
outputMessage.getHeaders().set(HttpHeaders.ACCEPT_RANGES, "bytes");
if (value != null && inputMessage.getHeaders().getFirst(HttpHeaders.RANGE) != null) {
@ -262,7 +262,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
if (genericConverter != null ?
((GenericHttpMessageConverter) converter).canWrite(declaredType, valueType, selectedMediaType) :
converter.canWrite(valueType, selectedMediaType)) {
outputValue = (T) getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType,
outputValue = getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType,
(Class<? extends HttpMessageConverter<?>>) converter.getClass(),
inputMessage, outputMessage);
if (outputValue != null) {
@ -321,7 +321,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
/**
* @see #getProducibleMediaTypes(HttpServletRequest, Class, Type)
*/
@SuppressWarnings({"unchecked", "unused"})
@SuppressWarnings("unused")
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass) {
return getProducibleMediaTypes(request, valueClass, null);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -113,6 +113,7 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
}
@Override
@SuppressWarnings("resource")
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -57,6 +57,7 @@ public class StreamingResponseBodyReturnValueHandler implements HandlerMethodRet
}
@Override
@SuppressWarnings("resource")
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

View File

@ -118,6 +118,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
logger.trace("Transforming resource: " + resource);
}
@SuppressWarnings("resource")
Scanner scanner = new Scanner(content);
LineInfo previous = null;
LineAggregator aggregator = new LineAggregator(resource, content);

View File

@ -17,7 +17,6 @@
package org.springframework.web.servlet.resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -165,7 +165,7 @@ public class MarshallingView extends AbstractView {
Assert.state(this.marshaller != null, "No Marshaller set");
Class<?> classToCheck = value.getClass();
if (value instanceof JAXBElement) {
classToCheck = ((JAXBElement) value).getDeclaredType();
classToCheck = ((JAXBElement<?>) value).getDeclaredType();
}
return this.marshaller.supports(classToCheck);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@ -27,7 +27,7 @@ public class TestBean {
private String name;
private List list;
private List<?> list;
private Object objRef;
@ -48,14 +48,14 @@ public class TestBean {
/**
* @return Returns the list.
*/
public List getList() {
public List<?> getList() {
return list;
}
/**
* @param list The list to set.
*/
public void setList(List list) {
public void setList(List<?> list) {
this.list = list;
}
@ -72,4 +72,5 @@ public class TestBean {
public void setObjRef(Object object) {
this.objRef = object;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@ -24,7 +24,7 @@ import java.util.Map;
* @author Thomas Risberg
* @author Juergen Hoeller
*/
public class BeanThatListens implements ApplicationListener {
public class BeanThatListens implements ApplicationListener<ApplicationEvent> {
private BeanThatBroadcasts beanThatBroadcasts;
@ -36,7 +36,7 @@ public class BeanThatListens implements ApplicationListener {
public BeanThatListens(BeanThatBroadcasts beanThatBroadcasts) {
this.beanThatBroadcasts = beanThatBroadcasts;
Map beans = beanThatBroadcasts.applicationContext.getBeansOfType(BeanThatListens.class);
Map<String, BeanThatListens> beans = beanThatBroadcasts.applicationContext.getBeansOfType(BeanThatListens.class);
if (!beans.isEmpty()) {
throw new IllegalStateException("Shouldn't have found any BeanThatListens instances");
}

View File

@ -6,7 +6,7 @@ package org.springframework.context;
* @author Rod Johnson
* @since January 21, 2001
*/
public class TestListener implements ApplicationListener {
public class TestListener implements ApplicationListener<ApplicationEvent> {
private int eventCount;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -321,6 +321,7 @@ public class ContextLoaderTests {
}
@Test
@SuppressWarnings("resource")
public void testClassPathXmlApplicationContext() throws IOException {
ApplicationContext context = new ClassPathXmlApplicationContext(
"/org/springframework/web/context/WEB-INF/applicationContext.xml");
@ -338,30 +339,25 @@ public class ContextLoaderTests {
assertTrue("Has kerry", context.containsBean("kerry"));
}
@Test
@Test(expected = BeanCreationException.class)
@SuppressWarnings("resource")
public void testSingletonDestructionOnStartupFailure() throws IOException {
try {
new ClassPathXmlApplicationContext(new String[] {
"/org/springframework/web/context/WEB-INF/applicationContext.xml",
"/org/springframework/web/context/WEB-INF/fail.xml" }) {
new ClassPathXmlApplicationContext(new String[] {
"/org/springframework/web/context/WEB-INF/applicationContext.xml",
"/org/springframework/web/context/WEB-INF/fail.xml" }) {
@Override
public void refresh() throws BeansException {
try {
super.refresh();
}
catch (BeanCreationException ex) {
DefaultListableBeanFactory factory = (DefaultListableBeanFactory) getBeanFactory();
assertEquals(0, factory.getSingletonCount());
throw ex;
}
@Override
public void refresh() throws BeansException {
try {
super.refresh();
}
};
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
// expected
}
catch (BeanCreationException ex) {
DefaultListableBeanFactory factory = (DefaultListableBeanFactory) getBeanFactory();
assertEquals(0, factory.getSingletonCount());
throw ex;
}
}
};
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -43,6 +43,7 @@ import static org.junit.Assert.*;
public class ServletContextSupportTests {
@Test
@SuppressWarnings("resource")
public void testServletContextAttributeFactoryBean() {
MockServletContext sc = new MockServletContext();
sc.setAttribute("myAttr", "myValue");
@ -59,6 +60,7 @@ public class ServletContextSupportTests {
}
@Test
@SuppressWarnings("resource")
public void testServletContextAttributeFactoryBeanWithAttributeNotFound() {
MockServletContext sc = new MockServletContext();
@ -80,6 +82,7 @@ public class ServletContextSupportTests {
}
@Test
@SuppressWarnings("resource")
public void testServletContextParameterFactoryBean() {
MockServletContext sc = new MockServletContext();
sc.addInitParameter("myParam", "myValue");
@ -96,6 +99,7 @@ public class ServletContextSupportTests {
}
@Test
@SuppressWarnings("resource")
public void testServletContextParameterFactoryBeanWithAttributeNotFound() {
MockServletContext sc = new MockServletContext();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@ -35,6 +35,7 @@ import static org.junit.Assert.*;
public class WebApplicationObjectSupportTests {
@Test
@SuppressWarnings("resource")
public void testWebApplicationObjectSupport() {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
@ -48,6 +49,7 @@ public class WebApplicationObjectSupportTests {
}
@Test
@SuppressWarnings("resource")
public void testWebApplicationObjectSupportWithWrongContext() {
StaticApplicationContext ac = new StaticApplicationContext();
ac.registerBeanDefinition("test", new RootBeanDefinition(TestWebApplicationObject.class));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.config;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
@ -54,18 +54,14 @@ import static org.junit.Assert.*;
/**
* Test fixture for the configuration in mvc-config-annotation-driven.xml.
*
* @author Rossen Stoyanchev
* @author Brian Clozel
* @author Agim Emruli
*/
public class AnnotationDrivenBeanDefinitionParserTests {
private GenericWebApplicationContext appContext;
@Before
public void setup() {
this.appContext = new GenericWebApplicationContext();
}
private final GenericWebApplicationContext appContext = new GenericWebApplicationContext();
@Test
public void testMessageCodesResolver() {
@ -191,7 +187,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
Object value = new DirectFieldAccessor(bean).getPropertyValue("responseBodyAdvice");
assertNotNull(value);
assertTrue(value instanceof List);
List<ResponseBodyAdvice> converters = (List<ResponseBodyAdvice>) value;
List<ResponseBodyAdvice<?>> converters = (List<ResponseBodyAdvice<?>>) value;
assertTrue(converters.get(0) instanceof JsonViewResponseBodyAdvice);
}
@ -201,7 +197,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
Object value = new DirectFieldAccessor(bean).getPropertyValue("requestResponseBodyAdvice");
assertNotNull(value);
assertTrue(value instanceof List);
List<ResponseBodyAdvice> converters = (List<ResponseBodyAdvice>) value;
List<ResponseBodyAdvice<?>> converters = (List<ResponseBodyAdvice<?>>) value;
assertTrue(converters.get(0) instanceof JsonViewRequestBodyAdvice);
assertTrue(converters.get(1) instanceof JsonViewResponseBodyAdvice);
}

View File

@ -347,6 +347,7 @@ public class MvcNamespaceTests {
}
@Test
@SuppressWarnings("unchecked")
public void testResources() throws Exception {
loadBeanDefinitions("mvc-config-resources.xml");

View File

@ -60,7 +60,6 @@ public class DefaultServletHandlerConfigurerTests {
@Test
public void enable() throws Exception {
configurer.enable();
SimpleUrlHandlerMapping getHandlerMapping = configurer.buildHandlerMapping();
SimpleUrlHandlerMapping handlerMapping = configurer.buildHandlerMapping();
DefaultServletHttpRequestHandler handler = (DefaultServletHttpRequestHandler) handlerMapping.getUrlMap().get("/**");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -27,7 +27,6 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
@ -48,7 +47,6 @@ import org.springframework.web.util.UrlPathHelper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
@ -122,7 +120,7 @@ public class DelegatingWebMvcConfigurationTests {
@Test
public void configureMessageConverters() {
final HttpMessageConverter customConverter = mock(HttpMessageConverter.class);
final HttpMessageConverter<?> customConverter = mock(HttpMessageConverter.class);
final StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
List<WebMvcConfigurer> configurers = new ArrayList<>();
configurers.add(new WebMvcConfigurer() {

View File

@ -83,7 +83,6 @@ public class HandlerMappingIntrospectorTests {
assertEquals(expected, actual);
}
@Test @SuppressWarnings("deprecation")
public void defaultHandlerMappings() throws Exception {
StaticWebApplicationContext cxt = new StaticWebApplicationContext();
cxt.refresh();
@ -170,7 +169,8 @@ public class HandlerMappingIntrospectorTests {
}
@Configuration @SuppressWarnings({"WeakerAccess", "unused"})
@Configuration
@SuppressWarnings({"WeakerAccess", "unused"})
static class TestConfig {
@Bean

View File

@ -131,7 +131,7 @@ public class HandlerMethodMappingTests {
// Direct URL lookup
List directUrlMatches = this.mapping.getMappingRegistry().getMappingsByUrl(key1);
List<String> directUrlMatches = this.mapping.getMappingRegistry().getMappingsByUrl(key1);
assertNotNull(directUrlMatches);
assertEquals(1, directUrlMatches.size());
assertEquals(key1, directUrlMatches.get(0));
@ -181,7 +181,7 @@ public class HandlerMethodMappingTests {
// Direct URL lookup
List directUrlMatches = this.mapping.getMappingRegistry().getMappingsByUrl(key1);
List<String> directUrlMatches = this.mapping.getMappingRegistry().getMappingsByUrl(key1);
assertNotNull(directUrlMatches);
assertEquals(1, directUrlMatches.size());
assertEquals(key1, directUrlMatches.get(0));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -41,6 +41,7 @@ import static org.junit.Assert.*;
public class SimpleUrlHandlerMappingTests {
@Test
@SuppressWarnings("resource")
public void handlerBeanNotFound() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext root = new XmlWebApplicationContext();
@ -89,6 +90,7 @@ public class SimpleUrlHandlerMappingTests {
assertSame(controller, hec.getHandler());
}
@SuppressWarnings("resource")
private void checkMappings(String beanName) throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext wac = new XmlWebApplicationContext();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 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.
@ -35,7 +35,6 @@ import static org.junit.Assert.*;
*/
public class RequestMappingInfoHandlerMethodMappingNamingStrategyTests {
@Test
public void getNameExplicit() {
@ -44,7 +43,7 @@ public class RequestMappingInfoHandlerMethodMappingNamingStrategyTests {
RequestMappingInfo rmi = new RequestMappingInfo("foo", null, null, null, null, null, null, null);
HandlerMethodMappingNamingStrategy strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy();
HandlerMethodMappingNamingStrategy<RequestMappingInfo> strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy();
assertEquals("foo", strategy.getName(handlerMethod, rmi));
}
@ -57,7 +56,7 @@ public class RequestMappingInfoHandlerMethodMappingNamingStrategyTests {
RequestMappingInfo rmi = new RequestMappingInfo(null, null, null, null, null, null, null, null);
HandlerMethodMappingNamingStrategy strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy();
HandlerMethodMappingNamingStrategy<RequestMappingInfo> strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy();
assertEquals("TC#handle", strategy.getName(handlerMethod, rmi));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -131,7 +131,7 @@ public abstract class AbstractRequestAttributesArgumentResolverTests {
Object actual = testResolveArgument(param, factory);
assertNotNull(actual);
assertEquals(Optional.class, actual.getClass());
assertFalse(((Optional) actual).isPresent());
assertFalse(((Optional<?>) actual).isPresent());
Foo foo = new Foo();
this.webRequest.setAttribute("foo", foo, getScope());
@ -139,8 +139,8 @@ public abstract class AbstractRequestAttributesArgumentResolverTests {
actual = testResolveArgument(param, factory);
assertNotNull(actual);
assertEquals(Optional.class, actual.getClass());
assertTrue(((Optional) actual).isPresent());
assertSame(foo, ((Optional) actual).get());
assertTrue(((Optional<?>) actual).isPresent());
assertSame(foo, ((Optional<?>) actual).get());
}
private Object testResolveArgument(MethodParameter param) throws Exception {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -76,6 +76,7 @@ public class CrossOriginTests {
@Before
@SuppressWarnings("resource")
public void setup() {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
Properties props = new Properties();

View File

@ -93,8 +93,8 @@ public class ExceptionHandlerExceptionResolverTests {
}
@SuppressWarnings("ConstantConditions")
@Test
@SuppressWarnings("ConstantConditions")
public void nullHandler() {
Object handler = null;
this.resolver.afterPropertiesSet();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -125,7 +125,6 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
}
@Override
@SuppressWarnings("rawtypes")
public ModelAndView resolveModelAndView(Method method, Class<?> handlerType, Object returnValue,
ExtendedModelMap model, NativeWebRequest request) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.mvc.method.annotation;
import java.io.IOException;
@ -400,8 +401,10 @@ public class ReactiveTypeHandlerTests {
this.value = value;
}
@SuppressWarnings("unused")
public String getValue() {
return this.value;
}
}
}

View File

@ -385,7 +385,6 @@ public class RequestMappingHandlerAdapterTests {
@ControllerAdvice
private static class ResponseCodeSuppressingAdvice extends AbstractMappingJacksonResponseBodyAdvice {
@SuppressWarnings("unchecked")
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -326,11 +326,11 @@ public class RequestPartMethodArgumentResolverTests {
Object actualValue = resolver.resolveArgument(optionalMultipartFile, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", expected, ((Optional) actualValue).get());
assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());
actualValue = resolver.resolveArgument(optionalMultipartFile, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", expected, ((Optional) actualValue).get());
assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());
}
@Test
@ -366,11 +366,11 @@ public class RequestPartMethodArgumentResolverTests {
Object actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional) actualValue).get());
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());
actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional) actualValue).get());
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());
}
@Test
@ -408,11 +408,11 @@ public class RequestPartMethodArgumentResolverTests {
Object actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", expected, ((Optional) actualValue).get());
assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());
actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", expected, ((Optional) actualValue).get());
assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());
}
@Test
@ -452,11 +452,11 @@ public class RequestPartMethodArgumentResolverTests {
Object actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional) actualValue).get());
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());
actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional) actualValue).get());
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());
}
@Test

View File

@ -151,7 +151,6 @@ public class RequestResponseBodyAdviceChainTests {
return true;
}
@SuppressWarnings("unchecked")
@Override
public String beforeBodyWrite(String body, MethodParameter returnType,
MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType,
@ -170,7 +169,6 @@ public class RequestResponseBodyAdviceChainTests {
return true;
}
@SuppressWarnings("unchecked")
@Override
public String beforeBodyWrite(String body, MethodParameter returnType,
MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType,

View File

@ -268,8 +268,8 @@ public class RequestResponseBodyMethodProcessorTests {
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
HttpMessageConverter target = new MappingJackson2HttpMessageConverter();
HttpMessageConverter proxy = ProxyFactory.getProxy(HttpMessageConverter.class, new SingletonTargetSource(target));
HttpMessageConverter<Object> target = new MappingJackson2HttpMessageConverter();
HttpMessageConverter<?> proxy = ProxyFactory.getProxy(HttpMessageConverter.class, new SingletonTargetSource(target));
converters.add(proxy);
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.mvc.method.annotation;
import java.util.Arrays;
@ -306,7 +307,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
private ResponseEntity<AtomicReference<String>> h6() { return null; }
private ResponseEntity h7() { return null; }
private ResponseEntity<?> h7() { return null; }
private Flux<String> h8() { return null; }
@ -315,6 +316,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
}
@SuppressWarnings("unused")
private static class SimpleBean {
private Long id;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -238,9 +238,6 @@ public class ResponseEntityExceptionHandlerTests {
}
private static class TestController {
}
@ControllerAdvice
private static class ApplicationExceptionHandler extends ResponseEntityExceptionHandler {
@ -253,7 +250,6 @@ public class ResponseEntityExceptionHandlerTests {
}
}
@SuppressWarnings("unused")
void handle(String arg) {
}

View File

@ -3033,7 +3033,6 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
public static class MyModelAndViewResolver implements ModelAndViewResolver {
@Override
@SuppressWarnings("rawtypes")
public ModelAndView resolveModelAndView(Method handlerMethod, Class<?> handlerType, Object returnValue,
ExtendedModelMap implicitModel, NativeWebRequest webRequest) {
@ -3048,7 +3047,6 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
throws Exception {
response.getWriter().write("myValue");
}
});
}
return UNRESOLVED;
@ -3143,7 +3141,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
String ARTICLES_PATH = API_V1 + "/articles";
}
public interface ResourceEndpoint<E extends Entity, P extends EntityPredicate> {
public interface ResourceEndpoint<E extends Entity, P extends EntityPredicate<?>> {
Collection<E> find(String pageable, P predicate) throws IOException;

View File

@ -458,6 +458,7 @@ public class ServletInvocableHandlerMethodTests {
this.value = value;
}
@SuppressWarnings("unused")
public String getValue() {
return this.value;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -107,6 +107,7 @@ public class ServletModelAttributeMethodProcessorTests {
}
@Test
@SuppressWarnings("unchecked")
public void createAttributeUriTemplateVarWithOptional() throws Exception {
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("testBean3", "Patty");
@ -141,6 +142,7 @@ public class ServletModelAttributeMethodProcessorTests {
}
@Test
@SuppressWarnings("unchecked")
public void createAttributeRequestParameterWithOptional() throws Exception {
request.addParameter("testBean3", "Patty");
@ -151,6 +153,7 @@ public class ServletModelAttributeMethodProcessorTests {
}
@Test
@SuppressWarnings("unchecked")
public void attributesAsNullValues() throws Exception {
request.addParameter("name", "Patty");
@ -170,6 +173,7 @@ public class ServletModelAttributeMethodProcessorTests {
}
@Test
@SuppressWarnings("unchecked")
public void attributesAsOptionalEmpty() throws Exception {
request.addParameter("name", "Patty");

View File

@ -39,7 +39,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Unit tests for {@link ResourceUrlProvider}.
*
@ -138,6 +137,7 @@ public class ResourceUrlProviderTests {
}
@Test // SPR-12592
@SuppressWarnings("resource")
public void initializeOnce() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());

View File

@ -365,7 +365,6 @@ public class MessageTagTests extends AbstractTagTests {
}
@Test
@SuppressWarnings("deprecation")
public void nullMessageSource() throws JspException {
PageContext pc = createPageContext();
ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext)

View File

@ -103,7 +103,6 @@ public abstract class AbstractHtmlElementTagTests extends AbstractTagTests {
return (RequestContext) getPageContext().getAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE);
}
@SuppressWarnings("deprecation")
protected RequestDataValueProcessor getMockRequestDataValueProcessor() {
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
HttpServletRequest request = (HttpServletRequest) getPageContext().getRequest();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2018 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.
@ -36,9 +36,9 @@ public class DummyMacroRequestContext {
private HttpServletRequest request;
private Map messageMap;
private Map<String, String> messageMap;
private Map themeMessageMap;
private Map<String, String> themeMessageMap;
private String contextPath;
@ -48,11 +48,11 @@ public class DummyMacroRequestContext {
}
public void setMessageMap(Map messageMap) {
public void setMessageMap(Map<String, String> messageMap) {
this.messageMap = messageMap;
}
public void setThemeMessageMap(Map themeMessageMap) {
public void setThemeMessageMap(Map<String, String> themeMessageMap) {
this.themeMessageMap = themeMessageMap;
}
@ -61,60 +61,60 @@ public class DummyMacroRequestContext {
* @see org.springframework.web.servlet.support.RequestContext#getMessage(String)
*/
public String getMessage(String code) {
return (String) this.messageMap.get(code);
return this.messageMap.get(code);
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getMessage(String, String)
*/
public String getMessage(String code, String defaultMsg) {
String msg = (String) this.messageMap.get(code);
String msg = this.messageMap.get(code);
return (msg != null ? msg : defaultMsg);
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getMessage(String, List)
*/
public String getMessage(String code, List args) {
return ((String) this.messageMap.get(code)) + args.toString();
public String getMessage(String code, List<?> args) {
return this.messageMap.get(code) + args;
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getMessage(String, List, String)
*/
public String getMessage(String code, List args, String defaultMsg) {
String msg = (String) this.messageMap.get(code);
return (msg != null ? msg + args.toString(): defaultMsg);
public String getMessage(String code, List<?> args, String defaultMsg) {
String msg = this.messageMap.get(code);
return (msg != null ? msg + args : defaultMsg);
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String)
*/
public String getThemeMessage(String code) {
return (String) this.themeMessageMap.get(code);
return this.themeMessageMap.get(code);
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String, String)
*/
public String getThemeMessage(String code, String defaultMsg) {
String msg = (String) this.themeMessageMap.get(code);
String msg = this.themeMessageMap.get(code);
return (msg != null ? msg : defaultMsg);
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String, List)
*/
public String getThemeMessage(String code, List args) {
return ((String) this.themeMessageMap.get(code)) + args.toString();
public String getThemeMessage(String code, List<?> args) {
return this.themeMessageMap.get(code) + args;
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String, List, String)
*/
public String getThemeMessage(String code, List args, String defaultMsg) {
String msg = (String) this.themeMessageMap.get(code);
return (msg != null ? msg + args.toString(): defaultMsg);
public String getThemeMessage(String code, List<?> args, String defaultMsg) {
String msg = this.themeMessageMap.get(code);
return (msg != null ? msg + args : defaultMsg);
}
public void setContextPath(String contextPath) {

View File

@ -137,8 +137,8 @@ public class RedirectViewTests {
assertEquals("http://url.somewhere.com", response.getHeader("Location"));
}
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
@Test
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void flashMap() throws Exception {
RedirectView rv = new RedirectView();
rv.setUrl("http://url.somewhere.com/path");

View File

@ -132,7 +132,7 @@ public class ViewResolverTests {
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
Map model = new HashMap();
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
@ -184,7 +184,7 @@ public class ViewResolverTests {
Properties props = new Properties();
props.setProperty("key1", "value1");
vr.setAttributes(props);
Map map = new HashMap();
Map<String, Object> map = new HashMap<>();
map.put("key2", new Integer(2));
vr.setAttributesMap(map);
vr.setApplicationContext(wac);
@ -192,7 +192,7 @@ public class ViewResolverTests {
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example1", ((InternalResourceView) view).getUrl());
Map attributes = ((InternalResourceView) view).getStaticAttributes();
Map<String, Object> attributes = ((InternalResourceView) view).getStaticAttributes();
assertEquals("value1", attributes.get("key1"));
assertEquals(new Integer(2), attributes.get("key2"));
@ -207,7 +207,7 @@ public class ViewResolverTests {
HttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
Map model = new HashMap();
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
@ -230,7 +230,7 @@ public class ViewResolverTests {
Properties props = new Properties();
props.setProperty("key1", "value1");
vr.setAttributes(props);
Map map = new HashMap();
Map<String, Object> map = new HashMap<>();
map.put("key2", new Integer(2));
vr.setAttributesMap(map);
vr.setExposeContextBeansAsAttributes(true);
@ -255,7 +255,7 @@ public class ViewResolverTests {
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
View view = vr.resolveViewName("example1", Locale.getDefault());
view.render(new HashMap(), request, response);
view.render(new HashMap<String, Object>(), request, response);
}
@Test
@ -270,7 +270,7 @@ public class ViewResolverTests {
Properties props = new Properties();
props.setProperty("key1", "value1");
vr.setAttributes(props);
Map map = new HashMap();
Map<String, Object> map = new HashMap<>();
map.put("key2", new Integer(2));
vr.setAttributesMap(map);
vr.setExposedContextBeanNames(new String[] {"myBean2"});
@ -295,7 +295,7 @@ public class ViewResolverTests {
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
View view = vr.resolveViewName("example1", Locale.getDefault());
view.render(new HashMap(), request, response);
view.render(new HashMap<String, Object>(), request, response);
}
@Test
@ -323,7 +323,7 @@ public class ViewResolverTests {
HttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
Map model = new HashMap();
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
@ -362,7 +362,7 @@ public class ViewResolverTests {
HttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
Map model = new HashMap();
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
@ -396,7 +396,7 @@ public class ViewResolverTests {
assertTrue("Correct URL", "/example2new.jsp".equals(((InternalResourceView) view2).getUrl()));
ServletContext sc = new MockServletContext();
Map model = new HashMap();
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -50,6 +50,7 @@ public class XlsViewTests {
@Test
@SuppressWarnings("resource")
public void testXls() throws Exception {
View excelView = new AbstractXlsView() {
@Override
@ -73,6 +74,7 @@ public class XlsViewTests {
}
@Test
@SuppressWarnings("resource")
public void testXlsxView() throws Exception {
View excelView = new AbstractXlsxView() {
@Override
@ -96,6 +98,7 @@ public class XlsViewTests {
}
@Test
@SuppressWarnings("resource")
public void testXlsxStreamingView() throws Exception {
View excelView = new AbstractXlsxStreamingView() {
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -19,7 +19,6 @@ package org.springframework.web.servlet.view.feed;
import com.rometools.rome.feed.atom.Content;
import com.rometools.rome.feed.atom.Entry;
import com.rometools.rome.feed.atom.Feed;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
@ -28,7 +27,6 @@ import org.xmlunit.matchers.CompareMatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -41,12 +39,7 @@ import static org.junit.Assert.assertThat;
*/
public class AtomFeedViewTests {
private AbstractAtomFeedView view;
@Before
public void createView() throws Exception {
view = new MyAtomFeedView();
}
private final AbstractAtomFeedView view = new MyAtomFeedView();
@Test
public void render() throws Exception {
@ -65,24 +58,21 @@ public class AtomFeedViewTests {
assertThat(response.getContentAsString(), isSimilarTo(expected));
}
private static CompareMatcher isSimilarTo(final String content) {
return CompareMatcher.isSimilarTo(content)
.ignoreWhitespace();
private static CompareMatcher isSimilarTo(String content) {
return CompareMatcher.isSimilarTo(content).ignoreWhitespace();
}
private static class MyAtomFeedView extends AbstractAtomFeedView {
@Override
protected void buildFeedMetadata(Map model, Feed feed, HttpServletRequest request) {
protected void buildFeedMetadata(Map<String, Object>model, Feed feed, HttpServletRequest request) {
feed.setTitle("Test Feed");
}
@Override
protected List<Entry> buildFeedEntries(Map model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
List<Entry> entries = new ArrayList<>();
for (Iterator iterator = model.keySet().iterator(); iterator.hasNext();) {
String name = (String) iterator.next();
for (String name : model.keySet()) {
Entry entry = new Entry();
entry.setTitle(name);
Content content = new Content();

View File

@ -101,6 +101,7 @@ public class GroovyMarkupConfigurerTests {
}
@Test
@SuppressWarnings("resource")
public void parentLoader() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 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.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.view.groovy;
import java.util.Locale;
@ -35,7 +36,7 @@ public class GroovyMarkupViewResolverTests {
GroovyMarkupViewResolver resolver = new GroovyMarkupViewResolver();
Assert.assertEquals(GroovyMarkupView.class, resolver.requiredViewClass());
DirectFieldAccessor viewAccessor = new DirectFieldAccessor(resolver);
Class viewClass = (Class) viewAccessor.getPropertyValue("viewClass");
Class<?> viewClass = (Class<?>) viewAccessor.getPropertyValue("viewClass");
Assert.assertEquals(GroovyMarkupView.class, viewClass);
}

View File

@ -454,6 +454,7 @@ public class MappingJackson2JsonViewTests {
@JsonFilter("myJacksonFilter")
@SuppressWarnings("unused")
private static class TestSimpleBeanFiltered {
private String property1;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@ -33,7 +33,7 @@ public class ScriptTemplateViewResolverTests {
ScriptTemplateViewResolver resolver = new ScriptTemplateViewResolver();
Assert.assertEquals(ScriptTemplateView.class, resolver.requiredViewClass());
DirectFieldAccessor viewAccessor = new DirectFieldAccessor(resolver);
Class viewClass = (Class) viewAccessor.getPropertyValue("viewClass");
Class<?> viewClass = (Class<?>) viewAccessor.getPropertyValue("viewClass");
Assert.assertEquals(ScriptTemplateView.class, viewClass);
}