Clean up warnings in spring-web

This commit is contained in:
Sam Brannen
2015-07-06 18:30:20 +02:00
parent 67ac675e9a
commit 0f7fc12569
23 changed files with 60 additions and 67 deletions

View File

@@ -28,8 +28,6 @@ import java.util.concurrent.TimeUnit;
*/
public class CacheControlTests {
private static final String CACHE_CONTROL_HEADER = "Cache-Control";
@Test
public void emptyCacheControl() throws Exception {
CacheControl cc = CacheControl.empty();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -20,6 +20,7 @@ import java.util.Calendar;
import java.util.Date;
import com.google.gson.Gson;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -172,6 +173,7 @@ public class GsonFactoryBeanTests {
private String name;
@SuppressWarnings("unused")
public String getName() {
return this.name;
}
@@ -186,6 +188,7 @@ public class GsonFactoryBeanTests {
private Date date;
@SuppressWarnings("unused")
public Date getDate() {
return this.date;
}
@@ -200,6 +203,7 @@ public class GsonFactoryBeanTests {
private byte[] bytes;
@SuppressWarnings("unused")
public byte[] getBytes() {
return this.bytes;
}

View File

@@ -60,6 +60,7 @@ import com.fasterxml.jackson.databind.ser.std.ClassSerializer;
import com.fasterxml.jackson.databind.ser.std.NumberSerializer;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test;
@@ -143,26 +144,25 @@ public class Jackson2ObjectMapperBuilderTests {
@Test
public void setNotNullSerializationInclusion() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() ==
JsonInclude.Include.ALWAYS);
assertSame(JsonInclude.Include.ALWAYS, objectMapper.getSerializationConfig().getSerializationInclusion());
objectMapper = Jackson2ObjectMapperBuilder.json().serializationInclusion(JsonInclude.Include.NON_NULL).build();
assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() == JsonInclude.Include.NON_NULL);
assertSame(JsonInclude.Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion());
}
@Test
public void setNotDefaultSerializationInclusion() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() == JsonInclude.Include.ALWAYS);
assertSame(JsonInclude.Include.ALWAYS, objectMapper.getSerializationConfig().getSerializationInclusion());
objectMapper = Jackson2ObjectMapperBuilder.json().serializationInclusion(JsonInclude.Include.NON_DEFAULT).build();
assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() == JsonInclude.Include.NON_DEFAULT);
assertSame(JsonInclude.Include.NON_DEFAULT, objectMapper.getSerializationConfig().getSerializationInclusion());
}
@Test
public void setNotEmptySerializationInclusion() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() == JsonInclude.Include.ALWAYS);
assertSame(JsonInclude.Include.ALWAYS, objectMapper.getSerializationConfig().getSerializationInclusion());
objectMapper = Jackson2ObjectMapperBuilder.json().serializationInclusion(JsonInclude.Include.NON_EMPTY).build();
assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() == JsonInclude.Include.NON_EMPTY);
assertSame(JsonInclude.Include.NON_EMPTY, objectMapper.getSerializationConfig().getSerializationInclusion());
}
@Test
@@ -213,26 +213,27 @@ public class Jackson2ObjectMapperBuilderTests {
@Test
public void modules() {
NumberSerializer serializer1 = new NumberSerializer();
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(module).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertTrue(serializers.findSerializer(null, SimpleType.construct(Integer.class), null) == serializer1);
assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Integer.class), null));
}
@Test
@SuppressWarnings("unchecked")
public void modulesToInstallByClass() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(CustomIntegerModule.class).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertTrue(serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass() == CustomIntegerSerializer.class);
assertSame(CustomIntegerSerializer.class, serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
}
@Test
public void modulesToInstallByInstance() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(new CustomIntegerModule()).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertTrue(serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass() == CustomIntegerSerializer.class);
assertSame(CustomIntegerSerializer.class, serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
}
@Test
@@ -257,6 +258,7 @@ public class Jackson2ObjectMapperBuilderTests {
}
@Test // SPR-12634
@SuppressWarnings("unchecked")
public void customizeDefaultModulesWithModuleClass() throws JsonProcessingException, UnsupportedEncodingException {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(CustomIntegerModule.class).build();
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
@@ -292,13 +294,13 @@ public class Jackson2ObjectMapperBuilderTests {
@Test
public void serializerByType() {
JsonSerializer<Number> serializer = new NumberSerializer();
JsonSerializer<Number> serializer = new NumberSerializer(Integer.class);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.serializerByType(Boolean.class, serializer).build();
assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertTrue(serializers.findSerializer(null, SimpleType.construct(Boolean.class), null) == serializer);
assertSame(serializer, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
}
@Test
@@ -309,7 +311,7 @@ public class Jackson2ObjectMapperBuilderTests {
.deserializerByType(Date.class, deserializer).build();
assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
assertTrue(deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null) == deserializer);
assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
}
@Test
@@ -362,7 +364,7 @@ public class Jackson2ObjectMapperBuilderTests {
deserializerMap.put(Date.class, deserializer);
JsonSerializer<Class<?>> serializer1 = new ClassSerializer();
JsonSerializer<Number> serializer2 = new NumberSerializer();
JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
@@ -387,15 +389,15 @@ public class Jackson2ObjectMapperBuilderTests {
assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertTrue(serializers.findSerializer(null, SimpleType.construct(Class.class), null) == serializer1);
assertTrue(serializers.findSerializer(null, SimpleType.construct(Boolean.class), null) == serializer2);
assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Class.class), null));
assertSame(serializer2, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null));
Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
assertTrue(deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null) == deserializer);
assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
assertTrue(annotationIntrospector == objectMapper.getSerializationConfig().getAnnotationIntrospector());
assertTrue(annotationIntrospector == objectMapper.getDeserializationConfig().getAnnotationIntrospector());
assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector());
assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector());
assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
@@ -408,7 +410,7 @@ public class Jackson2ObjectMapperBuilderTests {
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() == JsonInclude.Include.NON_NULL);
assertSame(JsonInclude.Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion());
}
@Test

View File

@@ -222,7 +222,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
@Test
public void setModules() {
NumberSerializer serializer1 = new NumberSerializer();
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
@@ -341,7 +341,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
deserializers.put(Date.class, new DateDeserializer());
JsonSerializer<Class<?>> serializer1 = new ClassSerializer();
JsonSerializer<Number> serializer2 = new NumberSerializer();
JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);
factory.setModules(new ArrayList<>()); // Disable well-known modules detection
factory.setSerializers(serializer1);

View File

@@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import org.junit.Test;
import org.springframework.core.ParameterizedTypeReference;
@@ -395,6 +396,7 @@ public class MappingJackson2HttpMessageConverterTests {
private interface MyJacksonView1 {};
private interface MyJacksonView2 {};
@SuppressWarnings("unused")
private static class JacksonViewBean {
@JsonView(MyJacksonView1.class)
@@ -431,6 +433,7 @@ public class MappingJackson2HttpMessageConverterTests {
}
@JsonFilter("myJacksonFilter")
@SuppressWarnings("unused")
private static class JacksonFilteredBean {
private String property1;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -106,13 +106,13 @@ public class SpringHandlerInstantiatorTests {
@Test
public void applicationContextAwaretypeResolverBuilder() throws JsonProcessingException {
this.objectMapper.writeValueAsString(new Group("authors"));
this.objectMapper.writeValueAsString(new Group());
assertTrue(CustomTypeResolverBuilder.isAutowiredFiledInitialized);
}
@Test
public void applicationContextAwareTypeIdResolver() throws JsonProcessingException {
this.objectMapper.writeValueAsString(new Group("authors"));
this.objectMapper.writeValueAsString(new Group());
assertTrue(CustomTypeIdResolver.isAutowiredFiledInitialized);
}
@@ -261,15 +261,6 @@ public class SpringHandlerInstantiatorTests {
@JsonTypeIdResolver(CustomTypeIdResolver.class)
public static class Group {
private String name;
public Group(String name) {
this.name = name;
}
public Group() {
}
public String getType() {
return Group.class.getName();
}

View File

@@ -45,7 +45,6 @@ import static org.junit.Assert.*;
* @author Arjen Poutsma
* @author Rossen Stoyanchev
*/
@SuppressWarnings("unused")
public class Jaxb2CollectionHttpMessageConverterTests {
private Jaxb2CollectionHttpMessageConverter<?> converter;

View File

@@ -53,7 +53,6 @@ import static org.junit.Assert.assertTrue;
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
*/
@SuppressWarnings("unused")
public class Jaxb2RootElementHttpMessageConverterTests {
private Jaxb2RootElementHttpMessageConverter converter;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -42,6 +42,7 @@ import static org.junit.Assert.*;
public class HttpInvokerFactoryBeanIntegrationTests {
@Test
@SuppressWarnings("resource")
public void testLoadedConfigClass() {
ApplicationContext context = new AnnotationConfigApplicationContext(InvokerAutowiringConfig.class);
MyBean myBean = context.getBean("myBean", MyBean.class);
@@ -51,6 +52,7 @@ public class HttpInvokerFactoryBeanIntegrationTests {
}
@Test
@SuppressWarnings("resource")
public void testNonLoadedConfigClass() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.registerBeanDefinition("config", new RootBeanDefinition(InvokerAutowiringConfig.class.getName()));
@@ -62,6 +64,7 @@ public class HttpInvokerFactoryBeanIntegrationTests {
}
@Test
@SuppressWarnings("resource")
public void withConfigurationClassWithPlainFactoryBean() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(ConfigWithPlainFactoryBean.class);
@@ -133,7 +136,7 @@ public class HttpInvokerFactoryBeanIntegrationTests {
}
@Bean
public FactoryBean myService() {
public HttpInvokerProxyFactoryBean myService() {
String name = env.getProperty("testbean.name");
HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean();
factory.setServiceUrl("/svc/" + name);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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,6 +36,7 @@ import static org.junit.Assert.*;
public class RequestAndSessionScopedBeanTests {
@Test
@SuppressWarnings("resource")
public void testPutBeanInRequest() throws Exception {
String targetBeanName = "target";
@@ -75,6 +76,7 @@ public class RequestAndSessionScopedBeanTests {
}
@Test
@SuppressWarnings("resource")
public void testPutBeanInSession() throws Exception {
String targetBeanName = "target";
HttpServletRequest request = new MockHttpServletRequest();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -34,6 +34,7 @@ import static org.junit.Assert.*;
public class AnnotationConfigWebApplicationContextTests {
@Test
@SuppressWarnings("resource")
public void registerSingleClass() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(Config.class);
@@ -44,6 +45,7 @@ public class AnnotationConfigWebApplicationContextTests {
}
@Test
@SuppressWarnings("resource")
public void configLocationWithSingleClass() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setConfigLocation(Config.class.getName());
@@ -54,6 +56,7 @@ public class AnnotationConfigWebApplicationContextTests {
}
@Test
@SuppressWarnings("resource")
public void configLocationWithBasePackage() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setConfigLocation("org.springframework.web.context.support");
@@ -64,6 +67,7 @@ public class AnnotationConfigWebApplicationContextTests {
}
@Test
@SuppressWarnings("resource")
public void withBeanNameGenerator() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -51,6 +51,7 @@ public class ExpressionValueMethodArgumentResolverTests {
private NativeWebRequest webRequest;
@Before
@SuppressWarnings("resource")
public void setUp() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -168,7 +168,6 @@ public class ModelFactoryOrderingTests {
}
}
@SuppressWarnings("unused")
private static class StraightLineDependencyController extends AbstractController {
@ModelAttribute
@@ -208,7 +207,6 @@ public class ModelFactoryOrderingTests {
}
}
@SuppressWarnings("unused")
private static class TreeDependencyController extends AbstractController {
@ModelAttribute
@@ -247,7 +245,6 @@ public class ModelFactoryOrderingTests {
}
}
@SuppressWarnings("unused")
private static class InvertedTreeDependencyController extends AbstractController {
@ModelAttribute
@@ -287,7 +284,6 @@ public class ModelFactoryOrderingTests {
}
@SuppressWarnings("unused")
private static class UnresolvedDependencyController extends AbstractController {
@ModelAttribute

View File

@@ -58,6 +58,7 @@ public class RequestHeaderMethodArgumentResolverTests {
@Before
@SuppressWarnings("resource")
public void setUp() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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,7 +57,6 @@ public class CompositeUriComponentsContributorTests {
}
@SuppressWarnings("unused")
public void handleRequest(@RequestParam String p1, String p2, @RequestHeader String h) {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -111,6 +111,8 @@ public class CommonsMultipartResolverTests {
doTestFiles(request);
doTestBinding(resolver, originalRequest, request);
wac.close();
}
private void doTestParameters(MultipartHttpServletRequest request) {